Module 1 · LlamaIndex architecture
Documents, Nodes and Indexes
6 min read
A language model knows neither your products, nor your procedures, nor your contracts. For it to answer from your data, you must show that data to it at the right moment, in the right form: that is the whole point of RAG (Retrieval-Augmented Generation). LlamaIndex is the framework specialized in this chain, from reading files to a sourced answer. This lesson presents its three core objects — Document, Node and Index — and the course's running project.
Quality starts with the data
Most teams disappointed by RAG blame the model. Most often, the problem is upstream: a badly read PDF, a table flattened into gibberish, a passage cut mid-sentence, a missing metadata field that prevents filtering. An excellent model cannot answer correctly from a bad excerpt.
| Step | What can go wrong | Module |
|---|---|---|
| Reading | Tables and columns mixed up, repeated headers, text in images lost | 1 and 2 |
| Chunking | A rule split in two, a passage without its heading | 2 |
| Indexing | The wrong index type for the type of question | 3 |
| Retrieval and answering | Off-topic passages, unsourced or invented answer | 4 |
| Operations | Stale index, no quality measurement | 5 |
This course follows that chain in order, on a complete project.
Document: the source
A Document represents a source: a file, a web page, a database row. It contains text, metadata and an identifier.
from llama_index.core import Document
doc = Document(
text="Vous disposez de 30 jours après la livraison pour retourner un article…",
metadata={"source": "policies/returns.md", "collection": "policies"},
id_="policies/returns.md",
)
Metadata is not a detail: it is used to filter (search only in product sheets), to cite (show the source of an answer) and to enrich the context given to the model. The identifier is the key to incremental ingestion (lesson 2.4): a modified document must keep the same identifier to replace its previous version.
Node: the indexable chunk
A whole document is rarely the right unit of retrieval: too long to fit in the context, too heterogeneous to be well represented by a single vector. LlamaIndex splits it into nodes (TextNode), the units actually indexed and retrieved.
from llama_index.core.node_parser import SentenceSplitter
nodes = SentenceSplitter(chunk_size=512, chunk_overlap=64).get_nodes_from_documents([doc])
node = nodes[0]
node.text # the passage
node.metadata # inherited from the document (+ what transformations add)
node.ref_doc_id # the identifier of the source document
node.relationships # links: source document, previous node, next node, parent, children
Each node inherits the metadata of its document and keeps a link to it. Previous/next and parent/child relationships enable advanced strategies: widening a retrieved passage to its neighbors, or moving up to a broader section (lesson 2.2).
Index: the retrieval structure
An index organizes nodes to retrieve them. LlamaIndex offers several, each suited to a type of question:
| Index | Organization | Typical question |
|---|---|---|
VectorStoreIndex | One vector (embedding) per node; similarity search | "What is the return window?" |
SummaryIndex | A plain list; reads everything | "Summarize this document" |
DocumentSummaryIndex | One summary per document | "Which policy covers furniture?" |
PropertyGraphIndex | A graph of entities and relationships | "Who makes this chair, and what is it compatible with?" |
On top of an index you build engines: a retriever (finds nodes), a query engine (finds, then writes an answer), a chat engine (converses with memory). Module 4 is dedicated to them.
The bare minimum, in five lines
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
documents = SimpleDirectoryReader("data", recursive=True).load_data()
index = VectorStoreIndex.from_documents(documents)
response = index.as_query_engine().query("Combien coûte la livraison express ?")
print(response, [n.node.metadata["file_name"] for n in response.source_nodes])
These five lines read a folder, split the documents, compute embeddings, build an in-memory index, retrieve relevant passages and write an answer. It is LlamaIndex's "hello world". The rest of the course consists of replacing each default with a deliberate choice: which reader, which chunking, which metadata, which vector database, which engine, which evaluation.
The running project: Lumen
Lumen is the internal knowledge base of the support team at Nimbus, a fictional online shop (the same one as in the LangGraph course). Support agents ask it questions; it answers citing its sources. Its corpus is deliberately varied, as in a real company:
| Source | Format | Challenge |
|---|---|---|
| Product sheets | Markdown with a metadata header | Keep the metadata, split by section |
| Policies (returns, warranty, shipping) | Markdown | Precise questions and global questions |
| Assembly manual | PDF with a parts table | Read a PDF correctly |
| FAQ | CSV | One row = one standalone entry |
| Catalog | JSON (products, suppliers, compatibilities) | Relationships, not text |
The corpus is in French. The multilingual embedding models used in the course let you query the base in any language.
Throughout the modules, Lumen gains an incremental ingestion pipeline, three indexes (vector, summaries, graph), a router that picks the index based on the question, a corrective RAG workflow, a tool-using agent, structured extraction, quantified evaluation and an HTTP service. The complete code is provided, with 27 tests that run without an API key thanks to a fake model and fake embeddings:
cd lumen-kb
pip install -e ".[dev,api]"
LUMEN_FAKE_LLM=1 pytest # on Windows: $env:LUMEN_FAKE_LLM="1"; pytest
The course is based on llama-index-core 0.14. LlamaIndex moves fast: when an API has changed recently, the course says so.
Key takeaways
- The quality of a RAG application is decided first in the data: reading, chunking, metadata.
- Document = a source (text + metadata + stable identifier); Node = an indexable chunk, which inherits metadata and keeps its links.
- An index organizes nodes; vector, summaries and graph answer different questions.
- Engines (retriever, query engine, chat engine) are built on indexes.
- Defaults work in five lines; production requires a deliberate choice at every step.
Practice
- Run
examples/01_documents_nodes.pyand look at the identifiers, metadata and nodes of a document. - Build the "five lines" index on the companion code's
data/folder, and ask three questions: which ones are handled well, which ones aren't? - For a corpus in your company, fill in the "source, format, challenge" table above.