Skip to content

perf(query): pyarrow.compute filters, index-backed prefix scans, shared DB + pragmas - #193

Closed
nwaughachukwuma wants to merge 1 commit into
feat/hybrid-retrievalfrom
claude/perf-query-plans-s230yb
Closed

perf(query): pyarrow.compute filters, index-backed prefix scans, shared DB + pragmas#193
nwaughachukwuma wants to merge 1 commit into
feat/hybrid-retrievalfrom
claude/perf-query-plans-s230yb

Conversation

@nwaughachukwuma

@nwaughachukwuma nwaughachukwuma commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

The uri-prefix range predicate lands inside _chunk_filter_sql, so the bm25 path and the LIKE fallback both become index-selective per directory instead of post-filtering results from the global table.

  • Context.filter / find --sort/--depth: vectorized pyarrow.compute instead of round-tripping the Arrow table through an in-memory SQLite DB (which also degraded timestamps to ints — schema is now preserved).
  • uri LIKE 'prefix%' → index-backed range predicates: the files.uri PK index is never used by LIKE, so every prefix query scanned the entire global DB. Applied to the chunk filter, mm sql, semantic search, and prune_missing; mm sql also reuses fetched rows instead of a third table scan.
  • New indexes: chunks(content_hash, mode, extraction_id, chunk_idx), extractions(content_hash) — the per-file has_text_chunks probe was scanning every orphan chunk in the global DB.
  • shared_db() everywhere (one schema bootstrap per process; a single grep -s did it 4-6x) + busy_timeout (writers previously failed immediately under concurrency), 64 MB page cache, mmap, in-memory temp store; chunks_vec probe memoized.

Speed gains

Change Old New Speedup
Context.filter (500 files) 6.79 ms 62 µs 110x
uri prefix predicate (20k rows, 1k matches) 1.85 ms 0.55 ms 3.3x; plan flips SCAN → SEARCH, gap grows with DB size
has_text_chunks probe (per cat'd file) O(orphan chunks) scan indexed seek O(chunks) → O(log n)
schema bootstrap per CLI invocation 4-6x 1x

Validation

Full suite passes (1,197 passed; the 2 TestRecordingFile failures are pre-existing environment failures on the base). Query-plan invariants are unit-tested (TestQueryPlans: SEARCH-not-SCAN assertion + range/LIKE semantic equivalence); filter has an A/B benchmark against the still-shipping query_arrow_table.

🤖 Generated with Claude Code

https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@nwaughachukwuma
nwaughachukwuma force-pushed the claude/core-perf-optimization-s230yb branch from 9ce1d7e to 0d2f4ca Compare August 12, 2026 10:30
…ed DB + pragmas

Stacked on the bm25/FTS work (#180); the range predicate lands inside
_chunk_filter_sql so both the bm25 path and the LIKE fallback become
index-selective per directory instead of post-filtering the global table.

- Context.filter and find --sort/--depth via vectorized pyarrow.compute
  instead of an in-memory SQLite round-trip (62µs vs 6.8ms per filter at
  500 files; Arrow schema/types now preserved).
- uri LIKE 'prefix%' → index-backed range predicates (plan flips full-table
  SCAN → index SEARCH, asserted in tests) across the chunk filter,
  mm sql, semantic search, and prune_missing; mm sql reuses fetched rows
  instead of a third table scan.
- New chunks(content_hash, mode, extraction_id, chunk_idx) and
  extractions(content_hash) indexes: the per-file has_text_chunks probe was
  scanning every orphan chunk in the global DB.
- shared_db() at every call site (one schema bootstrap per process, was 4-6
  per grep -s); busy_timeout/cache_size/mmap_size/temp_store pragmas;
  chunks_vec existence probe memoized per connection.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012GnYsrLTmdJphKkm7yjWDV
@nwaughachukwuma
nwaughachukwuma force-pushed the claude/perf-query-plans-s230yb branch from 5411164 to 48c92e5 Compare August 12, 2026 10:38
@nwaughachukwuma
nwaughachukwuma changed the base branch from claude/core-perf-optimization-s230yb to feat/hybrid-retrieval August 12, 2026 10:38
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.

2 participants