Module 1 · LlamaIndex architecture
The end-to-end ingestion pipeline
5 min read
Between raw documents and a queryable base lies a series of transformations: split, enrich, embed, store. LlamaIndex's IngestionPipeline chains them, and adds what makes the difference in production: a cache so nothing is ever computed twice, and a docstore so only new or modified documents are processed. This lesson builds Lumen's pipeline end to end; module 2 details each step.
A series of transformations
A transformation receives a list of nodes and returns a list of nodes. The pipeline applies them in order:
from llama_index.core.ingestion import DocstoreStrategy, IngestionCache, IngestionPipeline
from llama_index.core.node_parser import MarkdownNodeParser, SentenceSplitter
from llama_index.core.storage.docstore import SimpleDocumentStore
def transformations(with_llm_extractors: bool = False) -> list[TransformComponent]:
steps: list[TransformComponent] = [
MarkdownNodeParser(), # découpe selon les titres et garde le chemin des titres en métadonnée
SentenceSplitter(chunk_size=config.CHUNK_SIZE, chunk_overlap=config.CHUNK_OVERLAP),
SkuTagger(),
]
if with_llm_extractors:
steps.append(QuestionsAnsweredExtractor(questions=2, llm=models.fast_llm()))
steps.append(models.embed_model())
return steps
def build_pipeline(vector_store=None, with_llm_extractors: bool = False) -> IngestionPipeline:
return IngestionPipeline(
transformations=transformations(with_llm_extractors),
vector_store=vector_store,
docstore=SimpleDocumentStore(),
cache=IngestionCache(),
docstore_strategy=DocstoreStrategy.UPSERTS_AND_DELETE,
)
| Step | Role | Lesson |
|---|---|---|
MarkdownNodeParser | One node per section, with the heading path (header_path) | 2.2 |
SentenceSplitter | Re-splits sections that are too long, without cutting a sentence | 2.2 |
SkuTagger | Custom extractor: adds the product references cited in the passage | 2.3 |
QuestionsAnsweredExtractor | Optional: questions the passage answers (one LLM call per node) | 2.3 |
| Embedding model | Computes each node's vector — it's a transformation too | 1.2 |
vector_store | Destination: embedded nodes are written to it | 3.1 |
The order matters: split before enriching (metadata is computed per node) and embed last (so that the embedding accounts for the added metadata).
Running the pipeline
pipeline = build_pipeline(vector_store)
nodes = await pipeline.arun(documents=readers.load_all())
Lumen uses the async version, arun. Modern LlamaIndex is largely asynchronous — workflows and agents are by nature — and Lumen is async end to end; lesson 3.1 explains why this choice is required with Qdrant in embedded mode. arun also lets transformations that make network calls run in parallel.
The docstore: only process what changed
The docstore remembers, for each document, a hash of its content. On each run, the pipeline compares:
| Situation | Behavior |
|---|---|
| Unknown document | Processed and inserted |
| Same identifier, same hash | Skipped: nothing changed |
| Same identifier, different hash | Processed; its old nodes are replaced |
Identifier gone (with UPSERTS_AND_DELETE) | Its nodes are deleted from the vector database |
The examples/02_ingestion_pipeline.py example shows it:
1re ingestion : 40 nœuds créés
2e ingestion, sans changement : 0 nœud retraité
3e ingestion, un fichier modifié : 4 nœuds retraités, issus de ['policies/shipping.md']
Three strategies exist:
| Strategy | Use |
|---|---|
UPSERTS (default) | Adds and updates; never deletes |
UPSERTS_AND_DELETE | Syncs the base with the corpus: a removed document disappears from the index |
DUPLICATES_ONLY | Only drops exact duplicates; for append-only feeds |
Lumen picks UPSERTS_AND_DELETE: a withdrawn policy must never again be the source of an answer. This strategy assumes you provide the whole corpus on every run: a document missing from the list is considered deleted.
The cache: never recompute
The cache stores the result of each transformation for a given set of nodes. If you rerun a pipeline on data already seen — after a crash, in another environment, after adding a step at the end of the chain — the expensive steps (embeddings, LLM extractors) are not redone.
Docstore and cache can be saved and reloaded:
pipeline.persist("storage/pipeline") # writes docstore.json and the cache
pipeline.load("storage/pipeline") # at the next startup
In production, on several servers, put them in shared storage: LlamaIndex provides docstores and caches backed by Redis, MongoDB or PostgreSQL, interchangeable with the local versions.
The pipeline, single entry point
A simple architectural rule avoids many inconsistencies: everything that enters the index goes through the pipeline. No direct insertion "to go faster": it would bypass the docstore (the document would be inserted twice at the next refresh), skip metadata, or be embedded with another model. In Lumen, building the base and refreshing it (KnowledgeBase.refresh, route /admin/refresh) call the same pipeline.
Key takeaways
- The
IngestionPipelinechains splitting, enrichment, embedding and writing to the vector database.- Split first, enrich next, embed last.
- The docstore compares hashes: only new or modified documents are processed;
UPSERTS_AND_DELETEalso deletes removed documents.- The cache avoids recomputing embeddings and extractions; docstore and cache can be persisted.
- Everything that enters the index goes through the pipeline.
Practice
- Run
examples/02_ingestion_pipeline.py, then modify it to delete a file between two ingestions: how many nodes are left in the base? - Switch the strategy to
UPSERTSand repeat the experiment: what happens? - Add
QuestionsAnsweredExtractor(optionwith_llm_extractors=True) and measure, with a real model, the time and number of calls of the first ingestion, then of the second.