Architecting Streaming RAG Pipelines: Beyond Static Vector Chunks
A streaming RAG pipeline keeps answers grounded in live enterprise state by feeding change-data-capture events from Kafka or Kinesis into continuous vector store updates instead of nightly re-indexing. This real-time RAG architecture guide compares CDC, batch, and lambda designs; covers staleness budgets, tombstones, chunk invalidation, and exactly-once writes; and walks a reference build.
Streaming RAG Pipelines: Why Static Vector Chunks Fall Behind
Static RAG indexes rot on contact with production: a batch job embeds yesterday's documents while the ticket system mutates records this morning, and the model answers from a dead chunk. Embedding staleness â the gap between a source change and its vector appearing in retrieval â separates demo RAG from real-time RAG architecture.
Failure signatures of a static index
- Answers cite a policy version the source system already superseded.
- Deleted records still surface because nothing issued a vector delete.
- Freshness-sensitive queries (status, inventory, incident timeline) fall back to direct database calls â RAG is no longer the system of record.
| Approach | Index lag | Cost profile | Consistency | Ops complexity |
|---|---|---|---|---|
| Periodic re-index (batch) | Hours to 24h | Low at small scale, spikes at rebuild | Eventual, coarse | Low |
| CDC streaming (Kafka or Kinesis) | Seconds to minutes | Steady, scales with change rate | Eventual, fine-grained | Medium |
| Lambda (batch plus streaming) | Minutes hot path, hours backfill | Highest â two compute paths | Tunable per query | High |
| Full rebuild per change | Near zero | Prohibitive past small corpora | Strong for one doc | Unmaintainable |
Most teams land on CDC streaming plus occasional batch backfill: streaming owns freshness, batch owns repair. The indexer becomes a consumer rather than a cron job, deletes propagate as tombstone events, and retrieval pairs vectors with live metadata filters.
Key Takeaways
đĄ
- Embedding staleness is the gap between a source mutation and the vector update reaching retrieval; target under 60 seconds for hot tables and under 15 minutes for warm documents.
- CDC ingestion from Kafka or Kinesis beats nightly re-indexing whenever the corpus mutates more than a few times per hour; batch remains right for cold archives.
- Every source delete must become a vector tombstone, or your RAG system will keep answering with rows that no longer exist.
- Chunk invalidation on source mutation means versioning chunks by source row version: a new version retires old chunk ids atomically.
- Exactly-once processing matters at the vector upsert boundary â deduplicate by event id and enforce idempotent writes keyed on chunk id plus version.
- Hybrid retrieval pairs vector similarity with live metadata filters so answers reflect current state, not just semantically close stale text.
CDC vs Periodic Re-Index vs Lambda Architecture
Change-data-capture (CDC) streams row-level inserts, updates, and deletes from a database transaction log instead of polling tables. Each event carries identity to upsert or delete the corresponding chunks.
| Dimension | CDC streaming | Periodic re-index | Lambda architecture |
|---|---|---|---|
| Freshness (typical) | 5 to 60 seconds for hot tables | 6 to 24 hours | 30 seconds hot path, batch corrects drift |
| Lag visibility | Per-partition consumer lag metrics | Known after job finishes | Split across two paths |
| Delete handling | Native tombstone events | Discovered at full rebuild | Streaming deletes, batch reconciles |
| Historical backfill | Separate bootstrap needed | Natural strength of the job | Batch layer owns backfill |
| Compute cost | Steady, scales with change rate | Spikes; wasteful if corpus static | Pays for both paths |
| Infrastructure | Debezium or equivalent plus broker | Scheduler plus crawler | Broker, batch framework, merge logic |
| Failure blast radius | One partition delayed | Whole index waits for job | Layer divergence until merge |
| Best fit | Live state: tickets, CRM, inventory | Archives, weekly policies | Strict freshness plus audit needs |
Choose CDC when rows change continuously. Choose periodic re-index for cold documents with acceptable hourly rebuilds. Choose lambda when compliance needs batch-reproducible snapshots while users need minutes-level freshness â budget for the extra surface first.
Pipeline Stages of an Event-Driven RAG System
A streaming RAG pipeline is a sequence of bounded stages, each with its own lag and error budget:
| Stage | Input | Work | Output | Freshness SLO |
|---|---|---|---|---|
| 1. Capture | DB log via Debezium or native CDC | Publish row change events | Broker topics by entity | Under 5 seconds to broker |
| 2. Normalize | Raw change events | Map to document envelope: source, version, op | Normalized topic | Under 10 seconds |
| 3. Chunk and embed | Normalized envelope | Split text, call embedding model | Chunk vectors with ids | Under 60 seconds |
| 4. Upsert or tombstone | Vectors or delete ops | Idempotent write on chunk id plus version, with ACL metadata | Searchable vector state | Under 10 seconds searchable |
| 5. Retrieve | Query plus caller context | Dense plus keyword plus metadata filter | Ranked chunks | Under 300 ms p95 |
| 6. Verify and answer | Ranked chunks | Freshness check, citation binding, rerank | Grounded answer | End-to-end under 2.5 s |
Track consumer lag per stage â hiding stage 3 latency behind stage 5 dashboards ships stale answers while everything looks green.
Embedding Staleness, Tombstones, and Chunk Invalidation
Embedding staleness is wall-clock time between a committed source change and retrieval reflecting it. Publish it as an SLI: p95 under 60 seconds for transactional tables, under 15 minutes for document stores.
Tombstones: deletes that actually delete
An upsert-only pipeline cannot express deletion. When the source deletes row 4711, the consumer must delete every vector chunk derived from that row:
- Capture the delete event with the source primary key (CDC logs carry it).
- Look up chunk ids by source key via a source-to-chunk manifest.
- Issue vector deletes by chunk id, or write a filtered tombstone marker for soft-delete stores.
- Emit tombstones-applied-per-minute; alert on zero during known delete traffic.
Chunk invalidation on source mutation
Version everything by source row version:
- Each document envelope carries
source_version(log sequence number or updated_at). - Chunk ids include the version suffix, so a new version produces new ids.
- On upsert, write new chunks first, then retire the previous version's ids, and filter retrieval by max version per source.
- Never mutate chunk text in place under a stable id â mixed-version passages are how contradictory sentences reach one context window.
Staleness budget by data class
| Data class | Example | p95 staleness target | Mechanism |
|---|---|---|---|
| Transactional hot | Ticket status, inventory | Under 60 seconds | CDC topic, dedicated embedder |
| Operational warm | Runbooks, configs, policies | Under 15 minutes | CDC with micro-batch embedding |
| Real-time critical | Trading or incident feed | Under 5 seconds | Live-store filter plus retrieval |
Reference Streaming RAG Architecture, Step by Step
A reference build that holds up in production:
- Capture â run Debezium, AWS DMS to Kinesis, or pg_logical; publish per-entity topics with deletes enabled.
- Normalize â map each event into a document envelope: source, primary key, operation, source_version, ACL tags, text.
- Chunk â versioned chunking (500 to 800 tokens, 100-token overlap); store the source-to-chunk manifest.
- Embed â batch 100 to 500 vectors per window; on 429s, exponential backoff so the embedder does not stall the partition.
- Write â upsert vectors with metadata (source_version, updated_at, ACL); apply tombstones; keep writes idempotent on chunk id.
- Reconcile â hourly, compare source rows against chunk manifests; emit drift gauges for missing rows and orphan vectors.
- Serve â hybrid retrieval (dense plus BM25) with metadata filters for tenant, ACL, and max source_version.
- Evaluate â gate changes with evaluation-driven development suites including freshness cases: mutate a doc, wait the SLI window, assert the new fact is retrieved.
A minimal consumer contract:
consumer:
group_id: rag-indexer-v2
processing_guarantee: exactly_once
topics:
normalize:
- doc.events.orders.v1
- doc.events.policies.v1
embed:
batch_size: 256
max_retries: 5
backoff_ms: 500
backoff_multiplier: 2
backoff_max_ms: 30000
vector_store:
upsert_key: chunk_id
idempotent: true
tombstone:
enabled: true
freshness_sli:
p95_staleness_seconds: 60
alert_lag_seconds: 300
Exactly-Once Semantics and Ordering in RAG Feeds
Exactly-once matters most at the vector write boundary. Brokers can deliver at-least-once freely if your writer is idempotent:
- Deterministic chunk ids â hash of source key, source_version, and chunk index; duplicates collapse into one id.
- Version fencing â reject writes older than the stored source_version so out-of-order replays cannot regress freshness.
- Transactional writes â ACID-style batches commit new chunks and retire old ones together where supported.
- Checkpoint offsets after the write commits, never before, so a crash between fetch and upsert replays rather than loses.
Partition by source primary key so one entity stays ordered; global ordering across entities throttles throughput without improving correctness.
The write boundary in practice â deterministic ids, version fencing, and tombstones in one place:
import hashlib
def chunk_id(source_key: str, source_version: str, index: int) -> str:
raw = f"{source_key}:{source_version}:{index}"
return hashlib.sha256(raw.encode()).hexdigest()[:32]
def apply_event(store, manifest, event: dict) -> str:
source_key = event["source_key"]
version = event["source_version"]
op = event["op"]
if op == "delete":
for cid in manifest.get(source_key, []):
store.delete(cid)
manifest.pop(source_key, None)
return "tombstone"
stored = store.get_version(source_key)
if stored is not None and version < stored:
return "fenced" # stale replay must not regress freshness
ids = [chunk_id(source_key, version, i) for i, chunk in enumerate(event["chunks"])]
store.upsert([
{"id": cid, "vector": vec, "metadata": {"source_version": version}}
for cid, vec in zip(ids, event["vectors"])
])
for old in manifest.get(source_key, []):
if old not in ids:
store.delete(old)
manifest[source_key] = ids
return "upserted"
Writes are idempotent because re-applying the same event produces the same ids, and out-of-order replays die at the version fence instead of quietly making retrieval staler.
Hybrid Retrieval on Live Enterprise State
Streaming ingestion only pays off if retrieval uses it. Hybrid retrieval combines three signals:
- Dense vector similarity for semantic recall.
- Lexical search (BM25) for exact identifiers â ticket codes, SKUs, error strings that embeddings blur.
- Live metadata filters â tenant, ACL group, status, recency â applied at query time.
Add a rerank stage over the fused top-50 to top-100, then bind citations to chunk ids carrying source_version so the UI can prove which version was read.
| Retrieval mode | Signal | Strength | Weakness |
|---|---|---|---|
| Dense only | Embedding similarity | Semantic paraphrase recall | Weak on exact ids, hides staleness |
| Lexical only (BM25) | Term overlap | Exact identifier match | Misses paraphrases |
| Hybrid plus filter | Dense, lexical, metadata | Both recall styles, current state only | More tuning, two index paths |
| Hybrid plus rerank | Above plus cross-encoder | Best precision at top-k | Adds 50 to 150 ms latency |
Lag Budgets and Operational SLOs
Treat freshness like latency: publish budgets, alert on burn.
| Signal | Warning | Page | Runbook action |
|---|---|---|---|
| Ingest lag (capture or embed) | Over 2 minutes | Over 10 minutes | Check connector health, scale embed workers, verify backoff |
| p95 staleness (hot data) | Over 60 seconds | Over 5 minutes | Compare consumer offsets, inspect DLQ for poison events |
| Tombstones vs observed deletes | Any mismatch | Zero deletes during delete traffic | Verify delete handler and manifest lookups |
| Source-to-index drift | Over 0.5 percent | Over 2 percent | Run reconciliation backfill for missing keys |
Route poison events â messages that crash the embedder repeatedly â to a dead-letter topic with the raw payload intact. For the broader failure taxonomy, see multi-agent system failures and production fallbacks; for ownership of source tables feeding your CDC topics, see data lineage and metadata observability.
Common Mistakes in Streaming RAG Systems
Common Mistakes
Building an upsert-only pipeline and assuming the index handles deletes
Fix: Translate every source delete into vector deletions via a source-to-chunk manifest, and alert when tombstone counts hit zero during known delete traffic.
Mutating chunk text in place under a stable id
Fix: Version ids by source row version, write the new version first, then retire the old ids â in-place edits mix versions inside one context window.
Checkpointing the consumer offset before the vector store commit
Fix: Commit offsets after the write succeeds so a crash replays the event into an idempotent upsert instead of dropping the change entirely.
Frequently Asked Questions
What is a streaming RAG pipeline?
A streaming RAG pipeline is a retrieval-augmented generation system whose index updates continuously from event streams such as Kafka or Kinesis, so retrieval reflects enterprise state within seconds to minutes instead of waiting for a nightly batch re-index.
What is CDC ingestion for vector indexes?
CDC ingestion for vector indexes means reading the source transaction log to capture row inserts, updates, and deletes, then transforming those events into vector upserts and tombstones â replacing table scans and full rebuilds with fine-grained change propagation and measurable lag.
What is embedding staleness?
Embedding staleness is the elapsed time between a committed change in the source system and that change becoming retrievable from the vector index. Common targets are under 60 seconds p95 for hot transactional data and under 15 minutes for warm documents.
How do delete tombstones work in a vector store?
A delete tombstone is an explicit removal event that hard-deletes vectors by chunk id or writes a marker the retriever filters out. Each source delete must translate into deletions of all chunk ids derived from that source key, usually via a source-to-chunk manifest.
What is exactly-once processing in a streaming RAG system?
Exactly-once processing in streaming RAG means each source change results in exactly one effective vector write â achieved with deterministic chunk ids, version fencing, idempotent upserts, and checkpointing offsets only after the vector store commit.
Last updated: September 23, 2026