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 base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  efca5a17_7174_3316_46ec_3b51abde1db2["amax_marginal_relevance_search()"]
  6c336ac6_f55c_1ad7_6db3_73dbd71fb625["VectorStore"]
  efca5a17_7174_3316_46ec_3b51abde1db2 -->|defined in| 6c336ac6_f55c_1ad7_6db3_73dbd71fb625
  b6e9997b_7438_0977_d32b_03004dbd76a9["asearch()"]
  b6e9997b_7438_0977_d32b_03004dbd76a9 -->|calls| efca5a17_7174_3316_46ec_3b51abde1db2
  b39b9863_1373_282b_c5cb_bebb545f3276["_aget_relevant_documents()"]
  b39b9863_1373_282b_c5cb_bebb545f3276 -->|calls| efca5a17_7174_3316_46ec_3b51abde1db2
  style efca5a17_7174_3316_46ec_3b51abde1db2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/vectorstores/base.py lines 686–722

    async def amax_marginal_relevance_search(
        self,
        query: str,
        k: int = 4,
        fetch_k: int = 20,
        lambda_mult: float = 0.5,
        **kwargs: Any,
    ) -> list[Document]:
        """Async 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 `Document` objects to return.
            fetch_k: Number of `Document` objects 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.
            **kwargs: Arguments to pass to the search method.

        Returns:
            List of `Document` objects selected by maximal marginal relevance.
        """
        # This is a temporary workaround to make the similarity search
        # asynchronous. The proper solution is to make the similarity search
        # asynchronous in the vector store implementations.
        return await run_in_executor(
            None,
            self.max_marginal_relevance_search,
            query,
            k=k,
            fetch_k=fetch_k,
            lambda_mult=lambda_mult,
            **kwargs,
        )

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/core/langchain_core/vectorstores/base.py.
Where is amax_marginal_relevance_search() defined?
amax_marginal_relevance_search() is defined in libs/core/langchain_core/vectorstores/base.py at line 686.
What calls amax_marginal_relevance_search()?
amax_marginal_relevance_search() is called by 2 function(s): _aget_relevant_documents, asearch.

Analyze Your Own Codebase

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

Try Supermodel Free