Skip to content

Commit

Permalink
Merge pull request #41 from weni-ai/hotfix/content-base-search-query
Browse files Browse the repository at this point in the history
fix search query
  • Loading branch information
AlisoSouza authored Jun 27, 2024
2 parents 69ba454 + 6577829 commit fa1b9da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/store/elasticsearch_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def search_delete(self, search_filter: dict, scroll_id: str = None) -> tuple[str

def search(self, search: str, filter=None, threshold=0.1) -> list[Document]:
content_base_uuid = filter.get("content_base_uuid")
q = {"match": {"metadata.content_base_uuid": content_base_uuid}}
q = {"bool": {"filter": [{"term": {"metadata.content_base_uuid.keyword": content_base_uuid}}]}}


docs = self.vectorstore.similarity_search_with_score(query=search, k=5, filter=q)
return [doc[0] for doc in docs if doc[1] > threshold]
Expand Down
2 changes: 1 addition & 1 deletion app/tests/test_elasticsearch_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_search(self):
search="test", filter=query_filter
)
self.vectorstore.similarity_search_with_score.assert_called_once_with(
query="test", k=5, filter={'match': {'metadata.content_base_uuid': 'dfff32e7-dce6-40f7-a86e-8f9618887977'}}
query="test", k=5, filter={"bool": {"filter": [{"term": {"metadata.content_base_uuid.keyword": "dfff32e7-dce6-40f7-a86e-8f9618887977"}}]}}
)
self.assertEqual(1, len(results))
self.assertEqual(results[0].page_content, "test doc")
Expand Down

0 comments on commit fa1b9da

Please sign in to comment.