Home / Function/ similarity_search_by_vector() — langchain Function Reference

similarity_search_by_vector() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6a3478b4_fa50_7588_03e1_77e7f3ca09fc["similarity_search_by_vector()"]
  bf62db79_4217_463c_798f_6f8528ed0d6e["Qdrant"]
  6a3478b4_fa50_7588_03e1_77e7f3ca09fc -->|defined in| bf62db79_4217_463c_798f_6f8528ed0d6e
  6c8c9cf1_343a_b7b2_1ac5_f0f159c55037["similarity_search_with_score_by_vector()"]
  6a3478b4_fa50_7588_03e1_77e7f3ca09fc -->|calls| 6c8c9cf1_343a_b7b2_1ac5_f0f159c55037
  style 6a3478b4_fa50_7588_03e1_77e7f3ca09fc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 423–479

    def similarity_search_by_vector(
        self,
        embedding: list[float],
        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 embedding vector.

        Args:
            embedding: Embedding vector 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_by_vector(
            embedding,
            k,
            filter=filter,
            search_params=search_params,
            offset=offset,
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )
        return list(map(itemgetter(0), results))

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free