What it is
An embedding pipeline keeps a vector index in sync with a body of documents. For every new or changed document it extracts the text, splits it into chunks, sends the chunks to an embedding model that returns one vector per chunk, and upserts those vectors, together with the chunk text and metadata, into a vector store. Deleted documents and permission changes flow through the same pipeline.
Why it exists
Semantic search and retrieval-augmented generation need vectors for everything they might retrieve. Producing them is slow (a network call per batch), metered (embedding APIs bill and throttle by tokens), and has to happen again whenever a document changes or the embedding model does. A pipeline makes that work reliable, repeatable and scalable instead of a script someone reruns.
How it works
Extract. Get clean text out of PDFs, Office files, HTML or wiki markup, keeping structure (headings, lists, tables) where possible. Extraction quality limits everything downstream.
Chunk. Embedding models accept a limited input, and one vector per long document blurs its topics together. Split into chunks of a few hundred tokens, often with a small overlap. Structure-aware splitting (by heading, paragraph, table row) usually retrieves better than fixed character counts. Attach metadata to each chunk: document id, chunk index, section title, source URL, tenant and access-control information, timestamps.
Embed. Send chunks in batches; most embedding APIs accept many inputs per request, which cuts per-request overhead and request-count limits. The same model (and version) must embed both documents and queries.
Upsert. Write vector + text + metadata keyed by a deterministic id such as documentId#chunkIndex. When a document shrinks, delete the chunk ids past its new last index; when it is deleted, delete all of them.
Queue and workers. Accepting a change should be fast; embedding it is not. The ingest endpoint validates and enqueues; stateless workers consume at their own pace. Bursts become backlog: backlog grows at arrivals minus processing rate, and drains at processing rate once the burst ends.
Throttling. The embedding API’s quota (tokens per minute) caps throughput no matter how many workers run. Workers should back off on 429 (respecting Retry-After), and total concurrency should be sized to the quota. Messages that keep failing go to a dead letter queue.
Change detection. Store a content hash per chunk. If a document is edited, only chunks whose hash changed need a new embedding call.
When to use it
- Any retrieval or semantic search feature whose corpus changes over time.
- Bulk onboarding of a large corpus (a new customer, a connected document library).
- Model migrations and re-indexing, which are bulk imports in disguise.
When not to
- A small, static corpus that fits in one batch job: embed it once offline and load the index.
- Managed ingestion that already does this for you (for example, search services with built-in indexers and integrated vectorisation) when its chunking and scheduling fit your needs.
- Data you should not copy: if documents must stay in their source system for compliance, consider querying that system’s own search instead of duplicating content into a vector store.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Small chunks | Precise matches, less noise in prompts | Lost context, more vectors to store and search |
| Large chunks | More context per hit | Blurred vectors, fewer relevant passages fit in a prompt |
| Queue-based ingestion | Fast uploads, burst absorption, retries | Freshness lag, another component to operate |
| More workers | Faster drain | Hits the embedding quota or store write limit; more 429s |
| Content hashing | Skip unchanged chunks, lower cost | Extra state to store and keep correct |
Alternatives
- Synchronous inline embedding: fine for low, steady volume and when the caller needs the document searchable immediately.
- Provider batch APIs: submit large embedding jobs asynchronously at lower cost and higher latency; good for backfills.
- Change data capture from the source database instead of webhooks or polling, so no change is missed.
- Hybrid without vectors: keyword search (BM25) needs no embedding pipeline at all and is a strong baseline.
Failure modes
- Bulk import outage: inline processing rejects uploads during a burst.
- Retry storms against the quota: many workers retrying 429s immediately keep the quota exhausted.
- Duplicate chunks: at-least-once delivery plus random ids returns the same passage several times per query.
- Stale or orphaned chunks: deleted documents or revoked permissions stay searchable because deletes were never propagated.
- Mixed model versions: part of the corpus embedded with an old model, part with a new one; similarity scores become meaningless.
- Poison documents: a file that crashes extraction is redelivered forever unless a dead letter queue catches it.
In production
Track backlog size and age (oldest message), throughput, 429 rate and cost per document. Record the embedding model name and version with every vector, or in the index name. Run re-embedding as a blue/green migration: dual-write new changes, backfill through the queue (or a batch API), compare retrieval quality on an evaluation set, switch reads with an alias, then delete the old index. In .NET, Microsoft.Extensions.AI’s IEmbeddingGenerator<string, Embedding<float>> abstracts the provider; a hosted BackgroundService or a function triggered by Azure Service Bus or a storage queue makes a straightforward worker.
Common misconceptions
- "More workers always ingest faster." Only until the embedding quota or the store’s write capacity is reached.
- "The queue guarantees each document is processed once." Most queues deliver at least once; the write must be idempotent.
- "Same dimension, same space." Two models with 1,024-dimensional output still produce incomparable vectors.
- "Chunking is a detail." Chunk size and boundaries change what retrieval can find more than most model choices do.
- "Indexing is done once." Documents change, get deleted and change permissions; the pipeline runs forever.
Interview angle
In a RAG or search design, interviewers want the ingestion side, not only the query side. Describe extract → chunk → embed → upsert, put a queue in front of workers, estimate backfill time (corpus ÷ throughput, bounded by the embedding quota), explain idempotent upserts and delete propagation, and how you would migrate to a new embedding model without downtime. Mention storing access-control metadata with chunks so retrieval can filter by permission.
Model assumptions
The simulation is a simplified model, not a benchmark. Document changes arrive randomly (Poisson). Processing one document (extract, chunk, one batched embedding call and the upsert) takes ~600 ms (lognormal, cv 0.3); the embedding model and vector store are scenery, and their calls are part of that time and drawn as scripted packets. Inline, the Ingest API has 8 workers and room for 8 waiting requests; with a queue it only enqueues (~15 ms). Each worker node has 4 slots. Embedding-API throttling is modelled as a 25% chance that processing fails; the message is not acknowledged and comes back after the visibility timeout. Duplicate processing happens when processing outlasts the visibility timeout. Chunk sizes, corpus size and backfill duration are illustrative.