max_marginal_relevance_search() — langchain Function Reference
Architecture documentation for the max_marginal_relevance_search() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e6447f07_ba7b_8372_40bb_6d29265eb1a8["max_marginal_relevance_search()"] 6c336ac6_f55c_1ad7_6db3_73dbd71fb625["VectorStore"] e6447f07_ba7b_8372_40bb_6d29265eb1a8 -->|defined in| 6c336ac6_f55c_1ad7_6db3_73dbd71fb625 bacd4785_4aaa_2a48_7d2a_aaff3f343f40["search()"] bacd4785_4aaa_2a48_7d2a_aaff3f343f40 -->|calls| e6447f07_ba7b_8372_40bb_6d29265eb1a8 c524ddff_060d_d388_e89e_f62f4a167558["_get_relevant_documents()"] c524ddff_060d_d388_e89e_f62f4a167558 -->|calls| e6447f07_ba7b_8372_40bb_6d29265eb1a8 style e6447f07_ba7b_8372_40bb_6d29265eb1a8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/vectorstores/base.py lines 659–684
def max_marginal_relevance_search(
self,
query: str,
k: int = 4,
fetch_k: int = 20,
lambda_mult: float = 0.5,
**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 `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.
"""
raise NotImplementedError
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does max_marginal_relevance_search() do?
max_marginal_relevance_search() is a function in the langchain codebase, defined in libs/core/langchain_core/vectorstores/base.py.
Where is max_marginal_relevance_search() defined?
max_marginal_relevance_search() is defined in libs/core/langchain_core/vectorstores/base.py at line 659.
What calls max_marginal_relevance_search()?
max_marginal_relevance_search() is called by 2 function(s): _get_relevant_documents, search.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free