Data Consistency in Indexing Pipelines

How a crash or two racing versions leave stale rows in a RAG index, and how CocoIndex v1 keeps its internal store and your vector index consistent.

Concept6 min read

Crash or race, the index converges

Tracked keys stay a superset of the rows in the index, and runs of one item never overlap.

An indexing pipeline builds indexes derived from source data. The index should always converge to the current version of the source: once the pipeline processes a new version of a source item, no data derived from earlier versions should remain in the target index. This is the data consistency requirement for an indexing pipeline.

If you build RAG or an AI agent, that index is what the model reads at query time. A row that should have been deleted gets retrieved and quoted as current.

Crashes and races leave stale rows

A long-running pipeline faces two problems that an in-memory transformation in one process does not: a run can crash partway, and concurrent runs can finish out of order.

Crashes. A crash can leave stale or leaked rows. A pipeline’s work spans several processes over time. A run can stop partway, from a SIGTERM, a failed write to the target or a reboot. The next process must pick up the existing state and finish moving the target to the desired state. If the source item changed again before the restart, the pipeline must still find and delete the rows derived from the old version.

Races. An old version can overwrite a new one. Processing runs concurrently, sometimes on several machines. Suppose one source item changes quickly:

  1. Version 1 (V1) is in the index.
  2. Version 2 (V2) and Version 3 (V3) arrive within a second of each other.
  3. V2 takes longer to process than V3.

If V2’s writes land after V3’s, the index ends on V2. It has rolled back to stale data, and nothing reports an error.

Where stale rows surface

Stale rows surface wherever the index is read:

  • Retrieval. RAG answers, semantic search results and agent actions draw on outdated or retracted chunks.
  • Mixed versions. Chunks from two versions of one document sit side by side, and the internal state disagrees with the index.
  • Deletion and compliance. A deleted document, or personal data removed under a privacy rule such as GDPR, stays searchable.
  • Product data. A customer-facing app shows an old price or product detail.

How CocoIndex v1 keeps two stores consistent

CocoIndex v1 handles crashes with a fixed write order across its two stores, and races by serializing runs of one source item.

Two stores, no shared transaction

If all your state and your index live in one transactional database (for example, PostgreSQL with pgvector), a database transaction keeps them consistent. With CocoIndex they never share one: CocoIndex keeps its own internal storage in LMDB, and your index can live in an external vector store such as Qdrant, LanceDB or turbopuffer that holds the vector embeddings. The two stores share no transaction.

CocoIndex records, for each source item, the keys of the target rows it produced. When the item changes or goes away, that record is how it finds the rows to delete. So the record must never miss a row: if a crash leaves a row in the index that the internal store does not know about, nothing deletes it later.

Write order: claim, apply, commit

In CocoIndex v1 you typically mount each source item as its own processing component. The component runs your function and declares the rows (target states) the item should produce. Processing makes no target writes: it builds the declared rows in memory. All writes happen after processing completes, and each component’s changes sync as one unit, in three steps:

  1. Claim. In one LMDB transaction, CocoIndex records the keys of the new rows and marks the update as in flight. For each row it touches, it keeps both the old and the new state as possibilities.
  2. Apply. The target connector writes the changes to the target: upserts for new and changed rows, deletes for rows the component no longer declares. A backend that supports transactions applies the batch atomically. Changes to different backends are not transactional with each other.
  3. Commit. A second LMDB transaction records the new state as current and drops the keys of the deleted rows.

The order keeps one invariant: the keys tracked in the internal store are always a superset of the rows in the target. A row reaches the target only after its key is tracked, and a key leaves the internal store only after its row is deleted. So every row in the target has a tracked key that a later run can use to delete it.

Recovery: reconcile against every possible previous state

If the process dies between claim and commit, some writes may have reached the target and some may not. CocoIndex does not try to undo them. On the next run it computes the desired rows again, and the target connector reconciles against all possible previous states: the old state, the new state, or a mix. Built-in connectors use convergent operations such as upserts (INSERT ... ON CONFLICT DO UPDATE), so writing a row a second time is safe, and the target converges to the desired rows whichever previous state was real.

The demo below follows doc.md from V1 to V2. Pick where the process dies, then turn on the wrong write order, which writes the index first and records the keys after, and pick “doc.md deleted” for the next run.

Crash between two stores

doc.md: V1 (c1, c2) → V2 (c1 changed, c2 gone, c3 new)
Where the process dies
  1. 1 claim keysLMDB · done
  2. 2 write rowsindex · partly done
  3. 3 commitLMDB · not run

Dashed border: not run yet, or dropped at commit.

Crash during the index write: the index holds c1 v2, c2 v1, c3 v2; the internal store tracks c1, c2, c3.

At the crash

Internal store · LMDB

in flight: V1 or V2

  • c1
  • c2dropped at commit
  • c3claimed

Vector index

rows

  • c1 · v2changed
  • c2 · v1
  • c3 · v2new
After the next run
Next run

Internal store · LMDB

committed: V2

  • c1
  • c3

Vector index

rows

  • c1 · v2
  • c3 · v2

Next run, doc.md unchanged: the index converges to c1 and c3 at V2.

Reconcile: upsert c1, c3; delete c2.

With the right order, every crash point converges. With the wrong order, a crash during or after the index write leaves row c3 in the index with no key in the internal store. If the next run still declares c3, the upsert hides the gap. If doc.md is deleted, nothing knows c3 exists, and no later run deletes it.

Two versions in flight: runs of one component never overlap

Each source item keeps a stable component path across runs, and CocoIndex serializes runs at the same path. A run holds the component’s lock from before your function starts until its result is stored, so two runs of one component never overlap. If V3 arrives while V2 is still processing, the V3 run waits. V2 commits first, then V3 runs and commits. The index can show V2 for a moment, but it does not end on V2.

CocoIndex does not compare source versions or timestamps to do this. The order comes from serializing runs of the same component. Runs take the lock in the order they start, so the later version runs last. The lock lives in one CocoIndex process, so it orders runs within that process; two processes updating the same app are not serialized with each other.

In the demo below, V3 arrives 0.4 s after V2 and finishes processing first. Switch the pipeline to see which version the index ends on.

V2 slower than V3

Illustrative timings
Pipeline

Serialized runs (CocoIndex v1): the V3 run waits for the V2 run to commit, so the index ends on V3.

  1. 0.0s: V2 arrives; its run takes the component's lock.
  2. 0.4s: V3 arrives; its run waits for the lock.
  3. 2.0s: V2 commits. The index shows V2.
  4. 2.0s: V3 runs.
  5. 2.8s: V3 commits. The index ends on V3.

What else the framework handles

Consistency is one part of running a long-lived indexing pipeline.

In CocoIndex you write the transformation as a function of its input and declare the rows it should produce. This is the state-driven model. CocoIndex handles the rest:

  • create, update and delete calls across different target APIs
  • results of earlier computations, through function memoization
  • incremental processing and the state it needs
  • the write order and run serialization above
  • reprocessing when the code of a function changes

The processing component guide, the error handling guide and the custom target connector guide go deeper on each step. The source is on GitHub.

Frequently asked questions

What does data consistency mean for an indexing pipeline?

An indexing pipeline builds indexes derived from source data. The index should always converge to the current version of the source: once a new version is processed, no data derived from earlier versions remains in the target index.

See the opening definition and the two problems.

Why are concurrent updates hard for indexing pipelines?

Two problems. A run can stop partway (SIGTERM, a failed write to the target, a reboot), and the next process must still clear rows from old versions. Runs also execute concurrently: if V2 and V3 arrive together and V2 finishes last, the index ends on V2.

See Crashes and races leave stale rows.

What can go wrong when an index is inconsistent with its source?

RAG answers, semantic search results and agent actions draw on outdated or retracted chunks. Chunks from two versions of one document can sit side by side. A deleted document, or personal data removed under a privacy rule such as GDPR, can stay searchable. A customer-facing app can show an old price or product detail.

See Where stale rows surface.

How does CocoIndex keep its internal store consistent with a non-transactional vector store?

CocoIndex tracks the keys of the rows each source item produced in its internal LMDB store, which shares no transaction with an external vector store such as Qdrant, LanceDB or turbopuffer. After a processing component finishes, CocoIndex writes in three steps: it claims the new keys in an LMDB transaction, applies upserts and deletes to the target, then commits in a second LMDB transaction and drops the keys of deleted rows. The tracked keys are always a superset of the rows in the target, so no row is ever left untracked.

See Write order: claim, apply, commit.

What happens if the process crashes in the middle of a write?

CocoIndex does not undo partial writes. While an update is in flight it keeps both the old and the new state of each row as possibilities. On the next run it computes the desired rows again and the target connector reconciles against all possible previous states. Built-in target connectors use convergent operations such as upserts, so the target ends at the desired rows whether the earlier write finished, half-finished or never ran.

See Recovery.

Can an older version overwrite a newer one when updates arrive close together?

Not for runs of the same source item in one CocoIndex process. Each item keeps a stable component path, and CocoIndex serializes runs at that path: a run holds the component's lock from before your function starts until its result is stored. If V3 arrives while V2 is processing, the V3 run waits, V2 commits, then V3 commits. Two processes updating the same app are not serialized with each other. CocoIndex does not compare source versions or timestamps for this.

See Two versions in flight.

What does CocoIndex handle besides consistency?

You write the transformation as a function of its input and declare the rows it should produce. CocoIndex handles memoization of earlier results, incremental processing and its state, data consistency, and reprocessing when the code of a function changes.

See What else the framework handles.

Build fresh context for your agents.

CocoIndex keeps derived data in sync with its sources. Only what changed re-runs.