mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-26 23:51:14 +02:00
3.6 KiB
3.6 KiB
Phase 4 — Derived index + reindex
Can build alongside Phase 3 (both only need Phase 1's
commit/log). Umbrella:00-umbrella-plan.md.
Objective
Make Postgres a derived, rebuildable chunk/embedding index of the git repo: incremental on each commit (keyed by blob SHA), fully reproducible via one reindex(workspace). Delete the three hand-rolled versioning systems — git history replaces them.
Locked model
- Post-commit incremental index. On each commit, diff the tree against the parent, and for changed blobs re-chunk + re-embed. Key embeddings by git blob SHA: unchanged blob → same SHA → reuse existing vectors (no re-embed). This is the correct, native form of what
indexing_pipeline/chunk_reconciler.py::reconcilealready approximates (it matches by chunk text; blob SHA generalizes it to file identity). - Postgres is disposable. A single idempotent
reindex(workspace)wipes chunks/embeddings and rebuilds from git HEAD (the Fossilrebuilddiscipline). Search (shared/retrieval/hybrid_search.py) is unchanged — it reads the samechunkstable. - History = git. Delete
utils/document_versioning.py(DocumentVersion),services/revert_service.py+DocumentRevision/FolderRevision(Alembic migration to drop tables).git log/diff/revert/blamereplace them.
Work items
app/kb_git/indexer.py—index_commit(workspace_id, sha): tree-diff parent→sha, map changed paths→documents/chunks, re-chunk changed files, embed only new blob SHAs, upsert chunks; delete chunks for removed paths.- Blob-SHA reuse is new (there is no embedding cache today —
embed_textscalls the model directly; current reuse ischunk_reconcilermatching by chunk text). Add a(embedding_model_version, blob_sha)reuse layer, or generalize the reconciler from chunk-text identity to blob identity.content_hashis workspace-salted, so it is NOT the git blob SHA — do not alias them. See00c-shared-contract.mdC5. reindex(workspace_id)— wipe + full rebuild from HEAD; wire a Celery task entrypoint (Celery already runs; keep long rebuilds off the API process).- Trigger
index_commitoff the Phase-3 commit event. - Delete the three versioning systems + Alembic migration dropping
document_versions,document_revisions,folder_revisions. This also removes the snapshot code embedded incommit_staged_filesystem_state(Phase 3) — coordinate the two.
Tests
- Edit one file → only its chunks re-embed; other files' vectors are byte-identical (blob-SHA reuse verified).
reindex(workspace)produces a chunk set identical to the incremental path (determinism).- Search results for a fixed query match the pre-pivot baseline for the same content.
- Deleting a file removes its chunks; renaming preserves vectors (same blob SHA).
- Post-migration: version/revert endpoints and tables are gone; no import references remain.
Out of scope
- Live connectors (Slack/Gmail) — never indexed.
- Zero row projection → Phase 6. Reranker/chunking strategy changes (separate search work).
Resolved (see 00c-shared-contract.md)
- content_hash vs blob SHA: they differ (content_hash is workspace-salted); key embedding reuse by blob SHA, keep
content_hashthrough migration, drop later if redundant (C5). - Cache location: none exists today — the reuse layer is new (C5).
- Where
reindexruns: Celery task (C5).
Open questions
reindexprogress/observability surface (log vs. status row) — cosmetic, not blocking.