Loaders and Nodes
An LLM never sees “files on disk”—only the text you place in context. LlamaIndex splits ingestion into Load (Document) → Transform (chunk to Node, metadata, embeddings) → Index / Store. Same idea as this site’s RAG tutorial, different class names.
Document vs Node
Chunks too small: fragmented hits, missing context. Too large: noise in the prompt, window overflow. Start around chunk_size=512 with modest overlap, then inspect source_nodes on real questions.
Hand-written document:
SimpleDirectoryReader
The starter reader. It understands common Markdown, PDF, Word, PPT, and some media. Top-level only unless recursive=True.
Or pass input_files=["./data/a.pdf"]. Production often uses a LlamaHub reader (database, Notion, S3) instead of one recursive folder scan.
Confirm the package name on LlamaHub (e.g. llama-index-readers-database).
Splitting into Nodes
VectorStoreIndex.from_documents(documents) chunks using global Settings (or a transformations list). To control size:
Or a declarative IngestionPipeline (split, extract titles, embed):
Build Nodes yourself and skip Document splitting:
Why metadata matters
After retrieval you often filter by team, date, or file type. Write those fields at ingest time; query-time metadata filters are covered in Retrieval. Automatic extractors such as TitleExtractor cost extra LLM calls—fine for offline batches, not for every user question.
Practice:
- Prefer sentence/paragraph splits; do not cut inside words
- Scanned PDFs need OCR or LlamaParse; otherwise the reader returns garbage
- The same embedding model must be used at index time and query time