Originally published with interactive examples at lukiluki.me.
You search for “forgot password”, but the relevant help article is called “restore account access”. A search that only matches those words might miss it. How can it still find the right content?
Embeddings help search find related content across different phrasings. A trained model turns queries and passages into numerical vectors. A mathematical comparison then identifies candidates whose content might match the query. This extends word matching with a measure of semantic proximity. The application still needs to check whether a result is useful, correct and appropriate for the user's context.
Merksatz (Key takeaway):
Embeddings make semantic proximity computable. They help find relevant candidates, but a numerical score cannot establish relevance or correctness on its own.
How text becomes comparable numbers
An embedding model learns relationships between texts during training. It can therefore connect related phrasings even when they share few words. For each input, it calculates a vector (An ordered list of numbers; each number is a coordinate in the model's representation of the text.). The length of that list is the number of dimensions.
Imagine a space where related content points in similar directions. “Forgot password” and “restore account access” might be closer together than “change delivery address”. Unlike a map, this space often has hundreds or thousands of dimensions. Individual coordinates generally cannot be read as properties such as “password” or “problem”. The relationship comes from the whole vector.
Context matters. “I sat on the river bank” and “I transferred money to my bank” use the same word for different things. An embedding represents the particular text, rather than one fixed word meaning for every situation.
How this becomes a search system
For documentation search, first divide content into meaningful passages and store their embeddings. At query time, calculate only the new query vector and compare it with the stored vectors:
- Prepare content: Store the vector for a password-reset passage alongside its text and source link.
- Represent the query: Embed “forgot password” with the same model and a compatible search configuration.
- Find candidates: Rank passages by their comparison scores.
- Select results: Filter by additional criteria such as language, freshness or product version.
Passage size affects retrieval. A whole article may mix several topics; a single sentence may lose essential context. Useful passages address one coherent question and retain enough information to make sense on their own.
Exact identifiers such as “ERR-1042” still benefit from lexical search. Both methods can be combined: keywords match the exact spelling, while embeddings find related formulations. Intuitive Search explains the first building block.
What a similarity score tells you
A common comparison is cosine similarity (The dot product of two vectors divided by the product of their lengths.). It compares vector direction independently of length. Its range is −1 to +1, with higher scores indicating more similar directions. A score of 0.8 does not mean “80 percent identical meaning”.
For search, ranking is the first concern: does the password-reset guide appear before the delivery-address article? There is no universal threshold for a good result. You need representative queries and judgments about which passages should answer them. Compare only vectors from the same model with compatible configurations and the same number of dimensions.
Topic similarity can also conceal a crucial difference. “I like coffee” and “I do not like coffee” both concern coffee but contradict each other. A high score may identify an interesting candidate without confirming its statement. The same applies to outdated instructions and factually incorrect text.
Where embeddings help
| Task | Contribution from embeddings | What else is needed |
|---|---|---|
| Search documentation | Find related phrasings | Check relevance and version |
| Recommend similar articles | Suggest related topics | Consider quality and reader interests |
| Group texts by topic | Bring related content together | Review and name the groups |
| Find an exact product number | Add thematic context | Exact identifier matching |
| Check contradictions or facts | Retrieve related statements | Evaluate statements and evidence |
Retrieval in RAG
In RAG (Retrieval-Augmented Generation: Relevant passages are retrieved and supplied to a language model as context for its answer.), embedding search can retrieve passages from a knowledge collection. A language model then writes an answer using that context. The vectors themselves contain neither readable source text nor a finished answer; the retrieved passages must be loaded too.
Answer quality therefore also depends on retrieving the right sources. A high similarity score cannot compensate for a missing or unsuitable passage. An agent executing a specific function is a separate capability: Web MCP explains how to expose those tools.
Test similarity yourself
Try “forgot password”, “restore account access” and “change delivery address” below. Calculate embeddings and check which pair ranks highest. Then compare the two coffee sentences: does topical proximity remain high despite the contradiction? This experiment compares short texts; it does not evaluate an entire documentation search system.
The initial saved examples retain their original German and English words and vectors. Translating a word while keeping its old vector would misrepresent the data. The saved file records neither its model nor its generation date, so treat it as an illustrative starting point. New inputs require a fresh calculation using the selected AI backend; the interface distinguishes saved, changed and newly calculated results. No API key is required to inspect saved comparisons; new cloud requests require a configured backend, while local inference requires prepared model files and a suitable device.
Further detail: Metrics and dimensions
Cosine compares directions. Euclidean distance measures direct distance, while Manhattan distance sums absolute coordinate differences. For both distances, smaller values indicate greater proximity. Their values cannot be compared directly with cosine scores, and vector length affects them too.
\cos(\theta) = \frac{A \cdot B}{\|A\|\,\|B\|}
The dimensions slider uses only the first coordinates of existing vectors. It does not generate new embeddings. This can change the ranking. Some models are specifically trained to work with shortened vectors. Arbitrary truncation is not a general quality improvement: choose dimensions according to the model and actual retrieval tasks.
Checklist for embedding search
- [ ] Collect representative queries and record which passages should answer them.
- [ ] Split documents into coherent passages and preserve text, source and metadata.
- [ ] Use a compatible model and configuration for documents and queries.
- [ ] Test synonyms, ambiguous terms, contradictions and exact identifiers.
Primary sources
- Sentence Transformers: Semantic search, queries and documents
- Sentence Transformers: Text similarity and comparison metrics
- Google: Embeddings, retrieval tasks and dimension reduction
Read the original guide & explore the interactive playground on *lukiluki.me*.
Top comments (0)