Artificial Intelligence

Elasticsearch incremental index update creates duplicate vector IDs and stale pointers causing RAG to cite deleted passages

tildatech
1mo ago
Environment

Environment

Self-hosted Elasticsearch cluster used as vector store for RAG pipeline. Incremental index updater job (Python) runs nightly to add/replace vectors; deletions are performed by marking documents and issuing delete-by-query followed by segment merge.

Symptoms

Symptoms

After incremental job runs, RAG assistant returns passages that were deleted earlier and sometimes returns the same passage for multiple queries (duplicates). Vector dashboard shows duplicate vector IDs and some vectors reference outdated document pointers.

Observations

Observations

Index contains duplicate _id values (older id retained in segments), delete-by-query did not immediately remove all vector vectors. Merges/refreshes ran but duplicates persisted across shards. The update job uses bulk API with upsert semantics and a separate job that issues delete-by-query for removed docs; concurrency between these jobs observed in logs.

Already attempted

Already attempted

Forced a full index refresh and manual force-merge to 1 segment; duplicates reduced but reappeared after next incremental run. Adjusted bulk update to use explicit doc IDs, added versioning, and temporarily disabled delete job — duplicates still created when add/replace concurrency exists.

Question

Question

Why are deleted vectors resurfacing and duplicate vector IDs being created by incremental update, and how to safely avoid stale pointers in RAG retrieval?

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

Race between bulk upserts and delete-by-query causing older segment copies to persist and later reappear 90%
Indexer using inconsistent document IDs or routing so duplicates are indexed as separate docs 60%
Vector plugin storing external pointers not updated atomically with vector updates 50%

Summary

This pattern indicates race conditions between the incremental bulk-upsert job and delete-by-query/merge process. Elasticsearch delete-by-query is asynchronous and can leave tombstones that are later resurrected if a bulk index with the same doc ID writes to a segment prior to merge visibility, especially if updates use different routing/IDs or the updater doesn't enforce external versioning. Additionally, vector plugin or custom metadata pointers may not be atomically updated, leaving stale text pointers even when vector replaced. Force-merge temporarily consolidates segments but doesn't prevent future races if concurrency continues.

Suggested Fixes

Diagnostic step 1
Stop concurrent delete-by-query and bulk-upsert jobs; ensure single updater writes changes for an ID atomically.
Diagnostic step 2
Switch bulk updates to use explicit, stable document IDs and external versioning (set _version_type=external and supply a monotonically increasing version) so newer writes always win.
Diagnostic step 3
When deleting, prefer deleting by ID (bulk delete) rather than delete-by-query for high-concurrency workflows; follow with a refresh to make deletions visible.

Continue troubleshooting

Matched from the title, description and tags