Skip to main content
Botmartz AI Solutions Private Limited
LANGCHAIN

Advanced Retrieval: Maximum Marginal Relevance (MMR), Self-Query, and Parent-Document Retrieval

Simple similarity search returns similar but redundant results. Learn MMR (diverse results), self-query (metadata filtering), and parent-document retrieval (better context).

Soham Sharma
Soham Sharma
AI Engineer, Botmartz · Dec 4, 2026
Depth
Full Spec
Failure Modes
5
Code Snippets
4
Runnable Notebook
0
Advanced Retrieval: Maximum Marginal Relevance (MMR), Self-Query, and Parent-Document Retrieval

Basic similarity search retrieves the most similar documents—but they may be redundant. Advanced retrievers address this: MMR balances similarity and diversity, self-query filters by metadata, parent-document retrieval chunks contextually. This post covers each strategy and when to use them.

Maximum Marginal Relevance (MMR)

MMR returns diverse results: similar to the query but different from each other.

Code Snippet
# MMR retrieval
results = vector_store.max_marginal_relevance_search(
    "What is semantic search?",
    k=5,
    fetch_k=20,  # Retrieve more candidates
    lambda_mult=0.25  # Balance: 0=diversity, 1=similarity
)

Self-Query Retrieval

Translate user queries into metadata filters + similarity search.

Code Snippet
from langchain.retrievers.self_query.base import SelfQueryRetriever

retriever = SelfQueryRetriever.from_llm_and_db(
    llm=llm,
    db=vector_store,
    document_content_description="Academic papers"
)

# Automatically filters by year=2024, then searches
results = retriever.get_relevant_documents("Papers from 2024 about transformers")

Conclusion

Advanced retrieval improves quality: MMR adds diversity, self-query adds filtering, parent-document retrieval preserves context. Choosing the right retriever depends on your data and queries. Next: evaluating RAG systems with LangSmith to measure faithfulness and relevance.

#LangChain#Retrieval#Advanced Techniques#RAG#Search
1 views
Soham Sharma
Soham Sharma
Leading AI systems research, enterprise RAG, and multi-agent workflow architecture at Botmartz AI Solutions.