similarity_search_with_score() — langchain Function Reference
Architecture documentation for the similarity_search_with_score() function in vectorstores.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0a7f571a_baf1_50bb_32f7_1d2d10e43076["similarity_search_with_score()"] babbef04_3a0c_25f4_58a8_9d3209d5867e["Chroma"] 0a7f571a_baf1_50bb_32f7_1d2d10e43076 -->|defined in| babbef04_3a0c_25f4_58a8_9d3209d5867e 4c9c3785_e011_cdde_a2f4_4297d10bd826["similarity_search()"] 4c9c3785_e011_cdde_a2f4_4297d10bd826 -->|calls| 0a7f571a_baf1_50bb_32f7_1d2d10e43076 fa232e14_1436_226d_41f9_e49eff05c0d0["_results_to_docs_and_scores()"] 0a7f571a_baf1_50bb_32f7_1d2d10e43076 -->|calls| fa232e14_1436_226d_41f9_e49eff05c0d0 style 0a7f571a_baf1_50bb_32f7_1d2d10e43076 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/chroma/langchain_chroma/vectorstores.py lines 817–857
def similarity_search_with_score(
self,
query: str,
k: int = DEFAULT_K,
filter: dict[str, str] | None = None, # noqa: A002
where_document: dict[str, str] | None = None,
**kwargs: Any,
) -> list[tuple[Document, float]]:
"""Run similarity search with Chroma with distance.
Args:
query: Query text to search for.
k: Number of results to return.
filter: Filter by metadata.
where_document: dict used to filter by document contents.
E.g. {"$contains": "hello"}.
kwargs: Additional keyword arguments to pass to Chroma collection query.
Returns:
List of documents most similar to the query text and
distance in float for each. Lower score represents more similarity.
"""
if self._embedding_function is None:
results = self.__query_collection(
query_texts=[query],
n_results=k,
where=filter,
where_document=where_document,
**kwargs,
)
else:
query_embedding = self._embedding_function.embed_query(query)
results = self.__query_collection(
query_embeddings=[query_embedding],
n_results=k,
where=filter,
where_document=where_document,
**kwargs,
)
return _results_to_docs_and_scores(results)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does similarity_search_with_score() do?
similarity_search_with_score() is a function in the langchain codebase, defined in libs/partners/chroma/langchain_chroma/vectorstores.py.
Where is similarity_search_with_score() defined?
similarity_search_with_score() is defined in libs/partners/chroma/langchain_chroma/vectorstores.py at line 817.
What does similarity_search_with_score() call?
similarity_search_with_score() calls 1 function(s): _results_to_docs_and_scores.
What calls similarity_search_with_score()?
similarity_search_with_score() is called by 1 function(s): similarity_search.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free