What is Semantic Search?
Semantic search finds results based on meaning rather than exact keyword matches. "cheap flights" can find results about "affordable airfare".
Keyword vs Semantic
| Aspect | Keyword Search | Semantic Search |
|---|---|---|
| Matching | Exact terms | Meaning |
| Synonyms | Needs manual config | Automatic |
| Typos | Breaks search | Often works |
| Setup | Simple | Needs embeddings |
| Speed | Very fast | Fast (with index) |
How It Works
- Index: Convert all documents to embeddings
- Query: Convert search query to embedding
- Search: Find nearest neighbors
- Return: Most similar documents
Implementation
# Index documents
documents = ["...", "...", "..."]
doc_embeddings = model.encode(documents)
index.add(doc_embeddings)
# Search
query = "how to cook pasta"
query_embedding = model.encode(query)
results = index.search(query_embedding, k=10)
Hybrid Search
Best results often combine both approaches:
- Keyword for exact matches (product SKUs, names)
- Semantic for conceptual queries
- Rerank combined results
Use Cases
- Document search
- FAQ matching
- Product discovery
- Code search
- Support ticket routing
Improving Quality
- Choose appropriate embedding model
- Add metadata filtering
- Use reranking models
- Fine-tune embeddings on your domain