feat(python): open blob files by row offset (#5356)

Open seekable Blob files by row position with
`table.take_blob_files(column, offsets, *, buffer_size=None)` on
synchronous and asynchronous Embedded and Enterprise tables. Results
follow the requested order, duplicate offsets have independent cursors,
and NULL and empty values stay distinct. An invalid offset rejects the
entire batch.

Enterprise resolves positions and descriptors together and verifies one
snapshot across descriptor queries, location resolution, and
authenticated byte reads. Eligible ranges use the existing presigned
read path when the gateway advertises it.

Refs [OSS-2881](https://linear.app/lancedb/issue/OSS-2881).

## Validation

- On Enterprise 1.16.0, the same locked wheel passed both sync and async
reads of 1,025 distinct offsets after a deletion. The offsets matched an
independent ordered query, and the two descriptor chunks and subsequent
authenticated requests matched the pinned version and snapshot identity.
- Both APIs returned byte-for-byte matches for 37-byte proxy reads and a
32 MiB presigned object-store read. The large reads used zero gateway
byte requests. An independent range check returned two object-store HTTP
206 responses with matching physical ranges and bytes.
- The wheel passed 23 focused Python tests. The Rust library check and
all 81 Enterprise Blob module tests passed, including nested NULL and
strict snapshot echo cases.

Runtime evidence is from commit
`f56c359ba7874cd75c52169491166a941251510f` with Lance `16.0.0-beta.6`,
wheel SHA-256
`9abbbfe584513432547d237dcf7b684b479b35cad07c48cd9899d381f0e80423`. The
merge preview with `main` at `ff556729` is clean.
[#5352](https://github.com/lancedb/lancedb/pull/5352) updates the
integration dependencies to Lance `16.0.0-beta.7` and `object_store`
`0.14.2`. Those pins are outside the tested wheel's coverage.

The synthetic test table was removed from the catalog. Its physical
storage cleanup is tracked separately.
This commit is contained in:
Xuanwo
2026-12-02 12:47:38 +00:00
committed by GitHub
parent eea95c8778
commit 0a14761f0e
13 changed files with 1209 additions and 133 deletions
+14 -8
View File
@@ -1022,11 +1022,16 @@ with `search().with_row_id(True).to_arrow()` and pass the result to the fetch AP
One missing or deleted row ID rejects the entire blob-read batch; the APIs do
not return partial results.
Row positions are not row IDs. To read by position, call
`take_offsets(offsets, with_row_id=True)` first and pass the resulting `_rowid`
values; `fetch_blobs` remains row-ID based. A query result table that carries
snapshot metadata keeps the snapshot that produced it on LanceDB Enterprise, so
the fetched bytes or files stay pinned if the table changes. Metadata-free
Use [`Table.take_blob_files`][lancedb.table.Table.take_blob_files] or
[`AsyncTable.take_blob_files`][lancedb.table.AsyncTable.take_blob_files] to open
files by zero-based row position in the table's visible snapshot. The result
follows the requested order and gives every duplicate its own file cursor.
Negative or out-of-range positions fail the entire call. Enterprise supports
Blob V2 columns on native tables with a gateway that verifies query snapshots.
For row-ID based fetches, get `_rowid` from a query. A query result table that
carries snapshot metadata keeps the snapshot that produced it on LanceDB
Enterprise, so the fetched bytes or files stay pinned if the table changes. Metadata-free
inputs, including legacy query responses and plain row-ID lists, are read from
the table handle's current snapshot; keep the source unchanged between selection
and fetching. Partial snapshot metadata fails explicitly. For `fetch_blob_files`,
@@ -1034,9 +1039,10 @@ a snapshot-bound read also fails explicitly when the serving node cannot echo
the immutable identity. The basic remote Blob API floor (server 0.5.0) does not
by itself provide that echo capability.
Local and remote `BlobFile` handles prefetch 512 KiB for sequential reads by
default. Pass `buffer_size=0` to `fetch_blob_files`, `open_blob_file`, or
`open_blob_files` for sparse reads, or choose another window size in bytes.
Embedded and Enterprise `BlobFile` handles prefetch 512 KiB for sequential reads
by default. Pass `buffer_size=0` to `take_blob_files`, `fetch_blob_files`,
`open_blob_file`, or `open_blob_files` for sparse reads, or choose another window
size in bytes.
Call `file.set_buffer_size(size)` to change it without moving the cursor;
changing the size discards unused prefetched bytes. Explicit `read_range` and
`read_ranges` calls always read exactly the requested intervals and leave the
+20 -1
View File
@@ -795,7 +795,26 @@ Hybrid byte queries require matching snapshot provenance from both responses.
#### Read blobs on demand {#multimodal-read-blobs}
Query the rows you want and pass their `_rowid` values to a fetch method.
When you have row positions, Python's `take_blob_files` opens seekable handles
from the table's visible snapshot. This example reads the header at position 5
and closes the file afterward.
```python
[video] = table.take_blob_files("video", [5], buffer_size=0)
if video is not None:
with video:
header = video.read(4096)
```
Offsets are zero-based among live rows and may change when the table advances.
Results follow the input order. Duplicate offsets have independent cursors,
null blobs return `None`, and empty blobs return a file of size zero. A negative
or out-of-range offset rejects the whole batch. On an async table, use
`await table.take_blob_files(...)` and `await file.aread()` for asynchronous reads.
Enterprise supports Blob V2 columns on native tables with a gateway that
verifies query snapshots. Realtime/MemWAL tables are unsupported.
When selecting rows with a query, pass their `_rowid` values to a fetch method.
`fetch_blob_files` opens a seekable handle and loads bytes only when you read.
The Python example opens the JPEG from the ingest step and reads its EXIF
Make tag with Pillow. TypeScript and Rust read the first bytes from the handle.