Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 6 · 5. Retrieval & RAG Patterns
Lesson 39 of 68

Similarity vs MMR

Diversity leads to better answers. Avoiding the echo chamber.

Derpx0610 Jan · 1 min read
LangChain Mastery
The Retriever InterfaceSimilarity vs MMRMulti-Query RetrievalRAG-FusionQuery DecompositionParent Document RetrievalContextual CompressionPost-Retrieval Re-RankingConversational RAG & History
Contents
1. The Trap of Redundancy2. Maximal Marginal Relevance (MMR)3. The Result4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
The Retriever InterfaceSimilarity vs MMRMulti-Query RetrievalRAG-FusionQuery DecompositionParent Document RetrievalContextual CompressionPost-Retrieval Re-RankingConversational RAG & History
Contents
1. The Trap of Redundancy2. Maximal Marginal Relevance (MMR)3. The Result4. Summary

1. The Trap of Redundancy

User asks: "Tell me about the iPhone 15 camera."

Similarity Search (k=4) returns:

  1. iPhone 15 has a 48MP camera.
  2. The camera on iPhone 15 is 48MP.
  3. The iPhone 15 features a 48MP sensor.
  4. 48MP is the resolution of the iPhone 15.

The LLM gets 4 versions of the same sentence. It misses info about "Night Mode," "Zoom," or "Video." This is Redundancy Collapse.

2. Maximal Marginal Relevance (MMR)

MMR tries to maximize Relevance (Similarity) while punishing Redundancy (Similarity to already selected docs).

Algorithm intuition:

  1. Find the most similar doc (Doc A). Select it.
  2. Find the next doc that is similar to Query BUT dissimilar to Doc A.
  3. Repeat.

3. The Result

MMR (k=4) returns:

  1. iPhone 15 has a 48MP camera. (High Relevance)
  2. Night Mode is improved by 2x. (High Relevance, Low overlap with #1)
  3. Video supports 4K60. (High Relevance, Low overlap with #1, #2)
  4. The new Telephoto lens is 5x. (High Relevance, Low overlap with #1, #2, #3)

4. Summary

If your RAG answers feel repetitive or shallow, switch to MMR. It forces the retriever to explore the "Concept Space" rather than getting stuck in one corner.

Key Intuition: "Don't tell me the same thing 5 times."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonThe Retriever InterfaceNext lesson →Multi-Query Retrieval