Home / Function/ similarity_search_with_score_by_vector() — langchain Function Reference

similarity_search_with_score_by_vector() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f5c7d643_9c9c_c3ee_5be7_8f0b6359b191["similarity_search_with_score_by_vector()"]
  2d095452_70a7_4606_a1b1_4650d16b5343["Qdrant"]
  f5c7d643_9c9c_c3ee_5be7_8f0b6359b191 -->|defined in| 2d095452_70a7_4606_a1b1_4650d16b5343
  406ade67_c325_a78f_9b19_05989a520071["similarity_search_with_score()"]
  406ade67_c325_a78f_9b19_05989a520071 -->|calls| f5c7d643_9c9c_c3ee_5be7_8f0b6359b191
  32792606_a0d0_d540_c856_6b4ab038293f["similarity_search_by_vector()"]
  32792606_a0d0_d540_c856_6b4ab038293f -->|calls| f5c7d643_9c9c_c3ee_5be7_8f0b6359b191
  369cad42_a217_229d_f010_ae322d9fc342["_qdrant_filter_from_dict()"]
  f5c7d643_9c9c_c3ee_5be7_8f0b6359b191 -->|calls| 369cad42_a217_229d_f010_ae322d9fc342
  e51a8060_dfbc_bc2e_2d45_e5db47741681["_document_from_scored_point()"]
  f5c7d643_9c9c_c3ee_5be7_8f0b6359b191 -->|calls| e51a8060_dfbc_bc2e_2d45_e5db47741681
  style f5c7d643_9c9c_c3ee_5be7_8f0b6359b191 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 541–627

    def similarity_search_with_score_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[tuple[Document, float]]:
        """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 documents most similar to the query text and distance for each.

        """
        if filter is not None and isinstance(filter, dict):
            warnings.warn(
                "Using dict as a `filter` is deprecated. Please use qdrant-client "
                "filters directly: "
                "https://qdrant.tech/documentation/concepts/filtering/",
                DeprecationWarning,
                stacklevel=2,
            )
            qdrant_filter = self._qdrant_filter_from_dict(filter)
        else:
            qdrant_filter = filter

        query_vector = embedding
        if self.vector_name is not None:
            query_vector = (self.vector_name, embedding)  # type: ignore[assignment]

        results = self.client.search(
            collection_name=self.collection_name,
            query_vector=query_vector,
            query_filter=qdrant_filter,
            search_params=search_params,
            limit=k,
            offset=offset,
            with_payload=True,
            with_vectors=False,  # LangChain does not expect vectors to be returned
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )
        return [
            (
                self._document_from_scored_point(
                    result,
                    self.collection_name,
                    self.content_payload_key,

Domain

Subdomains

Frequently Asked Questions

What does similarity_search_with_score_by_vector() do?
similarity_search_with_score_by_vector() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is similarity_search_with_score_by_vector() defined?
similarity_search_with_score_by_vector() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 541.
What does similarity_search_with_score_by_vector() call?
similarity_search_with_score_by_vector() calls 2 function(s): _document_from_scored_point, _qdrant_filter_from_dict.
What calls similarity_search_with_score_by_vector()?
similarity_search_with_score_by_vector() is called by 2 function(s): similarity_search_by_vector, similarity_search_with_score.

Analyze Your Own Codebase

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

Try Supermodel Free