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,
    )
StepRoleLesson
MarkdownNodeParserOne node per section, with the heading path (header_path)2.2
SentenceSplitterRe-splits sections that are too long, without cutting a sentence2.2
SkuTaggerCustom extractor: adds the product references cited in the passage2.3
QuestionsAnsweredExtractorOptional: questions the passage answers (one LLM call per node)2.3
Embedding modelComputes each node's vector — it's a transformation too1.2
vector_storeDestination: embedded nodes are written to it3.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:

SituationBehavior
Unknown documentProcessed and inserted
Same identifier, same hashSkipped: nothing changed
Same identifier, different hashProcessed; 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:

StrategyUse
UPSERTS (default)Adds and updates; never deletes
UPSERTS_AND_DELETESyncs the base with the corpus: a removed document disappears from the index
DUPLICATES_ONLYOnly 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 IngestionPipeline chains 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_DELETE also 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

  1. Run examples/02_ingestion_pipeline.py, then modify it to delete a file between two ingestions: how many nodes are left in the base?
  2. Switch the strategy to UPSERTS and repeat the experiment: what happens?
  3. Add QuestionsAnsweredExtractor (option with_llm_extractors=True) and measure, with a real model, the time and number of calls of the first ingestion, then of the second.

Resources