[OpenSearch] Add support for filtering docs based on app_id in opensearch db (#729)
This commit is contained in:
@@ -144,6 +144,11 @@ class OpenSearchDB(BaseVectorDB):
|
|||||||
http_auth=self.config.http_auth,
|
http_auth=self.config.http_auth,
|
||||||
use_ssl=True,
|
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(
|
docs = docsearch.similarity_search(
|
||||||
input_query,
|
input_query,
|
||||||
search_type="script_scoring",
|
search_type="script_scoring",
|
||||||
@@ -151,6 +156,8 @@ class OpenSearchDB(BaseVectorDB):
|
|||||||
vector_field="embeddings",
|
vector_field="embeddings",
|
||||||
text_field="text",
|
text_field="text",
|
||||||
metadata_field="metadata",
|
metadata_field="metadata",
|
||||||
|
pre_filter=pre_filter,
|
||||||
|
k=n_results,
|
||||||
)
|
)
|
||||||
contents = [doc.page_content for doc in docs]
|
contents = [doc.page_content for doc in docs]
|
||||||
return contents
|
return contents
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "embedchain"
|
name = "embedchain"
|
||||||
version = "0.0.62"
|
version = "0.0.63"
|
||||||
description = "embedchain is a framework to easily create LLM powered bots over any dataset"
|
description = "embedchain is a framework to easily create LLM powered bots over any dataset"
|
||||||
authors = ["Taranjeet Singh"]
|
authors = ["Taranjeet Singh"]
|
||||||
license = "Apache License"
|
license = "Apache License"
|
||||||
|
|||||||
Reference in New Issue
Block a user