Database / LanceDB Interview questions
When should you use a scalar index versus a vector index?
The two index types accelerate fundamentally different kinds of query, and picking the right one for a given column comes down to what kind of question you're asking against it — similarity, or exact/range matching.
| Use a Scalar Index When | Use a Vector Index When |
| Filtering on exact values, ranges, or membership (WHERE clauses) | Finding items semantically similar to a query vector |
| The column is a string, number, boolean, or date | The column is a fixed-size vector/embedding |
| Queries commonly combine a filter with sorting or aggregation | Queries ask "find the top-k nearest neighbors" |
| The column has moderate-to-high cardinality worth indexing | The vector column is queried frequently at meaningful scale |
In practice, most production RAG tables benefit from both at once: a vector index on the embedding column for the semantic search itself, and one or more scalar indexes on metadata columns (like category, date, or tenant_id) that are commonly used to filter results down before or alongside the vector search.
Building an index of either kind isn't free — it costs build time and some storage overhead — so a column that's rarely filtered on, or a small table where a full scan is already fast enough, often doesn't need a scalar index at all; the decision should follow observed query patterns rather than indexing every column preemptively.
More Related questions...