Skip to content

Commit

Permalink
async implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bluearrow98 committed Feb 13, 2025
1 parent b7c0c1e commit d8e9d7c
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,26 @@ def _get_relevant_documents(
)
)
return docs[: self.k]

async def _aget_relevant_documents(
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
) -> List[Document]:
"""
Async implementation of the retriever
Async client (from elasticsearch import AsyncElasticsearch) need to be passed as an attribute to the class before invoking.

Check failure on line 193 in libs/community/langchain_community/retrievers/elastic_search_bm25.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.13

Ruff (E501)

langchain_community/retrievers/elastic_search_bm25.py:193:89: E501 Line too long (135 > 88)

Check failure on line 193 in libs/community/langchain_community/retrievers/elastic_search_bm25.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.9

Ruff (E501)

langchain_community/retrievers/elastic_search_bm25.py:193:89: E501 Line too long (135 > 88)
"""
query_dict = self.build_query_body(query)
res = await self.client.search(
index=self.index_name, body=query_dict, source=["content", "metadata"]
)

docs = []
for r in res["hits"]["hits"]:
docs.append(
Document(
metadata=r["_source"]["metadata"],
page_content=r["_source"]["content"],
)
)
return docs[: self.k]

0 comments on commit d8e9d7c

Please sign in to comment.