Skip to main content
PreparationZone Logo
PrepZone

Similarity, Keyword, and Hybrid Retrieval

Vector search, BM25 scoring, and the hybrid architecture that beats either method alone.

Pass checkpoint below

Read these first

Why this matters

  • PolicyDesk's vector search missed "casual leave" when employees typed the exact phrase "CL entitlement," which exists only as an acronym in the handbook.
  • BM25 caught the acronym. Vectors caught "time off." Hybrid search is how you stop choosing.
  • Interviewers ask you to write the BM25 idea, not to derive it from scratch, and to say when keyword search still wins.
  • The rest of the pipeline is decoration if top-k is the wrong pages.

Three families

TechniqueWhat it matchesBest atWeak at
Similarity (vector) searchMeaning, via embeddingsParaphrase: 'time off' finds 'privilege leave'Rare exact tokens: error codes, acronyms, SKUs, section numbers
Keyword / lexical searchTerms, usually BM25Exact words, names, codes, and phrases that must appearSynonyms and paraphrases the user did not type
HybridBoth, then a fused rankingReal questions, which mix meaning and exact termsMore moving parts: two indexes and a fusion rule
  • Similarity (vector) search

    What it matchesMeaning, via embeddings
    Best atParaphrase: 'time off' finds 'privilege leave'
    Weak atRare exact tokens: error codes, acronyms, SKUs, section numbers
  • Keyword / lexical search

    What it matchesTerms, usually BM25
    Best atExact words, names, codes, and phrases that must appear
    Weak atSynonyms and paraphrases the user did not type
  • Hybrid

    What it matchesBoth, then a fused ranking
    Best atReal questions, which mix meaning and exact terms
    Weak atMore moving parts: two indexes and a fusion rule

Most production RAG systems that survive contact with employees use hybrid search. Pure vectors feel magical in a demo and fail on the policy code "CL-2." Pure keywords fail the moment someone asks in their own words.

Similarity search

You embed the query, embed (already stored) chunks, and rank by cosine, Euclidean distance, or dot product. The top k chunks go forward.

User query
Embedding model
Query vector
Vector databaseTop-k chunks
The embedding model is shared. The database returns text, not only scores.

k is a product decision. k=3 keeps the prompt tight and fails if the answer is split across chunks 4 and 5. k=20 pastes a noisy dossier and the model may attend to the wrong paragraph. Start at 4 to 8 for a handbook, then measure whether the gold chunk appears in the set. That measurement is Recall@k, defined in the evaluation lesson.

Java
# Shape of a vector query. Client method names differ by version.
hits = client.query_points(
    collection_name="hr_docs",
    query=query_vector,
    limit=5,
).points
for hit in hits:
    print(hit.score, hit.payload["text"])

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Keyword search and BM25
  • Hybrid search
  • Choosing deliberately

Test yourself

Answer these before moving on — recall is what makes it stick.