AI Engineering · Module 04
Embeddings and vector search
- Lessons
- 10
- Free
- 0
- Reading
- ~2 h
Your progress
0 / 10 lessons done
Sign in to trackLessons
- Semantic search: finding by meaning, not keywordsSearch boxes, “related items” panels and every RAG system find their documents this way. Knowing which work happens once and which happens on every search tells you what the feature costs, where it is slow and when it will return the wrong thing.
- Embedding models: choosing and comparing themEvery vector you store is tied to the model that made it. The model you pick on day one decides search quality for years, and replacing it means embedding your whole corpus again.
- Similarity measures: cosine, dot product, distanceEvery vector store and every vector index asks you to pick a similarity measure before it stores anything. The wrong pick can quietly put the wrong documents first, and the right one usually takes one line of the model’s documentation.
- Vector databases: what they add to searchThe first similarity search in most products is a loop over every vector, and it works in the demo. Knowing what that loop costs, and what else a real search needs, tells you when to keep it and when a vector database earns its place.
- pgvector: vector search inside PostgreSQLMost teams adding search by meaning already run PostgreSQL. Knowing what pgvector does, how to tell whether its index is used, and where it runs out lets you ship the feature without a second database, and know when you will need one.
- Approximate nearest neighbours: speed vs recallEvery vector index you will use is approximate, and it ships with a default setting someone else chose. Measuring what it misses, and picking the setting yourself, decides whether search is both fast enough and good enough for your feature.
- Vector indexes: HNSW, IVF and quantizationA vector index that worked on a sample can need more memory than the server has once every customer’s data is in it. Knowing what each index stores and how it changes over time lets you size the machine and pick the index before launch, not after the first slow search.
- Filtering vector search by metadataAlmost every real vector search has a WHERE clause: one customer, one language, recent items only. Get the filter wrong and the search either returns nothing or shows one customer’s private data to another.
- Choosing a vector store for your workloadEvery retrieval feature needs somewhere to keep its vectors, and the choice is hard to undo once millions are stored. Teams often pick a store from a feature list or a benchmark; the ones that pick from their own workload numbers avoid running a second database they didn’t need, or outgrowing one they did.
- Lab: semantic search over 10,000 documentsEvery search feature, and every RAG system after it, rests on a vector search that someone has to build and check. Measuring recall on a small labelled set is how you find out whether a bad result comes from the embeddings or from the index, before users find out for you.
Practise with
Terms this module teaches 34
Open glossaryBinary quantization
Keeping only one bit for each number of a vector: whether it is above zero. Vectors become 32 times smaller than 32-bit floats and are compared by counting differing bits, with a large loss of recall unless results are rescored.
Brute-force search
Finding the most similar vectors by comparing the query with every stored vector. It always returns the true nearest results, and its cost grows with the number of vectors times their dimensions.
ef_search (HNSW)
The number of candidates an HNSW index keeps while it searches its graph. Higher values find more of the true nearest neighbours but take longer.
Embedding benchmark
A public set of tasks and datasets used to score and rank embedding models, such as MTEB. Its average covers many tasks, so it can shortlist models but not pick one for your own data.
Euclidean distance
The straight-line distance between the tips of two vectors: subtract matching numbers, square the results, add them and take the square root. Smaller means closer.
Exact nearest neighbour search
A vector search that compares the query with every stored vector and returns the k most similar, so its results are correct by definition but its cost grows with the collection.
EXPLAIN ANALYZE
A PostgreSQL command that runs a query and prints the plan it used, with the real row counts and timings of each step. Plain EXPLAIN shows the plan without running the query.
Extension (PostgreSQL)
A package of new types, functions, operators or index methods that you load into a PostgreSQL database with CREATE EXTENSION.
Filtered vector search
Applying a metadata filter while walking an approximate index, so only matching vectors can be returned. It loses speed or recall when few vectors match, unless the store adapts.
halfvec
pgvector’s half-precision vector type: each number takes 2 bytes instead of 4, halving storage for a small loss in precision.
IVF index
An inverted file index for vectors. It groups stored vectors around centre points found by k-means, and a search compares the query only with the vectors in the few lists whose centres are nearest.
IVFFlat
An approximate vector index that groups vectors into lists around centre points learned from the data, then searches only the lists nearest the query. It must be built after the data is loaded.
k-means
A method that splits a set of vectors into k groups. It repeatedly assigns each vector to its nearest centre, then moves each centre to the average of its group.
Keyword search
Search that ranks documents by the words they share with the query, usually looked up in an inverted index. Strong on exact strings, weak on different wording for the same meaning.
Labelled set (retrieval)
A list of real queries, each with the items a person marked as the right results, used to score and compare search methods.
Metadata filter
A condition on the fields stored with each vector, such as a customer id, status or date, that every result of a vector search must meet.
Nearest-neighbor search
Finding the stored vectors closest to a query vector. The exact version compares the query with every stored vector; approximate versions skip most of them.
Operator class
The part of an index definition that tells PostgreSQL which operators the index can serve. An index is used only for queries that use one of those operators.
Over-fetching
Asking a search for more candidates than you need, so enough remain after filtering or deduplication.
pgvector
An open-source PostgreSQL extension that adds a vector column type, operators that measure the distance between vectors, and approximate vector indexes (HNSW and IVFFlat).
Pooling
Building relevance labels by merging the top results of several search methods and having people judge only that merged pool. Items no method found count as not relevant.
Post-filtering
Running a vector search first and removing results that fail a metadata filter afterwards. It returns too few results when the filter matches a small share of the data.
Pre-filtering
Applying a metadata filter before the vector comparison, so only matching vectors are ever compared with the query.
Product quantization
Compressing a vector by cutting it into pieces and storing each piece as the number of its nearest entry in a codebook learned with k-means.
Re-embedding
Turning every stored item into a vector again with a new embedding model or setting, because vectors from different models can’t be compared.
Recall against exact search
The share of the exact top-k results that an approximate index also returns. It measures only what the index loses, not whether the results are useful.
Rescoring
After a search over compressed vectors, recomputing exact distances for the top candidates from the full vectors and reordering them. It wins back most of the recall that compression lost.
Scalar quantization
Storing each number of a vector in fewer bits, such as 16-bit floats or 8-bit integers instead of 32-bit floats. Vectors take less memory, and distances become slightly less exact.
Search effort
The setting on an approximate vector index that controls how much of the space each search examines; higher effort raises recall and latency.
Semantic search
Search that ranks documents by how close their meaning is to the query, by comparing embeddings, rather than by shared words.
Vector database
A database that stores vectors with an id and metadata and searches them by similarity, usually through an approximate index, with filtering, updates, deletes and replication.
Vector index
A structure that leads a similarity search to likely neighbours so it checks only a small fraction of the stored vectors. It is usually approximate: it can miss a true nearest result.
Vector normalization
Dividing every number in a vector by the vector’s length, so it keeps its direction and has length 1. For normalized vectors, dot product equals cosine similarity.
Vector store
Storage that keeps vectors next to document ids and other fields and returns the stored vectors closest to a query vector.