Vector databases can store metadata with each vector entry, and users can then query the database using additional metadata filters for finer-grained queries, such as one tenant, one document or one date range. Filtering matters most in multi-tenant products: without a filter, a similarity search can return another customer documents. The filter must be backed by an index on the filtered field, or it will be slow and may be applied after ranking, which can return fewer results than the top-k promises.
What you need
- The metadata fields stored on every chunk, for example tenant, document type and date
- The filter each query must apply
- A test query whose correct answer is in one tenant only
Step 1: Index the fields you filter on
Create a payload index for each field you filter by, before ingesting data, so the index is built with filter-aware edges. Only index fields you actually filter on, since each index costs memory.
Step 2: Apply the filter with the search, not after it
Send the metadata filter in the same query as the vector search, so the store can use the index while ranking. Filtering after ranking can return fewer than top-k results and can miss the right chunk entirely.
Step 3: Test that the filter holds
Run a query as one tenant and confirm no result from another tenant appears, then run the same query as a different tenant and confirm the results change. A similarity search with no tenant filter can return another customer documents.
Worked example: synthetic metadata filter check
The table below is a synthetic example. It shows the expected result of filtering a search; no database was queried.
| Query as tenant | Filter applied | Results |
|---|---|---|
| Tenant A | tenant = A | 3 chunks, all tenant A |
| Tenant B | tenant = B | 3 chunks, all tenant B |
| No tenant set | None | Chunks from both – leak |
| Tenant A, 2026 docs | tenant = A, year = 2026 | 2 chunks, both match |
Expected result (UNTESTED). filtered queries return only the right tenant results, and the unfiltered query leaks across tenants. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Payload indexes occupy additional memory and disk space, so only apply them to fields used in filtering.
- Queries that filter on unindexed fields are slower and can consume cluster resources; some stores can block them.
- If you create a payload index after data is ingested, you may need to rebuild the vector index to benefit from it.
- Store the tenant or workspace id on every chunk; a chunk without it cannot be filtered reliably.
