Home / Function/ max_marginal_relevance_search_with_score_by_vector() — langchain Function Reference

max_marginal_relevance_search_with_score_by_vector() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8c904251_65de_1c34_8693_324e08819e7e["max_marginal_relevance_search_with_score_by_vector()"]
  2d095452_70a7_4606_a1b1_4650d16b5343["Qdrant"]
  8c904251_65de_1c34_8693_324e08819e7e -->|defined in| 2d095452_70a7_4606_a1b1_4650d16b5343
  2586e337_0d72_62cf_82fd_2b92844e2c0c["max_marginal_relevance_search_by_vector()"]
  2586e337_0d72_62cf_82fd_2b92844e2c0c -->|calls| 8c904251_65de_1c34_8693_324e08819e7e
  e51a8060_dfbc_bc2e_2d45_e5db47741681["_document_from_scored_point()"]
  8c904251_65de_1c34_8693_324e08819e7e -->|calls| e51a8060_dfbc_bc2e_2d45_e5db47741681
  style 8c904251_65de_1c34_8693_324e08819e7e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 984–1070

    def max_marginal_relevance_search_with_score_by_vector(
        self,
        embedding: list[float],
        k: int = 4,
        fetch_k: int = 20,
        lambda_mult: float = 0.5,
        filter: MetadataFilter | None = None,  # noqa: A002
        search_params: models.SearchParams | None = None,
        score_threshold: float | None = None,
        consistency: models.ReadConsistency | None = None,
        **kwargs: Any,
    ) -> list[tuple[Document, float]]:
        """Return docs selected using the maximal marginal relevance.

        Maximal marginal relevance optimizes for similarity to query AND diversity
        among selected documents.

        Args:
            embedding: Embedding vector to look up documents similar to.
            k: Number of Documents to return.
            fetch_k: Number of Documents to fetch to pass to MMR algorithm.
            lambda_mult: Number between `0` and `1` that determines the degree of
                diversity among the results with `0` corresponding to maximum diversity
                and `1` to minimum diversity.
            filter: Filter by metadata.
            search_params: Additional search params
            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 selected by maximal marginal relevance and
                distance for each.
        """
        query_vector = embedding
        if self.vector_name is not None:
            query_vector = (self.vector_name, query_vector)  # type: ignore[assignment]

        results = self.client.search(
            collection_name=self.collection_name,
            query_vector=query_vector,
            query_filter=filter,
            search_params=search_params,
            limit=fetch_k,
            with_payload=True,
            with_vectors=True,
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )
        embeddings = [
            result.vector.get(self.vector_name)  # type: ignore[index, union-attr]
            if self.vector_name is not None
            else result.vector
            for result in results
        ]
        mmr_selected = maximal_marginal_relevance(
            np.array(embedding), embeddings, k=k, lambda_mult=lambda_mult
        )
        return [
            (
                self._document_from_scored_point(
                    results[i],
                    self.collection_name,
                    self.content_payload_key,

Domain

Subdomains

Frequently Asked Questions

What does max_marginal_relevance_search_with_score_by_vector() do?
max_marginal_relevance_search_with_score_by_vector() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is max_marginal_relevance_search_with_score_by_vector() defined?
max_marginal_relevance_search_with_score_by_vector() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 984.
What does max_marginal_relevance_search_with_score_by_vector() call?
max_marginal_relevance_search_with_score_by_vector() calls 1 function(s): _document_from_scored_point.
What calls max_marginal_relevance_search_with_score_by_vector()?
max_marginal_relevance_search_with_score_by_vector() is called by 1 function(s): max_marginal_relevance_search_by_vector.

Analyze Your Own Codebase

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

Try Supermodel Free