Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: implement qdrant _aembed_query and use it in other async funcs #19155

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions libs/community/langchain_community/vectorstores/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ async def asimilarity_search_with_score(
Returns:
List of documents most similar to the query text and distance for each.
"""
query_embedding = await self._aembed_query(query)
return await self.asimilarity_search_with_score_by_vector(
self._embed_query(query),
query_embedding,
k,
filter=filter,
search_params=search_params,
Expand Down Expand Up @@ -841,7 +842,7 @@ async def amax_marginal_relevance_search(
Returns:
List of Documents selected by maximal marginal relevance.
"""
query_embedding = self._embed_query(query)
query_embedding = await self._aembed_query(query)
return await self.amax_marginal_relevance_search_by_vector(
query_embedding,
k=k,
Expand Down Expand Up @@ -2022,6 +2023,26 @@ def _embed_query(self, query: str) -> List[float]:
raise ValueError("Neither of embeddings or embedding_function is set")
return embedding.tolist() if hasattr(embedding, "tolist") else embedding

async def _aembed_query(self, query: str) -> List[float]:
"""Embed query text asynchronously.

Used to provide backward compatibility with `embedding_function` argument.

Args:
query: Query text.

Returns:
List of floats representing the query embedding.
"""
if self.embeddings is not None:
embedding = await self.embeddings.aembed_query(query)
else:
if self._embeddings_function is not None:
embedding = self._embeddings_function(query)
else:
raise ValueError("Neither of embeddings or embedding_function is set")
return embedding.tolist() if hasattr(embedding, "tolist") else embedding

def _embed_texts(self, texts: Iterable[str]) -> List[List[float]]:
"""Embed search texts.

Expand Down