Key Concepts

February 25, 2026 ยท View on GitHub

New to RAG? This 60-second primer explains what's happening under the hood.

How RAG Retrieval Works

flowchart LR
    A[๐Ÿ“„ Documents] --> B[Chunker]
    B --> C[Embedder]
    C --> D[(Vector DB)]
    
    E[โ“ Query] --> F[Embedder]
    F --> G{Similarity\nSearch}
    D --> G
    G --> H[๐ŸŽฏ Top-K Results]

Terminology

TermWhat It Means
EmbeddingText converted to a vector (list of numbers representing meaning). Similar texts have similar vectors.
ChunkA piece of a document. Long docs are split into chunks before embedding.
Similarity score0-1 scale. Higher = query and chunk have more similar meaning.
Top-KReturn the K most similar chunks to your query.

Why Chunk Size Matters

Document: "To reset your password, go to Settings, click Security, 
           then click Reset Password. You'll receive an email..."

Chunk size 100:  ["To reset your password, go to", 
                  "Settings, click Security, then",
                  "click Reset Password. You'll..."]
                  โ†’ Query matches piece 1, but context is scattered

Chunk size 500:  ["To reset your password, go to Settings, 
                   click Security, then click Reset Password. 
                   You'll receive an email..."]
                  โ†’ Full context preserved in one chunk

Too small = context gets split, retrieval misses connections
Too large = noise drowns out relevant parts

Score Interpretation

Score RangeMeaningAction
0.90+Excellent matchExactly what user asked
0.75-0.90Good matchRelevant, may need refinement
0.60-0.75Weak matchMight be relevant, or noise
< 0.60Poor matchLikely not what user wants

What Good Metrics Look Like

MetricPoorAcceptableGoodExcellent
Recall@5< 0.600.60โ€“0.750.75โ€“0.90> 0.90
MRR< 0.500.50โ€“0.700.70โ€“0.85> 0.85
NDCG@5< 0.500.50โ€“0.700.70โ€“0.85> 0.85
Coverage< 0.700.70โ€“0.850.85โ€“0.95> 0.95
NeedleCoverage@5< 0.300.30โ€“0.500.50โ€“0.75> 0.75
Latency p95> 500ms200โ€“500ms50โ€“200ms< 50ms

Context matters:

  • Legal/medical domains: aim for Excellent (accuracy critical)
  • Customer support: Good is often sufficient
  • Creative/exploration: Acceptable may be fine

Metrics Explained

MetricDescription
Recall@KFraction of relevant docs found in top-K results
MRRMean Reciprocal Rank โ€” how high the first relevant result ranks
NDCG@KNormalized Discounted Cumulative Gain โ€” rewards good ranking of ALL results
CoverageFraction of relevant docs ever retrieved across all queries
RedundancyAverage times a doc is retrieved (detects over-representation)
Diversity@KFraction of unique docs in top-K (detects wasted slots from duplicates)
NeedleCoverage@KFraction of specific answer spans ("needles") found in retrieved chunks. Catches cases where the right document is retrieved but the actual content needed to answer the question is missing from the chunks. Activated automatically when queries include needles annotations.

Next Steps