feat: support vector indexes via ALTER TABLE ... CREATE INDEX#449
Open
wombatu-kun wants to merge 1 commit intolance-format:mainfrom
Open
feat: support vector indexes via ALTER TABLE ... CREATE INDEX#449wombatu-kun wants to merge 1 commit intolance-format:mainfrom
wombatu-kun wants to merge 1 commit intolance-format:mainfrom
Conversation
This was referenced Apr 18, 2026
Extends the existing `ALTER TABLE … CREATE INDEX … USING method (...)`
statement to accept vector index methods (`ivf_flat`, `ivf_pq`,
`ivf_hnsw_pq`, `ivf_hnsw_sq`) alongside the existing scalar methods
(`btree`, `fts`). No new SQL statement is introduced — the grammar rule
`LanceSqlExtensions.g4#createIndex` is unchanged; only the `method`
parameter accepts new values.
Vector index training currently runs single-shot on the driver
(`AddIndexExec.runVectorIndex`) because Lance's distributed vector-index
path requires pre-computed IVF centroids — per-fragment tasks cannot
train a global codebook on their own. A follow-up can precompute
centroids in a Spark job and re-enable the per-fragment build via
`IvfBuildParams.Builder.setCentroids`.
`DistanceTypes` is shared infrastructure for parsing user-facing metric
strings (`l2` / `cosine` / `dot` / `hamming`) into the `DistanceType`
enum from lance-core.
Index correctness is verified through the existing DataFrame API path
(`option("nearest", QueryUtils.queryToString(query))`), so this PR has
no dependency on the SQL TVF.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fd225b9 to
08923cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is one of three PRs that supersede #436, splitting it per reviewer feedback.
Summary
Extends the existing
ALTER TABLE … CREATE INDEX … USING method (...)statement (grammar ruleLanceSqlExtensions.g4#createIndex) to accept vector index methods (ivf_flat,ivf_pq,ivf_hnsw_pq,ivf_hnsw_sq) alongside the existing scalar methods (btree,fts). No new SQL statement is introduced — the grammar rule is unchanged; only themethodparameter accepts new values, exactly as the reviewer suggested.Example:
```sql
ALTER TABLE lance.db.items CREATE INDEX emb_idx USING ivf_pq (embedding)
WITH (num_partitions = 256, num_sub_vectors = 16, metric = 'cosine');
```
Vector index training currently runs single-shot on the driver (`AddIndexExec.runVectorIndex`) because Lance's distributed vector-index path requires pre-computed IVF centroids — per-fragment tasks cannot train a global codebook on their own and the native code rejects the call with "Build Distributed Vector Index: missing precomputed IVF centroids". A follow-up can precompute centroids in a Spark job and re-enable the per-fragment build via `IvfBuildParams.Builder.setCentroids`.
`DistanceTypes` is shared infrastructure for parsing user-facing metric strings (`l2` / `cosine` / `dot` / `hamming`) into the `DistanceType` enum from lance-core.
Index correctness is verified through the existing DataFrame API path (the `"nearest"` read option backed by `LanceSparkReadOptions.CONFIG_NEAREST`), so this PR has no dependency on the SQL TVF PR — the two can be merged in any order.
Test plan
🤖 Generated with Claude Code