Add transactional document deletion and replacement - #7
Merged
1816x merged 1 commit intoAug 17, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
deleteandreplaceoperations that preserve existing persistence guarantees.len(index) == len(chunks), chunk ids dense0..n-1, every chunk references an existing document,Document.n_chunksmatches live chunks, and_next_doc_idnever moves backward.Description
DocumentStore._rebuild(...)that orders live vectors bydocument idascending thenchunk ordinalascending, reuses survivor vectors via the HNSWvector(id)API, inserts vectors into a fresh HNSW, and regenerates denseStoredChunkmetadata and document chunk counts.DocumentStore.delete_document(doc_id)andDocumentStore.replace_document(...)with transactional semantics: build staged index/state, call existing_persistwhenRAG_STATE_PATHis enabled, and only publish the new in-memory state after successful persistence; replacement preservesdoc_idand embeds only replacement chunks.PUT /documents/{document_id}andDELETE /documents/{document_id}that reuseDocumentInvalidation andRAG_UPLOADS_ENABLEDgating, and return proper404/403/413/422semantics; update CORS to allowPUTandDELETEwithout weakening other controls.deleteDocument,replaceDocument), a dynamic proxy routeapp/api/documents/[id]/route.ts, and minimal workspace UI controls for Replace/Delete (confirmation, disabled/loading states, error display, refresh after mutation).README.mdwith the rebuild strategy and trade-offs.Testing
cargo fmt --all --check(passed),cargo clippy --all-targets -- -D warnings(passed), andcargo test --workspace(passed).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 testsPYTHONPATH=service pytest -q service/tests/test_document_lifecycle.py service/tests/test_e2e.py(38 passed).cd app && npm ci(succeeded),npm run build(production build succeeded), andnpx tsc --noEmit(typecheck passed).python -m compileall -q serviceandgit diff --checkran 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
bindingsand rerunning the tests.