Beyond Keyword Search
Traditional search (like Elasticsearch with BM25) matches keywords. If you search "how to cancel my subscription" but the doc says "steps to terminate your account," keyword search might miss it. Semantic search understands that "cancel subscription" and "terminate account" mean the same thing.
How It Works
An embedding model (like OpenAI's text-embedding-3-small or the open-source BGE-large) converts text into a vector — an array of numbers that captures meaning. Similar meanings produce similar vectors. You find relevant documents by finding the nearest vectors to your query.
# Semantic similarity in action
embed("cancel my subscription")
→ [0.23, -0.41, 0.87, ...]
embed("terminate your account")
→ [0.21, -0.39, 0.85, ...]
cosine_similarity = 0.94 # very similar!
embed("today's weather forecast")
→ [-0.65, 0.12, -0.33, ...]
cosine_similarity = 0.11 # not similar
This is the magic of RAG. Embedding models compress the meaning of text into vectors, and vector databases find the nearest neighbors in milliseconds — even across millions of documents.