Skip to content

Add transactional document deletion and replacement - #7

Merged
1816x merged 1 commit into
mainfrom
codex/add-transactional-document-lifecycle-operations
Aug 17, 2026
Merged

Add transactional document deletion and replacement#7
1816x merged 1 commit into
mainfrom
codex/add-transactional-document-lifecycle-operations

Conversation

@1816x

@1816x 1816x commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Close the gap in corpus lifecycle management by adding transactional delete and replace operations that preserve existing persistence guarantees.
  • Preserve invariants: len(index) == len(chunks), chunk ids dense 0..n-1, every chunk references an existing document, Document.n_chunks matches live chunks, and _next_doc_id never moves backward.
  • Use deterministic full HNSW rebuild/compaction (no tombstones) so surviving vectors are reused and chunk ids remain dense and aligned with HNSW ids.

Description

  • Add a deterministic internal rebuild primitive DocumentStore._rebuild(...) that orders live vectors by document id ascending then chunk ordinal ascending, reuses survivor vectors via the HNSW vector(id) API, inserts vectors into a fresh HNSW, and regenerates dense StoredChunk metadata and document chunk counts.
  • Implement DocumentStore.delete_document(doc_id) and DocumentStore.replace_document(...) with transactional semantics: build staged index/state, call existing _persist when RAG_STATE_PATH is enabled, and only publish the new in-memory state after successful persistence; replacement preserves doc_id and embeds only replacement chunks.
  • Surface lifecycle endpoints in the service: PUT /documents/{document_id} and DELETE /documents/{document_id} that reuse DocumentIn validation and RAG_UPLOADS_ENABLED gating, and return proper 404/403/413/422 semantics; update CORS to allow PUT and DELETE without weakening other controls.
  • Add same-origin Next.js server helpers (deleteDocument, replaceDocument), a dynamic proxy route app/api/documents/[id]/route.ts, and minimal workspace UI controls for Replace/Delete (confirmation, disabled/loading states, error display, refresh after mutation).
  • Add store/regression tests covering deletion, replacement, restart recovery, failed-persistence rollback, dense-id invariants, and embedder call-counting to prove survivors are not re-embedded; update README.md with the rebuild strategy and trade-offs.

Testing

  • Ran Rust checks: cargo fmt --all --check (passed), cargo clippy --all-targets -- -D warnings (passed), and cargo test --workspace (passed).
  • Built and installed the Python bindings with python -m pip install -e bindings (succeeded) and then ran Python tests: PYTHONPATH=service pytest -q bindings/tests service/tests (73 passed, 1 warning) and targeted lifecycle tests PYTHONPATH=service pytest -q service/tests/test_document_lifecycle.py service/tests/test_e2e.py (38 passed).
  • Verified frontend build: cd app && npm ci (succeeded), npm run build (production build succeeded), and npx tsc --noEmit (typecheck passed).
  • Additional checks: python -m compileall -q service and git diff --check ran clean.

All automated test runs listed above passed after installing the bindings; initial collection failed before the editable bindings were installed but was resolved by installing bindings and rerunning the tests.

@1816x
1816x marked this pull request as ready for review August 17, 2026 18:54
@1816x
1816x merged commit ec995a9 into main Aug 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant