After this lesson, you will be able to: Index documents in a vector store, build a RAG pipeline, and create a data agent that queries multiple sources and synthesises answers.
LlamaIndex specialises in data-heavy agents, long documents, structured tables, knowledge graphs. Where LangChain is generalist, LlamaIndex is the RAG specialist. This lesson indexes documents, queries them, and builds a multi-source data agent.
1. `pip install llama-index llama-index-llms-anthropic`
2. Set ANTHROPIC_API_KEY.
3. Make a folder `./data` and drop in 2–3 PDFs or text files.
5 lines from PDFs to RAG.
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settingsfrom llama_index.llms.anthropic import AnthropicSettings.llm = Anthropic(model='claude-sonnet-4-6')documents = SimpleDirectoryReader('./data').load_data()index = VectorStoreIndex.from_documents(documents)query_engine = index.as_query_engine()print(query_engine.query('What is the main argument across these documents?'))
Two indexes (e.g., HR docs + product docs), one agent routes between them.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReaderfrom llama_index.core.tools import QueryEngineTool, ToolMetadatafrom llama_index.core.agent import ReActAgentfrom llama_index.llms.anthropic import Anthropicllm = Anthropic(model='claude-sonnet-4-6')hr_index = VectorStoreIndex.from_documents(SimpleDirectoryReader('./hr_docs').load_data())prod_index = VectorStoreIndex.from_documents(SimpleDirectoryReader('./product_docs').load_data())tools = [QueryEngineTool(query_engine=hr_index.as_query_engine(),metadata=ToolMetadata(name='hr_docs', description='HR policies, benefits, time off.')),QueryEngineTool(query_engine=prod_index.as_query_engine(),metadata=ToolMetadata(name='product_docs', description='Product specs, features, roadmap.')),]agent = ReActAgent.from_tools(tools, llm=llm, verbose=True)print(agent.chat('How many vacation days do I get and which features ship next quarter?'))
By default, the index lives in memory. For production: use Chroma, Qdrant, Weaviate, or Pinecone storage. `index.storage_context.persist('./store')` saves to disk; `load_index_from_storage('./store')` reloads. Saves you from re-embedding every run.
Sign in and purchase access to unlock this lesson.