Your semantic search fails for short queries (1–3 words). How do you improve it?
NLPLevel: IntermediateTroubleshooting Scenarios
Your semantic search fails for short queries (1–3 words). How do you improve it?
Hints
- Separate text representation, modeling and evaluation.
- Check ambiguity, rare terms and training versus target text distributions.
Answer
Short queries produce poor embeddings — one token embeddings are ambiguous:
- "Python" → programming language? snake? Monty Python?
Fixes:
- HyDE (Hypothetical Document Embeddings): generate a hypothetical full answer to the short query, embed that
- Query expansion: use an LLM to expand the short query into a full sentence: "Python" → "Python programming language tutorial and documentation"
- Keyword augmentation: combine vector search with BM25 — keyword search works well for short, specific queries
- Contextual queries: use conversation context to expand the query (if user asked about programming earlier, "Python" is the language)
Source and licence: JustInCache & contributors — Awesome AI Interviews · Apache-2.0