Skip to content

feat(v2): Phase 3 — LanceDB index#228

Merged
JonnyTran merged 19 commits into
developfrom
feat/v2-index
Jul 7, 2026
Merged

feat(v2): Phase 3 — LanceDB index#228
JonnyTran merged 19 commits into
developfrom
feat/v2-index

Conversation

@JonnyTran

Copy link
Copy Markdown
Member

Phase 3 of 6 — LanceDB index engine (v2)

Adds a LanceDB-backed index derived from Postgres, exposing full-text (BM25) + scalar-filter search over v2 records via POST /api/v2/schemas/{id}/records:search, kept in sync best-effort on write and rebuildable. Additive only — the v1 search_engine/ (ES/OpenSearch) package is untouched (branch diff is empty over that path); v1 retires in Phase 6.

Spec: docs/superpowers/specs/2026-06-27-schema-centric-data-model-design.md §15 (design) + new §16 (implementation resolutions).
Plan: docs/superpowers/plans/2026-07-07-v2-lancedb-index.md.

What's included

  • index/ package — pure Arrow/row mapping.py (no LanceDB/DB import); v2-shaped IndexEngine ABC + result/filter models (base.py); LanceIndexEngine on the async LanceDB API (lancedb_engine.py); get_index_engine DI provider mirroring get_search_engine.
  • Best-effort sync (contexts/v2/index_sync.py) — ensure/evolve on schema publish, upsert after bulk-upsert, delete on delete. Any engine error is logged at WARNING and swallowed; the API request still succeeds. Only :rebuild-index, rebuild_schema_index, and the reindex CLI surface errors.
  • POST /schemas/{id}/records:search — Lance supplies matching record_ids + scores; payloads are hydrated from Postgres (source of truth), returned in Lance hit order, tolerant of stale-index rows.
  • POST /schemas/{id}:rebuild-index recovery endpoint + extralit_server index reindex|list CLI.
  • EXTRALIT_LANCEDB_URI setting (defaults to {home_path}/lance).

Design guarantees

  • Postgres authoritative; Lance is a rebuildable derived index (never serialized into a response body).
  • One Lance table per schema (schema_{id.hex}): system columns + typed columns (superset across versions via add_columns) + a derived text column carrying the FTS index.
  • Vector/embeddings deferred to the PDF-chunk-retrieval session (spec §15) — no vector column, no similarity_search, no litellm this phase.

Testing / review

  • TDD per task; 85 v2 + index tests pass (the single teardown ERROR is pre-existing Elasticsearch-at-localhost:9200 infra noise). v1 search_engine + v2 index coexist on import; create_server_app() boots; ruff check/format clean.
  • Per-task spec+quality reviews, a whole-branch review, and roborev branch review (job 98 — no issues).
  • Non-blocking follow-ups recorded in spec §16 (deferred-optimize call-count not asserted; ge/le + None → always-false >= NULL; lancedb_uri annotation).

🤖 Generated with Claude Code

JonnyTran added 19 commits July 7, 2026 17:47
Single list_tables() call only returns first page; iterate until
page_token is None to avoid missing tables beyond the first page in
ensure_table, drop_table and search existence checks.
- table_columns: add ORDER BY version ASC so earliest-version dtype
  wins deterministically (prevents dtype divergence between successive
  table_columns calls on the same schema).
- rebuild_schema_index: add V2Record.id as tiebreaker to the OFFSET
  pagination sort key so rows with equal inserted_at cannot be skipped
  across page boundaries.
…ild; add response_model

- RecordFilter: pydantic model_validator rejects op='in' with a scalar value (str/non-iterable)
  raising ValueError → 422 instead of an unmapped TypeError → 500
- LanceIndexEngine.upsert: add optimize=False kwarg; new optimize_table() method
- rebuild_schema_index: upsert all batches with optimize=False, call optimize_table() once
  at the end — avoids O(batches) FTS rebuilds during a full reindex
- rebuild_schema_index endpoint: add response_model=dict[str,int] and timeout advisory docstring
- Test: assert op='in' + scalar → 422
@JonnyTran JonnyTran requested a review from a team as a code owner July 7, 2026 20:21
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
extralit-frontend Ignored Ignored Jul 7, 2026 8:21pm

@JonnyTran JonnyTran merged commit 090547e into develop Jul 7, 2026
6 checks passed
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