Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Databases that find similar things
A vector database is a library catalogue for meaning: each document is stored as a list of numbers, and a query finds the closest ones. Real questions often add conditions, such as ‘only manuals for this aircraft type’. How the database combines the condition with the similarity search matters: if it first grabs the ten most similar documents and then applies the condition, it may end up with almost nothing. The demo shows how many results survive such a filter.
A fleet-wide documentation search must filter by aircraft type, revision and access rights; filtered vector search done wrongly silently returns too few results.
- 1. A vector database stores…
- 2. Filtering after taking the top 10 can…
- 3. pgvector adds vectors to…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- FAISS: IndexFlatIP/L2 (exact), IndexIVFFlat (nlist, nprobe), IndexHNSWFlat (M, efSearch), IndexIVFPQ (compressed); GPU support; no metadata or persistence layer of its own.
- Chroma: embedded or client–server; collections with documents, metadata and where filters; good for prototypes.
- Qdrant / Weaviate / Milvus: HNSW with payload filtering inside the graph, quantisation, sparse + dense hybrid search, sharding and replication, snapshots.
- pgvector: vector type, HNSW and IVFFlat indexes, distance operators; SQL joins and transactions with your data; iterative index scans for filters.
- Filtering: post-filter (ANN then filter), pre-filter (filter then exact or ANN), filter-aware index traversal; query planners choose by selectivity.
- Operations: upserts by stable ids, deletes and re-indexing, embedding-model versioning, memory sizing (vectors + graph), backups, multi-tenancy (per-tenant collections or payload filters).
- 1. FAISS lacks…
- 2. Filter-aware HNSW traversal is offered by…
- 3. When you change embedding models you must…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Choosing and running a vector store
Exercise 1.
- A flat cosine index.
- Metadata filters.
- Recall@k against exact search.
Practice.
- Up to about a million vectors on one machine: FAISS or pgvector HNSW; prototypes: Chroma; large or multi-tenant production: a vector server or pgvector with care.
- Measure recall@k against exact search on your data before tuning speed.
- For filters, check selectivity: pre-filter with exact search for small sets; use filter-aware indexes otherwise; avoid naive post-filtering.
- Store the embedding model name and version with every vector; plan re-embedding.
- Size memory: n·d·4 bytes plus graph links; consider scalar or product quantisation.
import faiss, numpy as np
X = np.load("chunks.npy").astype("float32"); faiss.normalize_L2(X)
index = faiss.IndexHNSWFlat(X.shape[1], 32, faiss.METRIC_INNER_PRODUCT); index.add(X)
index.hnsw.efSearch = 64
q = embed("hydraulic leak at the main gear").astype("float32")[None]; faiss.normalize_L2(q)
D, I = index.search(q, 10)
# pgvector equivalent: SELECT id FROM chunks WHERE aircraft = 'A320' ORDER BY embedding <=> :q LIMIT 10;- 1. Before tuning speed, measure…
- 2. Store with every vector…
- 3. For a filter matching 1% of items…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Post-filtering. If a fraction s of items pass the filter independently of similarity, the expected number of survivors among the top k′ is k′s. To expect k survivors you need k′ ≈ k/s, which explodes for selective filters.
Filtered IVF. Scanning the probed lists and keeping only passing items returns the best passing candidates in those lists. With n·s passing items spread over L lists, the probed lists hold about nprobe·n·s/L of them; when that is close to k, many true neighbours lie in unprobed lists.
Exact pre-filtering. Scanning only the n·s passing items costs n·s distance computations and is exact; it beats the ANN index whenever n·s is below the index’s own scan cost.
- 1. Survivors among k′ candidates at selectivity s:
- 2. Filtered IVF fails when probed lists hold…
- 3. Exact pre-filter cost is…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How should a metadata filter be combined with approximate nearest-neighbour search as the filter becomes more selective?
History.
- J. Johnson, M. Douze and H. Jégou, “Billion-scale similarity search with GPUs” (FAISS, 2019).
- Y. Malkov and D. Yashunin, “HNSW” (2018).
- S. Gollapudi et al., “Filtered-DiskANN” (2023).
Exercise 2. Filtered search on 50000 vectors.
- Data: 32 dimensions in 100 clusters; each item has a random tag, and a filter of selectivity s keeps items with tag < s.
- Index: IVF with 256 lists, nprobe 8. 200 queries.
- Strategies: post-filter the ANN top 10; post-filter the top 100; filter inside the probed lists; exact search over the passing items.
- Measure: recall@10 against exact filtered search; distance computations include the 256 centroid distances.
| selectivity | post-filter top 10 | post-filter top 100 | filtered IVF | exact pre-filter |
|---|---|---|---|---|
| 0.5 | 0.493 (4.9 results) | 1.0 | 1.0 | 1.0 (24948 computations) |
| 0.1 | 0.098 (1.0 result) | 0.863 | 1.0 | 1.0 (4967) |
| 0.01 | 0.014 (0.1 results) | 0.105 | 0.778 | 1.0 (513) |
- Post-filtering returned about 10·s of the 10 results asked for.
- Oversampling to 100 worked at 10% selectivity, not at 1%.
- Filtering inside the index was exact for broad filters but missed 22% at 1%.
- Exact pre-filtering was exact and cheaper than IVF at 1% (513 vs 1895 distance computations); at 50% it cost 13 times more.
- Seeds 1 and 2: filtered IVF at 1% 0.736 and 0.778; post-filter top 100 at 10% 0.88 and 0.89.
- Caveat: tags independent of position; filters correlated with clusters behave differently, better or worse.
Vector databases in AI, robotics and aerospace
- Technical documentation search: filters by aircraft type, configuration, revision and access level are the norm, so filtered search must be tested.
- Robotics: episode and scene embeddings stored with metadata (robot, task, outcome) for retrieval-augmented policies and data curation.
- Earth observation: image-tile embeddings with time and location filters for similarity search over archives.
References
- J. Johnson, M. Douze and H. Jégou (2019). “Billion-scale similarity search with GPUs.” IEEE Transactions on Big Data.
- Y. A. Malkov and D. A. Yashunin (2018). “Efficient and robust approximate nearest neighbor search using HNSW graphs.” IEEE TPAMI.
- S. Gollapudi et al. (2023). “Filtered-DiskANN: graph algorithms for approximate nearest neighbor search with filters.” WWW.
- pgvector contributors (2025). pgvector: open-source vector similarity search for Postgres, documentation.