Metadata Filtering with Vector Search
In this article
- Treat a metadata filter as an exact yes-or-no condition that the application sets, separate from the similarity score.
- Predict how many results survive a filter applied after an approximate search, and recognise candidate starvation.
- Choose between an exact search over the matching rows, an iterative index scan and partitioning for a selective filter.
- Keep a permission filter inside the database query so that no execution path can return another user's rows.
- Terms defined here: pre-filtering, post-filtering, filter selectivity, candidate starvation.
Overview
A customer signs in and asks the support assistant, "What did you tell me about my router last month?" The search should look only at that customer's own past conversations. You add the condition, the query runs, and it returns nothing, although the customer has ten conversations on file. Nothing crashed: the condition and the search ran in the wrong order.
In an invented example, Brightline, a home-internet provider, runs a support assistant that searches about 2,000 chunks of its help pages, router manuals and staff handbook and puts the best 3 into each request. Brightline also indexes customers' past conversations, about 200,000 chunks, and each customer may see only their own.
By the end you can predict when a filter leaves a search with too few results, pick a fix in PostgreSQL with pgvector (its vector-search extension), and keep a permission filter where it cannot leak.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- A filter is a yes or no
- Where the filter runs
- Forty candidates
- Three fixes in pgvector
- The filter that is a permission
- When the field is wrong
- The rule at work
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions