Home / Function/ similarity_search() — langchain Function Reference

similarity_search() — langchain Function Reference

Architecture documentation for the similarity_search() function in vectorstores.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  cfa891db_5c93_01da_45e0_d39950f0b51e["similarity_search()"]
  2d095452_70a7_4606_a1b1_4650d16b5343["Qdrant"]
  cfa891db_5c93_01da_45e0_d39950f0b51e -->|defined in| 2d095452_70a7_4606_a1b1_4650d16b5343
  406ade67_c325_a78f_9b19_05989a520071["similarity_search_with_score()"]
  cfa891db_5c93_01da_45e0_d39950f0b51e -->|calls| 406ade67_c325_a78f_9b19_05989a520071
  style cfa891db_5c93_01da_45e0_d39950f0b51e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 225–281

    def similarity_search(
        self,
        query: str,
        k: int = 4,
        filter: MetadataFilter | None = None,  # noqa: A002
        search_params: models.SearchParams | None = None,
        offset: int = 0,
        score_threshold: float | None = None,
        consistency: models.ReadConsistency | None = None,
        **kwargs: Any,
    ) -> list[Document]:
        """Return docs most similar to query.

        Args:
            query: Text to look up documents similar to.
            k: Number of Documents to return.
            filter: Filter by metadata.
            search_params: Additional search params
            offset:
                Offset of the first result to return.
                May be used to paginate results.
                Note: large offset values may cause performance issues.
            score_threshold:
                Define a minimal score threshold for the result.
                If defined, less similar results will not be returned.
                Score of the returned result might be higher or smaller than the
                threshold depending on the Distance function used.
                E.g. for cosine similarity only higher scores will be returned.
            consistency:
                Read consistency of the search. Defines how many replicas should be
                queried before returning the result.
                Values:
                - int - number of replicas to query, values should present in all
                        queried replicas
                - 'majority' - query all replicas, but return values present in the
                               majority of replicas
                - 'quorum' - query the majority of replicas, return values present in
                             all of them
                - 'all' - query all replicas, and return values present in all replicas
            **kwargs:
                Any other named arguments to pass through to QdrantClient.search()

        Returns:
            List of `Document` objects most similar to the query.

        """
        results = self.similarity_search_with_score(
            query,
            k,
            filter=filter,
            search_params=search_params,
            offset=offset,
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )
        return list(map(itemgetter(0), results))

Domain

Subdomains

Frequently Asked Questions

What does similarity_search() do?
similarity_search() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is similarity_search() defined?
similarity_search() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 225.
What does similarity_search() call?
similarity_search() calls 1 function(s): similarity_search_with_score.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free