asimilarity_search_with_relevance_scores() — langchain Function Reference
Architecture documentation for the asimilarity_search_with_relevance_scores() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9136aa9f_d720_ee5b_3f80_83c18d3e014d["asimilarity_search_with_relevance_scores()"] 6c336ac6_f55c_1ad7_6db3_73dbd71fb625["VectorStore"] 9136aa9f_d720_ee5b_3f80_83c18d3e014d -->|defined in| 6c336ac6_f55c_1ad7_6db3_73dbd71fb625 b6e9997b_7438_0977_d32b_03004dbd76a9["asearch()"] b6e9997b_7438_0977_d32b_03004dbd76a9 -->|calls| 9136aa9f_d720_ee5b_3f80_83c18d3e014d b39b9863_1373_282b_c5cb_bebb545f3276["_aget_relevant_documents()"] b39b9863_1373_282b_c5cb_bebb545f3276 -->|calls| 9136aa9f_d720_ee5b_3f80_83c18d3e014d 37ad19f9_1964_1b28_9306_a16c8d128f6e["_asimilarity_search_with_relevance_scores()"] 9136aa9f_d720_ee5b_3f80_83c18d3e014d -->|calls| 37ad19f9_1964_1b28_9306_a16c8d128f6e style 9136aa9f_d720_ee5b_3f80_83c18d3e014d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/vectorstores/base.py lines 556–604
async def asimilarity_search_with_relevance_scores(
self,
query: str,
k: int = 4,
**kwargs: Any,
) -> list[tuple[Document, float]]:
"""Async return docs and relevance scores in the range `[0, 1]`.
`0` is dissimilar, `1` is most similar.
Args:
query: Input text.
k: Number of `Document` objects to return.
**kwargs: Kwargs to be passed to similarity search.
Should include `score_threshold`, an optional floating point value
between `0` to `1` to filter the resulting set of retrieved docs.
Returns:
List of tuples of `(doc, similarity_score)`
"""
score_threshold = kwargs.pop("score_threshold", None)
docs_and_similarities = await self._asimilarity_search_with_relevance_scores(
query, k=k, **kwargs
)
if any(
similarity < 0.0 or similarity > 1.0
for _, similarity in docs_and_similarities
):
warnings.warn(
"Relevance scores must be between"
f" 0 and 1, got {docs_and_similarities}",
stacklevel=2,
)
if score_threshold is not None:
docs_and_similarities = [
(doc, similarity)
for doc, similarity in docs_and_similarities
if similarity >= score_threshold
]
if len(docs_and_similarities) == 0:
logger.warning(
"No relevant docs were retrieved using the "
"relevance score threshold %s",
score_threshold,
)
return docs_and_similarities
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does asimilarity_search_with_relevance_scores() do?
asimilarity_search_with_relevance_scores() is a function in the langchain codebase, defined in libs/core/langchain_core/vectorstores/base.py.
Where is asimilarity_search_with_relevance_scores() defined?
asimilarity_search_with_relevance_scores() is defined in libs/core/langchain_core/vectorstores/base.py at line 556.
What does asimilarity_search_with_relevance_scores() call?
asimilarity_search_with_relevance_scores() calls 1 function(s): _asimilarity_search_with_relevance_scores.
What calls asimilarity_search_with_relevance_scores()?
asimilarity_search_with_relevance_scores() is called by 2 function(s): _aget_relevant_documents, asearch.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free