lance-format / lance-format/lance

Opportunities for late materialization in knn_combined style scans

Open
#3,639 0 comments 0 reactions 1 assignee View on GitHub

@westonpace is already working on this.

Since Apr 18, 2025.

enhancement
Dominant language
Rust
Stars
7.1k
Forks
852
Avg merge
3d 18h
Merged PRs (30d)
272

Description

When we fallback to a prefiltered knn_combined scan we always do a full scan of the unindexed data. We could improve this:

  • If there is no scalar index we can do a full scan of the filter columns followed by a take of the vector data
  • If there is a scalar index then we can materialize the index and do a take of the vector data

Example script:

import lance
import pyarrow as pa
import shutil

shutil.rmtree("/tmp/weston", ignore_errors=True)

ds = lance.write_dataset(pa.table({
    "vec": pa.array([[i, i] for i in range(1000)], pa.list_(pa.float32(), 2)),
    "filt": range(1000)
}), "/tmp/weston")

ds.create_index("vec", num_sub_vectors=2, num_partitions=2, index_type="IVF_PQ")

ds = lance.write_dataset(pa.table({
    "vec": pa.array([[i, i] for i in range(1000)], pa.list_(pa.float32(), 2)),
    "filt": range(1000)
}), "/tmp/weston", mode="append")

print(ds.scanner(filter="filt > 500", prefilter=True, nearest={"q": [5, 5], "k": 10, "column": "vec"}).analyze_plan())

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.