Repository navigation
Conversation
| if nearest is not None: | ||
| scanner_options["disable_scoring_autoprojection"] = True | ||
| # With no Daft projection, expose the full nearest scan schema. | ||
| if columns is None: |
There was a problem hiding this comment.
[P2] Handle empty scan projections in nearest searches
If the query only selects a literal, such as df.select(daft.lit(1).alias("one")), Daft asks Lance for columns=[]. With scoring auto-projection disabled, Lance returns a batch with rows but no columns, which Daft cannot convert. On a search with two matches, the base commit returns {"one": [1, 1]}, while this PR raises on both pylance 12.0.0 and 14.0.2.
Could we explicitly request _distance when the final Lance projection is empty, and add a regression test that verifies one output row per match?
There was a problem hiding this comment.
Good catch, thanks! Fixed in e2a1f1e to request _distance on empty projections, and added a regression test for literal-only selects.
| - uses: actions/checkout@v4 | ||
| - uses: astral-sh/setup-uv@v5 | ||
| - name: Run vector search tests on newer Lance | ||
| run: uv run --locked --python 3.12 --with 'pylance==14.0.2' pytest tests/io/lance/test_lance_vector_search.py -v |
There was a problem hiding this comment.
Any reason to add the test for pylance 14?
9b8c95e to
e2a1f1e
Compare
Problem
read_lance(..., default_scan_options={"nearest": {...}})runs a nearest-neighbour search, but the resulting DataFrame cannot observe the result:LanceScanOperator.__init__builds its schema fromds.schemaonly, and_distanceis produced at scan time, so any reference to_distancefails during planning withFieldNotFound.include_fragment_id=Trueplusnearest,fragment_idis a synthetic column, but Daft pushes predicates on it into the Lance filter, where the column does not exist, and the read fails.Changes
_distance(Float32) in the operator schema whennearestis configured.disable_scoring_autoprojection=Trueand project_distanceexplicitly instead of relying on Lance's deprecated default. When Daft requests an empty projection (e.g. literal-onlyselect) withoutfragment_id, request_distanceso matched row counts are preserved.fragment_idfrom the physical row address (_rowaddr >> 32) for index-driven searches, dropping_rowaddrunless the caller asked for it._distance, syntheticfragment_id) in the post-scan remainder so Daft evaluates them after the nearest selection.nearestis active.Usage
README documents that
distance_rangeis applied before the Top-K cutoff (inclusive lower, exclusive upper bound), while a Daft filter on_distanceruns after the nearest selection, and that L2 reports squared Euclidean distance.Testing
pytest tests/io/lance/test_lance_vector_search.py: 29 passed locally on bothpylance==12.0.0(locked) andpylance==14.0.2.include_fragment_id,with_row_address, and empty matches), distance withfragment_id, post-scanfragment_idfiltering under strict filter pushdown,distance_rangebefore Top-K including the exclusive upper bound, Hamming distance dtype, and merging query distances back viamerge_columns_df.Notes
use_index=False.vector_searchAPI. This change only makes the existingdefault_scan_options["nearest"]path observable; it does not add query-parallel execution.🤖 Generated with Claude Code