100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

LlamaIndex Cheat Sheet

LlamaIndex Cheat Sheet

Ingest, index, and query your own data for LLM apps using LlamaIndex's data connectors, indices, retrievers, and query engines.

2 PagesIntermediateFeb 10, 2026

Load Documents and Build an Index

Read a directory of files and build a vector index in a few lines.

python
from llama_index.core import SimpleDirectoryReader, VectorStoreIndexdocuments = SimpleDirectoryReader("./docs").load_data()index = VectorStoreIndex.from_documents(documents)index.storage_context.persist(persist_dir="./storage")

Query the Index

Turn an index into a query engine and ask natural-language questions over your data.

python
query_engine = index.as_query_engine(similarity_top_k=5, response_mode="compact")response = query_engine.query("What were Q3 revenue drivers?")print(response)for node in response.source_nodes:    print(node.score, node.node.metadata.get("file_name"))

Custom Node Parsing (Chunking)

Control how documents are split into nodes before embedding.

python
from llama_index.core.node_parser import SentenceSplittersplitter = SentenceSplitter(chunk_size=512, chunk_overlap=64)nodes = splitter.get_nodes_from_documents(documents)index = VectorStoreIndex(nodes)

Reload a Persisted Index

Restore a previously built index from disk without re-embedding everything.

python
from llama_index.core import StorageContext, load_index_from_storagestorage_context = StorageContext.from_defaults(persist_dir="./storage")index = load_index_from_storage(storage_context)query_engine = index.as_query_engine()

Index Types

Different index structures for different retrieval patterns.

  • VectorStoreIndex- similarity search over embeddings, the most common choice
  • SummaryIndex- linear scan, good for small corpora needing full-context summarization
  • TreeIndex- hierarchical summarization tree for large documents
  • KeywordTableIndex- keyword-based lookup, useful as a retrieval fallback
  • KnowledgeGraphIndex- extracts and queries entity-relation triples
  • as_chat_engine()- wraps a query engine with conversational memory
Pro Tip

Persist your storage_context after every index build — re-embedding a large corpus on every process restart is the single most common source of wasted API spend in LlamaIndex apps.

Was this cheat sheet helpful?

Explore Topics

#LlamaIndex#LlamaIndexCheatSheet#DataScience#Intermediate#Load#Documents#Build#Index#Databases#MachineLearning#CheatSheet#SkillVeris