Module 2 · AI engineering foundations · Chapter 8 · Free
Embeddings and vector databases
An embedding is a position for meaning
An embedding model turns a piece of text into a list of numbers called a vector. The training makes texts with similar meaning land close together and unrelated texts land far apart. Searching by meaning then becomes a geometry problem: embed the question, find the nearest stored vectors.
Below is a 2D picture of that idea. Real embeddings have hundreds or thousands of dimensions, but the intuition carries over. Pick a question and watch which snippets are closest. Try the second one, "Who can see employee salaries?": it sits between two topics, which is exactly where real systems get confused.
Where the vectors live
You need somewhere to store millions of vectors and quickly find the nearest ones to a query. That is a vector database, or a vector index inside a database you already run. Step through the flow.
- PDFs, wiki pages, tickets, emails. Their quality limits everything downstream.
- Documents are cut into passages of a few hundred tokens, often overlapping slightly. Too big and the match is vague; too small and the meaning is lost.
- The embedding model turns every chunk into a vector. Use the same model later for questions.
- Vectors are stored with the original text and metadata such as source, date, owner and who may read it. The metadata is what makes filtering and citations possible.
- The user asks in their own words.
- Same model, same space, so the question lands near relevant chunks.
- The index returns the closest vectors. At scale it uses an approximate method (such as HNSW graphs) that trades a little accuracy for large speed gains. Filters on metadata, like permissions, apply here.
- The best k chunks go to the next step: usually a language model that writes the answer (Chapter 9).
Which store should you pick?
There is no universal answer. Answer the questions for a typical customer situation.
Features, limits and pricing of specific products change often. Treat this as a framework and check current documentation before choosing.
Mistakes that bite later
- Changing the embedding model means re-embedding everything. Vectors from different models are not comparable.
- Forgetting metadata. Without source, date and access info you cannot cite, filter or delete.
- Trusting closeness as relevance. The nearest chunk is not always the right one. That is why hybrid search and re-ranking exist (Chapter 9).
- Stale data. Documents change. Plan for re-indexing and for deleting chunks when sources are removed.
Check your understanding
Recap
- An embedding places text in a space where closeness approximates similarity of meaning.
- A vector store holds vectors, text and metadata, and finds nearest neighbours fast, often approximately.
- Choose the store the customer can approve and operate. Pgvector is a good default when Postgres is already there.
- Closeness is not permission. Keep access metadata and filter on it.
Chapter quiz
Four questions. Score 70% or more to mark this chapter complete.