[OpenSearch] Add support for filtering docs based on app_id in opensearch db (#729)

This commit is contained in:
Deshraj Yadav
2023-09-29 15:19:10 -07:00
committed by GitHub
parent 333eb8d60f
commit 6ae33d04b8
2 changed files with 8 additions and 1 deletions

View File

@@ -144,6 +144,11 @@ class OpenSearchDB(BaseVectorDB):
http_auth=self.config.http_auth,
use_ssl=True,
)
pre_filter = {"match_all": {}} # default
if "app_id" in where:
app_id = where["app_id"]
pre_filter = {"bool": {"must": [{"term": {"metadata.app_id": app_id}}]}}
docs = docsearch.similarity_search(
input_query,
search_type="script_scoring",
@@ -151,6 +156,8 @@ class OpenSearchDB(BaseVectorDB):
vector_field="embeddings",
text_field="text",
metadata_field="metadata",
pre_filter=pre_filter,
k=n_results,
)
contents = [doc.page_content for doc in docs]
return contents

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "embedchain"
version = "0.0.62"
version = "0.0.63"
description = "embedchain is a framework to easily create LLM powered bots over any dataset"
authors = ["Taranjeet Singh"]
license = "Apache License"