Home / Function/ amax_marginal_relevance_search() — langchain Function Reference

amax_marginal_relevance_search() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  32137f96_4258_744f_9902_4d022e824899["amax_marginal_relevance_search()"]
  2d095452_70a7_4606_a1b1_4650d16b5343["Qdrant"]
  32137f96_4258_744f_9902_4d022e824899 -->|defined in| 2d095452_70a7_4606_a1b1_4650d16b5343
  b6daed04_d43f_da3b_07c7_c1835c32cf84["_aembed_query()"]
  32137f96_4258_744f_9902_4d022e824899 -->|calls| b6daed04_d43f_da3b_07c7_c1835c32cf84
  0ec7a2c6_a51b_581a_7363_858cc7222d22["amax_marginal_relevance_search_by_vector()"]
  32137f96_4258_744f_9902_4d022e824899 -->|calls| 0ec7a2c6_a51b_581a_7363_858cc7222d22
  style 32137f96_4258_744f_9902_4d022e824899 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/qdrant/langchain_qdrant/vectorstores.py lines 788–851

    async def amax_marginal_relevance_search(
        self,
        query: str,
        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:
            query: Text 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
                `AsyncQdrantClient.Search()`.

        Returns:
            List of `Document` objects selected by maximal marginal relevance.

        """
        query_embedding = await self._aembed_query(query)
        return await self.amax_marginal_relevance_search_by_vector(
            query_embedding,
            k=k,
            fetch_k=fetch_k,
            lambda_mult=lambda_mult,
            filter=filter,
            search_params=search_params,
            score_threshold=score_threshold,
            consistency=consistency,
            **kwargs,
        )

Domain

Subdomains

Frequently Asked Questions

What does amax_marginal_relevance_search() do?
amax_marginal_relevance_search() is a function in the langchain codebase, defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py.
Where is amax_marginal_relevance_search() defined?
amax_marginal_relevance_search() is defined in libs/partners/qdrant/langchain_qdrant/vectorstores.py at line 788.
What does amax_marginal_relevance_search() call?
amax_marginal_relevance_search() calls 2 function(s): _aembed_query, amax_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