#3602·lancedb

Silent vector/row misalignment when appending large_list vectors (writer drops FixedSizeList child-array offset)

Author: ddangelovCreated Jun 30, 2026Updated Sep 24, 2026

Summary

When appending data whose vector column is a large_list<float> (rather than fixed_size_list), LanceDB silently misaligns the vector values onto the wrong rows for a subset of rows. The vectors themselves are intact — each affected row receives a vector that belongs to a different row, shifted by a constant offset. The scalar columns stay correctly aligned, so the corruption is invisible unless vectors are compared against their source.

Environment

  • lancedb 0.30.2
  • pyarrow 24.0.0
  • Python 3.12, macOS (arm64)

Reproduction

Self-contained. Each row i is given vec0 = [i, i, …, i], so a correct round-trip means row i reads back as all-i.

python
import os, tempfile
import lancedb, numpy as np, polars as pl

DIM = 304
N = 120_000
ROW_GROUP = 12_221   # row groups smaller than the load chunk -> cross-chunk Arrow slices
CHUNK = 30_000

rng = np.random.default_rng(0)
noise = [list(map(float, rng.standard_normal(DIM).astype(np.float32))) for _ in range(N)]
df = pl.DataFrame(
    {
        "id": np.arange(N),
        "text_a": [f"a-{i}" for i in range(N)],
        "text_b": [f"row {i} " * 5 for i in range(N)],
        "vec0": [[float(i)] * DIM for i in range(N)],
        "vec1": noise,
        "vec2": noise,
    },
    schema_overrides={
        "vec0": pl.List(pl.Float32),
        "vec1": pl.List(pl.Float32),
        "vec2": pl.List(pl.Float32),
    },
)

path = os.path.join(tempfile.mkdtemp(), "data.parquet")
df.write_parquet(path, row_group_size=ROW_GROUP)
loaded = pl.read_parquet(path)
print("vector arrow type:", loaded.to_arrow().column("vec0").type)  # large_list<item: float>

db = lancedb.connect(tempfile.mkdtemp())
tbl = db.create_table("t", loaded.head(5))     # establishes fixed_size_list schema
for chunk in loaded.iter_slices(n_rows=CHUNK):
    tbl.add(chunk, mode="append")

back = tbl.to_pandas().drop_duplicates("id")
wrong = [int(r.id) for r in back.itertuples()
         if not np.allclose(np.asarray(r.vec0, dtype=np.float32), float(r.id))]
print(f"misaligned rows: {len(wrong)} / {len(back)}")
i = sorted(wrong)[0]
got = np.asarray(back[back.id == i].vec0.iloc[0], dtype=np.float32)
print(f"row id={i}: expected all {float(i)}, got all {got[0]} (shifted by {i - int(got[0])})")

Output:

vector arrow type: large_list<item: float>
misaligned rows: 15536 / 120000
row id=30000: expected all 30000.0, got all 24442.0 (shifted by 5558)

Expected: misaligned rows: 0 / 120000.

Root cause

The vector column arrives as large_list<float> (polars exports list columns as large_list). Since the table schema is fixed_size_list<float, 304>, _sanitize_data → _cast_to_target_schema (lancedb/table.py) casts each incoming RecordBatch:

python
yield pa.Table.from_batches([batch]).cast(reordered_schema).to_batches()[0]

When a parquet file has more row groups than fit a load chunk, iter_slices yields chunks whose Arrow representation is multiple zero-copy batches, and the first batch of a chunk is often the tail of a chunk — i.e. a large_list slice with a non-zero outer offset sharing a values buffer with earlier rows.

Casting such a slice to fixed_size_list produces an array that is semantically correct but whose values child carries a non-zero offset:

fixed_size_list array: offset=0, length=6723
  values child:        offset=1671392   (= 5498 * 304)

Reading element 0 respecting that child offset gives the correct vector; reading it from buffer position 0 (ignoring the child offset) gives the vector 5498 rows earlier. The read-back data matches the latter — i.e. the writer drops the values-child offset of the FixedSizeListArray and reads the values buffer from position 0. The shift equals the offset, which is why the result is a constant-offset misalignment that begins exactly at chunk boundaries.

The bug only surfaces past a row-width/buffer-size threshold (it does not reproduce with a single narrow vector column, but does with wider rows — multiple 304-d vectors plus string columns), which points at the writer's batch-splitting / buffer-handling path rather than the cast itself. The Python-side _sanitize_data output is fully aligned; the misalignment is introduced downstream in the writer.

Conditions to trigger

  1. Vector column supplied as large_list (or list) so LanceDB casts to fixed_size_list (supplying fixed_size_list directly hits the reader.schema == target_schema fast path, skips the cast, and there is no corruption).
  2. Input arrives as multiple Arrow batches where a batch is a zero-copy slice with a non-zero offset into a shared values buffer (typical for multi-row-group parquet read via polars/pyarrow and sliced for batched loading).
  3. Rows wide enough to cross the internal size threshold.

Workarounds

Either of these fully avoids it (verified, 0 misaligned):

  • Cast vector columns to fixed_size_list before handing data to LanceDB:
    python
    table = table.set_column(idx, name, table.column(name).cast(pa.list_(pa.float32(), DIM)))
  • Materialize each batch with combine_chunks() so the values child has offset 0.

Both make the values child offset 0, so the writer reads the correct data.