Notes

Semantic Search

Search used to mean matching words. Semantic search matches meaning — ask it how to stop a laptop from overheating and it returns a page about thermal throttling that shares not one word with the question.

Meaning as coordinates

An embedding model turns each chunk of text into a vector of a few hundred to a few thousand numbers, positioned so that passages about the same thing land near each other. Documents are embedded once, ahead of time, and stored. At query time the question goes through the same model and the store returns the nearest vectors by cosine similarity. Nearest is computed approximately — an HNSW or IVF index inside Faiss, Pinecone or pgvector — because an exact scan over millions of vectors is too slow to sit inside a request.

Where it wins and where it loses
  • Wins on paraphrase, synonyms and questions worded nothing like the source text, which is why it is the retrieval half of nearly every RAG system.
  • Loses on exact tokens: a part number, an error code, a surname, a rare acronym. Keyword search finds those; an embedding smooths them away.
  • Hence production retrieval is usually hybrid — BM25 and vector scores combined, then reordered by a reranker.
Why it matters

A grounded answer is only as good as the passage that was fetched. When semantic search misses, the model has no way to know something is missing — it answers confidently from whatever came back, which is how a well-built stack still serves a wrong answer. The embedding model and the chunk size therefore set the ceiling for the whole system, and both are decided before the language model sees a single token.

Semantic search retrieves text by meaning instead of by shared words. An embedding model maps every document chunk to a vector, the query is mapped by the same model, and the store returns the nearest vectors by cosine similarity using an approximate index. It finds material phrased nothing like the question, which is what makes retrieval-augmented generation work, and it misses exact strings such as error codes — the reason production retrieval pairs it with keyword search.

Picture a librarian who has read every book in the building. Ask for "something about why my laptop keeps getting hot" and she walks you to a chapter on cooling fans — even though your words appear nowhere in it. She is matching what you mean, not the letters you typed.

Semantic search gives software that ability. Every page is converted into a position in a kind of meaning-map, and your question is placed on the same map; whatever sits nearby comes back as the answer. It is how an AI assistant finds the right paragraph in a company handbook. Its weak spot is exact details — a serial number or an error code is easier to find by plain old word matching.