Prompt
How do I combine embeddings with keyword search?
Latest observation
Oct 10, 2026
OpenAI APIWeb search: off
A common way to combine embeddings with keyword search is to use a hybrid search pipeline:
1) Run both searches
- Keyword search: good for exact matches, IDs, names, rare terms, filters.
- Embedding/vector search: good for semantic similarity and paraphrases.
2) Merge the results
Typical approaches:
A. Weighted score fusion
Give each document:
- a keyword score
- a vector similarity score
Then combine them:
[ \text{final_score} = \alpha \cdot \text{vector_score} + (1-\alpha) \cdot \text{keyword_score} ]
Choose α based on your use case:
- higher
αif meaning matters more - lower
αif exact term matching matters more
B. Reciprocal Rank Fusion (RRF)
If your keyword and vector systems produce ranked lists, combine ranks instead of raw scores:
[ \text{RRF}(d) = \sum_i \frac{1}{k + rank_i(d)} ]
This is popular because it’s robust even when score scales differ.
C. Two-stage retrieval
- Use keyword search to get candidates
- Re-rank candidates with embeddings
Or the reverse:
- Vector search for candidates
- Boost exact keyword matches in re-ranking
3) Use metadata filters
Before or during retrieval, filter by:
- date
- category
- language
- permissions
- product type
This keeps search relevant and efficient.
4) Practical best practices
- Normalize scores before blending; keyword and vector scores often live on different scales.
- Use keyword search for:
- names
- codes
- error messages
- URLs
- exact phrases
- Use embeddings for:
- paraphrases
- conceptual matching
- natural language queries
- Consider stemming, synonyms, and phrase queries in keyword search.
5) Simple implementation pattern
- Build an inverted index for keyword search.
- Store embeddings in a vector database or ANN index.
- For each query:
- search both indexes
- retrieve top
Nfrom each - merge with RRF or weighted scoring
- optionally rerank with a cross-encoder/LLM
Example
Query: “reset my account password”
- Keyword search finds documents with “reset” and “password”
- Embedding search also finds “forgot credentials” or “change login details”
- Hybrid search returns both exact and semantically similar results
If you want, I can also show:
- a Python example
- an example using Elasticsearch/OpenSearch
- or a vector DB + BM25 hybrid architecture
Brands