Home / Function/ max_marginal_relevance_search_by_vector() — langchain Function Reference

max_marginal_relevance_search_by_vector() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  356b00a0_41fb_37f6_c2e0_41baee3bf61a["max_marginal_relevance_search_by_vector()"]
  bf62db79_4217_463c_798f_6f8528ed0d6e["Qdrant"]
  356b00a0_41fb_37f6_c2e0_41baee3bf61a -->|defined in| bf62db79_4217_463c_798f_6f8528ed0d6e
  c17a2c48_ebf6_0c5a_fc95_55ab8d53b4a8["max_marginal_relevance_search()"]
  c17a2c48_ebf6_0c5a_fc95_55ab8d53b4a8 -->|calls| 356b00a0_41fb_37f6_c2e0_41baee3bf61a
  4b9f243e_cca1_f266_85ad_e0317f60aa3e["max_marginal_relevance_search_with_score_by_vector()"]
  356b00a0_41fb_37f6_c2e0_41baee3bf61a -->|calls| 4b9f243e_cca1_f266_85ad_e0317f60aa3e
  style 356b00a0_41fb_37f6_c2e0_41baee3bf61a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 853–915

    def max_marginal_relevance_search_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[Document]:
        """Return docs selected using the maximal marginal relevance.

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

        Args:
            embedding: Embedding 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.

        """
        results = self.max_marginal_relevance_search_with_score_by_vector(
            embedding,
            k=k,
            fetch_k=fetch_k,
            lambda_mult=lambda_mult,
            filter=filter,
            search_params=search_params,
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )
        return list(map(itemgetter(0), results))

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free