Embeddings and vector search, explained simply
How AI turns text into numbers that capture meaning, and how vector search uses them to find answers even when the words don't match.
On this page
Search for "how do I reset my password" on a good help site and it finds the article titled "Forgot your login?", even though the words barely match. The trick behind this is embeddings and vector search. They power semantic search, recommendations and RAG. Here is how they work, without the maths.
The problem with keyword search
Classic search matches words. If you type "cheap phone", it looks for pages with "cheap" and "phone".
But people say the same thing in many ways: "budget mobile", "affordable smartphone", "phone under 10,000". Keyword search misses these because the words are different, even though the meaning is the same.
Embeddings: meaning as coordinates
An embedding is a list of numbers that represents the meaning of a piece of text. An embedding model reads a sentence and outputs something like [0.12, -0.48, 0.91, ...], usually with hundreds or thousands of numbers.
The key property: texts with similar meaning get similar numbers.
Everyday comparison: a map. Imagine every sentence placed as a dot on a giant map. "Budget mobile" and "cheap phone" land right next to each other. "Mango recipe" lands far away. The embedding is simply the dot's location on the map.
A real map has two coordinates (latitude and longitude). An embedding has hundreds, which gives room to capture many shades of meaning: topic, tone, language and more. You can't picture that many directions, but the idea is exactly the same.
Vector search: find the nearest dots
Once your text is on the map, searching becomes easy to describe:
- Turn every document into an embedding and store it.
- When a question comes in, turn the question into an embedding too.
- Find the stored embeddings that are closest to the question's embedding.
- Return those documents as the results.
"Closest" is usually measured with cosine similarity, which checks whether two lists of numbers point in the same direction. You don't need the formula to use it; libraries and databases do it for you.
Where the embeddings are stored
With a few hundred documents you can compare against every one. With millions you need a vector database, which stores embeddings and finds near neighbours quickly using clever indexes. Popular choices include Postgres with the pgvector extension, Qdrant and Chroma.
Our hands-on tutorial builds a RAG chatbot with Ollama and pgvector on a normal laptop if you want to try it.
What embeddings are used for
| Use | How embeddings help |
|---|---|
| Semantic search | Find results by meaning, not exact words |
| RAG chatbots | Find the right paragraphs to give the AI |
| Recommendations | "People who liked this article also liked..." |
| Duplicate detection | Spot two support tickets about the same problem |
| Grouping | Sort thousands of reviews into topics automatically |
Things to keep in mind
- Use the same embedding model for your documents and your questions. Numbers from two different models live on two different maps and can't be compared.
- Keyword search still matters. For exact things like error codes, product IDs and names, keyword search often wins. Many real systems combine both, called hybrid search.
- Chunk long documents. One embedding for a 50-page PDF blurs everything together. Split it into paragraphs or sections first.
Quick recap
- An embedding turns text into numbers that capture its meaning.
- Similar meanings get nearby numbers, like nearby dots on a map.
- Vector search finds the nearest dots to your question.
- Vector databases store embeddings and search them fast.