BREAKING CHANGE: Executing or analyzing an async Python hybrid query
with `limit(0)` now raises `ValueError` before either search runs. In
0.41.0, `offset(2).limit(0).to_arrow()` returned a typed empty table
after retrieval and reranking. Skip query execution and `analyze_plan()`
when the requested page size is zero.
Refs #4758
## Problem
Each side of a hybrid query fetched only `limit + offset` rows before
rank fusion, so asking for fewer results could return a different top
result instead of just a shorter list.
Repro (lancedb 0.41.0, 300 rows, RRF reranker):
- `limit=1` -> top id 294
- `limit=10` -> top id 269
## Fix
With the default RRF reranker, both hybrid paths
(`LanceHybridQueryBuilder._create_query_builders` and
`AsyncHybridQuery._create_child_queries`) now fetch `max(limit + offset,
DEFAULT_HYBRID_RANK_WINDOW)` rows per side, with
`DEFAULT_HYBRID_RANK_WINDOW = 50`. The requested limit/offset window is
still sliced out of the fused results as before. This implements option
1 from the issue: a fixed minimum window, no new API surface.
Custom and model rerankers keep the caller's `limit + offset` budget per
side, since every candidate is sent to them (for example
`OpenaiReranker` puts all merged texts in one prompt). Callers who want
a wider window for those rerankers can raise `limit()`. An explicit
`limit(0)` never gets the floor. In the async builder it raises
`ValueError` before schema discovery or either sub-query runs, with or
without an offset, so neither Embedded nor Enterprise retrieves or
scores anything. On main, async `limit(0)` was rejected by the native
`k` check only without an offset; `offset(2).limit(0)` fetched and
reranked two rows per side and returned nothing. The sync builder still
treats `limit(0)` as the default of 10, as before.
Trade-off: default RRF queries with small limits now fetch up to 50 rows
per side, and their result orderings can change, which is the bug being
fixed.
## Tests
- `test_hybrid_query_top_result_stable_across_limits` and its async
mirror (issue repro): fail on base, pass with the fix
- `test_hybrid_query_custom_reranker_keeps_candidate_budget` and its
async mirror: a recording reranker receives 1 vector and 1 FTS candidate
for `limit(1)` and 5 of each for `offset(2).limit(3)`
- `test_async_hybrid_query_default_rrf_candidate_window`: default RRF
receives 50 of each for `limit(1)`
- `test_async_hybrid_query_empty_page_does_not_fetch_candidates` (offset
0 and 2): `limit(0)` raises, and neither sub-query nor the reranker runs
- `test_remote_db.py::test_async_hybrid_zero_limit_sends_no_query`
(offset 0 and 2): `limit(0)` raises and no `/query/` request is sent;
fails on 281fdc7, passes on this head
- `test_remote_db.py::test_query_sync_hybrid` now expects `k=50` for the
default RRF request with `limit(42)`
- `test_hybrid_query.py`: 30 passed, 1 failed. The failure is
pre-existing and unrelated
(`test_hybrid_query_with_stale_fixed_size_binary_prefilter` needs the
`lance` package)
- `test_wal_hybrid.py`: 15 passed
- `ruff check` and `ruff format --check` clean on the touched files
Local runs used the lancedb 0.41.0 wheel with this PR's `query.py` diff
applied, since main needs a newer native extension than the published
wheel. `test_query_sync_hybrid` and the new remote zero-limit test were
run from an extracted copy because `test_remote_db.py` imports
`lancedb.graph`, which 0.41.0 does not have.
---------
Signed-off-by: shadowmodder <sudhirvissa@gmail.com>
Signed-off-by: Sudhir Vissa <sudhirvissa@gmail.com>
The Multimodal Lakehouse for AI
How to Install ✦ Detailed Documentation ✦ Tutorials and Recipes ✦ Contributors
The ultimate multimodal data platform for AI/ML applications.
LanceDB is designed for fast, scalable, and production-ready vector search. It is built on top of the Lance columnar format. You can store, index, and search over petabytes of multimodal data and vectors with ease. LanceDB is a central location where developers can build, train and analyze their AI workloads.
Demo: Multimodal Search by Keyword, Vector or with SQL
Star LanceDB to get updates!
Key Features:
- Fast Vector Search: Search billions of vectors in milliseconds with state-of-the-art indexing.
- Comprehensive Search: Support for vector similarity search, full-text search and SQL.
- Multimodal Support: Store, query and filter vectors, metadata and multimodal data (text, images, videos, point clouds, and more).
- Advanced Features: Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure. GPU support in building vector index.
Products:
- LanceDB Embedded (open source): 100% open source, runs in your application's process; your data can live on local disk or in object storage. No vendor lock-in.
- LanceDB Enterprise: Production-scale distributed search, indexing, and maintenance. Plus, complete data sovereignty and security.
Ecosystem:
- Columnar Storage: Built on the Lance columnar format for efficient storage and analytics.
- Seamless Integration: Python, Node.js, Rust, and REST APIs for easy integration. Native Python and Javascript/Typescript support.
- Rich Ecosystem: Integrations with LangChain 🦜️🔗, LlamaIndex 🦙, Apache-Arrow, Pandas, Polars, DuckDB and more on the way.
How to Install:
Follow the Quickstart doc to set up LanceDB locally.
API & SDK: We also support Python, Typescript and Rust SDKs
| Interface | Documentation |
|---|---|
| Python SDK | https://lancedb.github.io/lancedb/python/python/ |
| Typescript SDK | https://lancedb.github.io/lancedb/js/globals/ |
| Rust SDK | https://docs.rs/lancedb/latest/lancedb/index.html |
| REST API | https://docs.lancedb.com/api-reference/rest |
Join Us and Contribute
We welcome contributions from everyone! Whether you're a developer, researcher, or just someone who wants to help out.
If you have any suggestions or feature requests, please feel free to open an issue on GitHub or discuss it on our Discord server.
Check out the GitHub Issues if you would like to work on the features that are planned for the future. If you have any suggestions or feature requests, please feel free to open an issue on GitHub.
Contributors
Stay in Touch With Us
License
See LICENSE for the project license.

