Skip to content

Fix chunk fetch loading the entire index into memory#567

Merged
tobocop2 merged 2 commits into
feat/retrieval-consolidatedfrom
fix/chunk-fetch-arrow-fallback
Jul 20, 2026
Merged

Fix chunk fetch loading the entire index into memory#567
tobocop2 merged 2 commits into
feat/retrieval-consolidatedfrom
fix/chunk-fetch-arrow-fallback

Conversation

@tobocop2

@tobocop2 tobocop2 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Problem

get_chunks_by_source and get_chunks_by_indices normally filter in the database. If that query raised, both fell back to table.to_arrow(), which loads every chunk of every document into memory, embedding vectors included, then filters in Python. Multi-gigabyte spike on a large library, and neighbor expansion hits it once per hit source per query.

Closes #565.

Solution

The fallback guarded old LanceDB behavior where FTS-indexed tables rejected .where(). That no longer reproduces on the pinned version, so it was dead code kept alive by tests that mocked search() into raising.

Both functions now let a query failure propagate. An exception names the problem; the rescue scan just gets the process OOM-killed. The mocked tests are replaced by ones that build the FTS index for real, so a future LanceDB bump that breaks the query fails CI instead of silently reading everything.

get_chunks_by_source and get_chunks_by_indices rescued a failed filtered
query by calling table.to_arrow(), which materializes every chunk of every
document -- embedding vectors included -- before filtering in Python. On a
large library that is a multi-gigabyte spike, and neighbor expansion hits it
once per hit source per query.

The fallback guarded a LanceDB version whose FTS-indexed tables rejected
.where() on arbitrary columns. That no longer reproduces: a filtered
empty-search query returns the right rows on an FTS-indexed table, so the
path was dead code held alive by tests that mocked search() into raising.

Both functions now let a query failure propagate. An exception names the
problem; an OOM kill from the rescue scan leaves nothing to debug. The two
mocked-fallback tests are replaced by tests that build the FTS index for
real and assert the filtered query still selects rows, so a future LanceDB
bump that breaks the predicate fails CI instead of failing in production.
@tobocop2 tobocop2 changed the title Fetch a document's chunks without ever reading the whole index Stop the chunk fetch from loading the whole index into memory Jul 20, 2026
The test patched pathlib.Path.expanduser globally; the config validator also
expands the data root on every field assignment, so the cfg-restoring fixture
raised through the patch at teardown and turned the whole suite red. Patch
only the autocomplete module's Path instead. The breakage predates this branch
(it came with the data-root expanduser fix on the base) but blocks this PR's
CI, so carry the one-test fix here too.
@tobocop2
tobocop2 marked this pull request as ready for review July 20, 2026 15:45
@tobocop2
tobocop2 merged commit d9bd867 into feat/retrieval-consolidated Jul 20, 2026
45 of 51 checks passed
@tobocop2 tobocop2 changed the title Stop the chunk fetch from loading the whole index into memory Fix chunk fetch loading the entire index into memory Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant