█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/AI Agents/Code-First Agents/LlamaIndex: RAG Pipelines and Data Agents
65 minIntermediate

LlamaIndex: RAG Pipelines and Data Agents

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.

Prerequisites:LangGraph: Stateful Multi-Step Agent Graphs

Install + setup

  1. 1

    1. `pip install llama-index llama-index-llms-anthropic`

  2. 2

    2. Set ANTHROPIC_API_KEY.

  3. 3

    3. Make a folder `./data` and drop in 2–3 PDFs or text files.

Index and query documents

5 lines from PDFs to RAG.

python
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, Settings
from llama_index.llms.anthropic import Anthropic
Settings.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?'))

💡 What LlamaIndex does that LangChain doesn't (as easily)

Hierarchical retrieval, query routing across many indexes, structured-data agents (SQL + vector), and data connectors for 100+ sources (Notion, Slack, Google Drive, Postgres). RAG-as-a-product, not RAG-as-a-feature.

Multi-document data agent

Two indexes (e.g., HR docs + product docs), one agent routes between them.

python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.tools import QueryEngineTool, ToolMetadata
from llama_index.core.agent import ReActAgent
from llama_index.llms.anthropic import Anthropic
llm = 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?'))

Persistence

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.

Sign in to purchase
←LangGraph: Stateful Multi-Step Agent Graphs
Back to Code-First Agents
CrewAI: Multi-Agent Teams with Roles and Tasks→