Embeddings & Vector Search
Intermediate
An embedding turns a piece of text into a list of numbers (a vector) that captures its meaning. Texts with similar meaning get vectors that are close together — even if they share no words. That's the trick behind semantic search and RAG.
- Picture an embedding as a point in a space arranged so that similar meanings sit near each other
- Tell keyword search from semantic search — and know why hybrid search usually wins
- Walk the four steps of a vector search, from chunking to nearest-neighbor lookup
- Avoid the three mistakes that quietly ruin retrieval quality: bad chunk sizes, mixed embedding models, and no metadata filters
- Decide when you actually need a vector database and when you don't
The intuition
Imagine every sentence placed as a point in a huge multi-dimensional space, arranged so that similar meanings sit near each other. "How do I reset my password?" lands near "I forgot my login," far from "best pizza in Rome."
Semantic vs keyword search
- Keyword search matches literal words ("password" finds "password").
- Semantic search matches meaning — "I can't sign in" finds the password-reset doc even without the word "password."
Best results often combine both (hybrid search).
How a vector search works
Guided walkthrough1 of 4
- Split each document into chunks first, then embed each chunk and store the vectors in a vector database. This is the step you do once, ahead of time.
- At query time, run the user's question through the same embedding model so it lands in the same space as your chunks.
- Compare the query vector against the stored ones by cosine similarity or distance, and keep the closest matches.
- Typically to feed into RAG, where the retrieved text becomes context for the model's answer.
Practical notes
- Chunking matters. Too big = noisy matches; too small = lost context. Tune it.
- Use one embedding model consistently — vectors from different models aren't comparable.
- Metadata + filters (date, source, type) make retrieval far more precise.
- A vector DB isn't always needed — for small corpora, a simple in-memory search is fine.
1 / 9
Check yourself
0/3- An embedding is meaning as a point in space — nearness means similar meaning, not shared words.
- Semantic search finds what keyword search misses, but hybrid search usually beats either alone.
- Four steps: embed and store chunks, embed the query, find nearest vectors, return the chunks.
- One embedding model, used consistently on both sides. Vectors from different models aren't comparable.
- Chunk size and metadata filters do more for retrieval quality than the choice of vector database.
- For a small corpus, a simple in-memory search is enough — a vector DB isn't a requirement.