core practice · implementation task

Add metadata filtering to vector search

Extend your brute-force index to support 'nearest WHERE field = value'. Implement both pre-filtering and post-filtering and compare results and timing.

The mechanism

Real queries are 'nearest vectors WHERE tenant=X AND date>Y'. Pre-filtering shrinks the candidate set before ANN (accurate, can be slow); post-filtering runs ANN then drops misses (fast, can return too few). The hard part is doing it inside a graph index.

Study Metadata Filtering

Expected evidence

Filtered top-k that always returns k items when k qualify.

Try this drill in the practice workspace →

Hints when you need them
  • Post-filtering an ANN result can return fewer than k.
  • Pre-filtering is exact but scans the filtered subset.

Watch for these mistakes

  • Post-filtering an HNSW result and returning fewer than k items
  • Treating filters as an afterthought to the index design
  • Ignoring multi-tenancy isolation in a shared index

Check the sources

Browse all practice briefs