Course contentsShow
← AI Engineering
Lesson 282 of 1,8867. Vector Databases - FundamentalsFree lesson

Query-time vs Index-time Filtering

Trade-offs between filtering at query time versus maintaining separate filtered indexes.

Query-time vs Index-time Filtering

What you'll learn: How choosing when to apply filters—during the search or when building the index—affects your vector database performance and flexibility.

The Two Timing Options

When you need to filter your vector search results (say, only documents from 2023 or only products under $50), you have two choices about when to apply those filters:

  1. Query-time filtering: Store everything together, then filter during each search
  2. Index-time filtering: Create separate indexes for different filter categories upfront

Query-time Filtering

With query-time filtering, you maintain one large index containing all your vectors. When a search arrives with filters, the database applies those filters as part of the search process.

Advantages:

  • Maximum flexibility—any filter combination works
  • No need to anticipate filter patterns
  • Simpler infrastructure (one index)

Disadvantages:

  • Slower searches when filters eliminate most candidates
  • Database must check and reject irrelevant vectors

Index-time Filtering

Index-time filtering means creating separate indexes for predictable filter categories (e.g., one index per language, per year, or per product category).

Advantages:

  • Faster searches—you only search relevant vectors
  • Better memory efficiency during queries
  • Reduced computational overhead

Disadvantages:

  • Must predict common filter patterns upfront
  • More indexes to maintain and update
  • Storage overhead if categories overlap

The Trade-off Decision

Think of it like organizing a library: query-time filtering keeps all books together and you scan for your genre during checkout. Index-time filtering creates separate genre sections you can visit directly.

Choose index-time filtering when filters are predictable and selective (removing >50% of data). Choose query-time when you need maximum flexibility or filters vary widely.

Key Takeaway: Query-time filtering maximizes flexibility at the cost of speed, while index-time filtering optimizes performance for predictable filter patterns but requires more infrastructure planning.