Skip to content

fix: isolate RAG corpus vector lifecycles and publish consistent snapshots - #302

Open
Cookie0103 wants to merge 2 commits into
ANative-Lab:mainfrom
Cookie0103:fix/rag-corpus-lifecycle
Open

Cookie0103 wants to merge 2 commits into
ANative-Lab:mainfrom
Cookie0103:fix/rag-corpus-lifecycle

Conversation

@Cookie0103

Copy link
Copy Markdown

RAG corpora currently own different LlamaIndex document catalogs but share one FAISS backend. A query can select vectors from another corpus, and replacing/deleting duplicate external node IDs can affect the wrong corpus. Failed updates can remove the old vector before embedding succeeds, while repeated snapshot loads append duplicate backend state.

This repairs the vector-corpus lifecycle across ingestion, retrieval, deletion and persistence:

  • Give each vector index its own FAISS backend, retaining trained IVF centroids/settings without copying template vectors.
  • Allocate stable native IDs after deletion, validate complete batches before mutation, and journal touched vectors/catalog records so failed writes restore the previous committed state. Caller inputs remain unchanged.
  • Use request-local retrievers and one mutation lock for native search plus node resolution. Keep registry locks short so slow ingestion does not block unrelated async queries; serialize lifecycle writers to prevent duplicate publication or resurrection after clear/load.
  • Validate snapshots and construct complete replacement indexes before publishing them. Preserve corpus identity from metadata, support legacy JSONL pairs, and atomically publish checksummed file generations.
  • Preserve multiple index types under the existing database corpus primary key, without a schema migration; keep colliding local chunk IDs distinct during reranking.

Validation: 307 tests passed in the full suite, including 65 RAG/storage tests and real local FAISS flat/IVF tests with deterministic embeddings. The original implementation fails all 17 selected lifecycle reproductions. Independent review caught and verified a registry-lock regression: the same 20 ms async heartbeat improved from about 416 ms to 21 ms while another corpus was embedding. New event-order and lifecycle writer tests verify the repair. No paid provider requests were used.

Incremental write measurements journaled only three catalog keys at both 1,000 and 5,000 existing nodes; native vector corpora are not cloned. LlamaIndex's existing full index-ID mapping serialization still contributes O(corpus size) metadata cost.

Compatibility notes: direct VectorIndexing.insert_nodes now propagates the original failure; RAGEngine.add retains its existing empty-list failure result. New file snapshots retain older content generations for readers already using them, so repeated saves accumulate files. Existing graph-backend transaction boundaries remain unchanged. The configured vector backend is now a template for isolated corpus stores.

Prepared with AI assistance.

This branch has not been deployed

No deployments
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