Artificial Intelligence

Incremental vector index job creates duplicate vector IDs and stale text pointers — RAG assistant returns deleted passages

Environment

Environment

Self-hosted vector DB (custom pipeline using Faiss + metadata store PostgreSQL) running on Ubuntu 20.04; nightly incremental index job processes document diffs: insert new docs, update changed docs, delete removed docs. Embeddings generated by hosted model (API). RAG pipeline queries vector DB and fetches document text by stored pointer (doc_id) from metadata store.

Symptoms

Symptoms

After incremental job completes, search results sometimes return passages from documents that were deleted earlier in the day. Running similarity queries returns high-similarity scores pointing to vector IDs that no longer exist in the metadata table. Reindexing full dataset fixes the problem until next incremental run.

Observations

Observations

Indexer logs show 'upsert vector id X' followed by 'delete doc id X' during the same job for some documents (order depends on file processing). The vector index contains duplicate vector IDs according to internal mapping (two vectors map to same external doc_id), and metadata table shows doc_id marked deleted. Audit logs show the incremental job retries on transient embedding generation failures and then re-applies operations. There is a separate compact/merge job running weekly. No errors reported by Faiss during upserts/deletes.

Already attempted

Already attempted

Inspected incremental job code: it performs 'embed -> upsert vector -> update metadata -> if delete mark metadata deleted -> remove vector' but ordering is subject to retry/backoff. Added additional logging and ran indexer in dry-run — saw race where delete task runs before previous upsert completed due to asynchronous worker pool. Manually removed duplicate vectors by scanning for vector_id collisions and deleting stale vectors — temporarily resolved. Full reindex clears all duplicates.

Question

Question

What are the likely root causes for duplicate/stale vectors after incremental updates and what robust, reversible safeguards should I implement in the pipeline to avoid RAG returning deleted passages without requiring full reindex every time?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Non-atomic incremental workflow: upserts, metadata updates, and delete operations interleave due to async workers and retries, producing orphaned/duplicate vectors 95%
Vector DB (Faiss) client library not using an external unique-id mapping layer, allowing duplicate internal IDs when same external id is upserted rapidly 60%
Embedding generation retries produce different vector IDs for same doc leading to stale pointers if metadata update fails 45%

Summary

Evidence points to race conditions and non-atomic operations in the incremental pipeline: asynchronous upserts, retries, and non-idempotent operations allow upsert and delete to interleave, leaving orphaned vectors or duplicate vector entries referencing deleted doc IDs. The vector store and metadata DB are not updated atomically, so consistency gaps appear. Faiss itself may not enforce unique external IDs; the metadata store must be canonical.

Suggested Fixes

Diagnostic step 1
Make the incremental update sequence atomic from the application's perspective: implement a two-phase update or a transaction-like pattern where metadata changes (in PostgreSQL) are only committed after successful vector upsert/remove. For example, write a change-log row and have a single worker apply vector-store changes in order.
Diagnostic step 2
Switch to idempotent operations: ensure upsert includes a deterministic external id and the vector DB client overwrites old vectors for the same external id rather than creating duplicates. If Faiss client doesn't support this, maintain a mapping table that records current vector internal id and update that atomically.
Diagnostic step 3
Add optimistic locking or processing queue: serialize updates per document (per-doc worker or consistent hashing) to avoid concurrent upsert/delete for same doc. Add dedupe check: before querying for vectors, verify metadata 'deleted' flag and skip entries.

Continue troubleshooting

Matched from the title, description and tags