Indexes
An index organizes Nodes so queries can fetch them quickly. The workhorse is VectorStoreIndex: each Node has an embedding; queries run similarity search. Other indexes (summary, keyword, tree, property graph) serve other access patterns. Master the vector index first, then extend from the official module guides.
This site’s RAG course covers why you index. This chapter is how LlamaIndex builds, persists, and incrementally inserts.
VectorStoreIndex.from_documents
Under the hood (overridable via Settings / transformations / storage_context):
- Split Documents into Nodes
- Embed with
Settings.embed_model(starter OpenAI embeddings; historicallytext-embedding-ada-002) - Write into the
StorageContextvector store (in-memorySimpleVectorStoreby default)
Pin splitter and LLM (gpt-4o-mini in examples; follow current docs):
From existing Nodes: VectorStoreIndex(nodes). Vectors already in an external DB: VectorStoreIndex.from_vector_store(vector_store) (Vector Stores).
Persist to disk (default storage)
An in-memory index dies with the process. Embeddings are slow and costly, so persist:
StorageContext holds docstore / index store / vector store. If you customized embeddings or transformations, restore the same Settings on load.
Incremental insert:
Other index types (awareness)
Do not start by composing five indexes. Stabilize vector search, then add keyword or graph based on evals. Combine at query / retrieval time with a router or fused retriever instead of copying every corpus five ways.
An index is not your system of record
Indexes optimize which context the LLM sees. They do not replace Postgres business tables. Filters, ACLs, and transactions stay in the source system; LlamaIndex picks passages. Simple tenancy: one collection / persist dir per tenant, or tenant_id in metadata plus query-time filters.
FAQ
Double bills from repeating from_documents?
If storage/ exists, load_index_from_storage—do not rebuild every boot.
Quality collapsed after changing the embedding model?
Vectors live in different spaces. Wipe storage and re-index fully.
Stuck while embedding?
Check network and keys; use show_progress=True. Large jobs: ingestion pipeline + batch writes into an external vector DB.