LangChain

Advanced Retrieval: Maximum Marg in al 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).

SS
Soham Sharma
AI Engineer, Botmartz · July 17, 2026 · 1 min read
Read Time
1 min
Failure Modes
5
Code Snippets
3
Runnable Notebook
1
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.

# 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.

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.

Closing Takeaways

Measure retrieval precision and recall in isolation before touching the model.
Chunk along document structure, not arbitrary character counts.
Combine vector and keyword search — hybrid retrieval beats either alone.
Treat evaluation as continuous infrastructure, not a launch-week report.
Try It Yourself
A runnable Google Colab notebook with the eval harness and hybrid search code from this post.
#LangChain#Retrieval#Advanced Techniques#RAG#Search
0 views
SS
Soham Sharma
AI Engineer at Botmartz, building enterprise RAG and agent systems in production. Contributing to open-source libraries.

Discussion (0)

No approved comments yet. Be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *

More Engineering Insights
TensorFlow>-
Soham Sharma · 8 min read
GeneralPlaywright E2E Test Post
Integration Bot · 5 min read