Skip to content

Commit

Permalink
Merge pull request #34 from weni-ai/feature/return-filename-field
Browse files Browse the repository at this point in the history
Return filename on search request
  • Loading branch information
AlisoSouza authored May 15, 2024
2 parents a67af8c + 6c68ba5 commit 9985769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/handlers/content_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ContentBaseSearchRequest(BaseModel):


class ContentBaseSearchResponse(BaseModel):
response: List[str]
response: List[dict]


class ContentBaseDeleteRequest(BaseModel):
Expand Down
16 changes: 15 additions & 1 deletion app/indexer/content_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ def index_batch(self):

def search(self, search, filter=None, threshold=0.1) -> list[Product]:
matched_responses = self.storage.search(search, filter, threshold)
return set([doc.metadata.get("full_page") for doc in matched_responses])

seen = set()
return_list = []

for doc in matched_responses:
full_page = doc.metadata.get("full_page")
if full_page not in seen:
seen.add(full_page)
return_list.append({
"full_page": full_page,
"filename": doc.metadata.get("filename"),
"file_uuid": doc.metadata.get("file_uuid"),
})

return return_list

def _search_docs_by_content_base_uuid(self, content_base_uuid: UUID, file_uuid: str = None):
search_filter = {
Expand Down

0 comments on commit 9985769

Please sign in to comment.