Notesstorage🌱 seedling
Vector Search
Also: Semantic Search · Similarity Search · k-NN Search · Nearest Neighbor Search · Embedding Search
Search by meaning: items and queries are mapped to [[Embedding]] vectors, and the answer is the k vectors nearest the query. Exact search is a full scan, so production systems use an [[Approximate Nearest Neighbor]] index.
Why it exists
Keyword search misses matches that share meaning but not words ("quiet headphones for flights" vs "noise cancelling, ideal for travel"). Embedding models place similar meanings close together, so similarity becomes distance.
How it works
- An embedding model turns text, images or users into vectors with hundreds or thousands of dimensions.
- Similarity is cosine similarity, dot product or Euclidean distance; use the metric the model was trained for.
- Exact k-NN compares the query with every vector: 1M vectors × 1,536 float32 dimensions is about 6 GB read per query.
- Spatial trees (k-d trees) degrade to scanning in high dimensions, because most points end up roughly equidistant.
- Real queries add filters (tenant, category, stock), which interact badly with approximate indexes.
Trade-offs
| Gains | Costs |
|---|---|
| matches by meaning, across languages and media | results depend on the embedding model |
| one technique for text, images, recommendations | vectors are large: memory and storage |
| combines well with keyword search (hybrid) | exact search doesn't scale; ANN is approximate |
In practice
- pgvector adds a
vectortype and distance operators to Postgres, so embeddings live next to the rows they describe. - Elasticsearch stores
dense_vectorfields and quantizes them by default to save memory.
Pitfalls
- Changing the embedding model means re-embedding everything; vectors from different models aren't comparable.
- Pure vector search is weak on exact identifiers (SKUs, error codes); hybrid search covers that.
Connections
- Part of
- Storage
- Contains
- Approximate Nearest Neighbor
- Contrasts with
- Full-Text Search
- In real systems
- pgvectorElasticsearch
Recall
These cards are also in your review deck, scheduled with spaced repetition.