Module 01 — Agentic RAG

From a fixed RAG pipeline to an LLM-driven agentic loop

Key Concepts

Core

RAG Architecture

Three independent, swappable components: Search → Prompt Builder → LLM. Your model is only as good as your retrieval.

retrievalgroundinghallucination fix
Core

Search with minsearch

Lightweight in-memory search. Text fields are ranked by TF-IDF; keyword fields are exact-match filters only.

text_fieldskeyword_fieldsfilter_dict
Core

Prompt Engineering

Fixed instructions separate from dynamic context. Instructions reduce hallucinations by constraining the LLM to retrieved content.

instructionscontexttemplate
Core

Chunking

Sliding window splits long pages into overlapping pieces. Overlap ensures passages near boundaries aren't lost.

size=2000step=1000overlap
Agentic

Function Calling

LLM requests tool execution via JSON schemas. It can retry with reformulated queries — behaviour you didn't explicitly program.

tool schemafunction_call
Agentic

The Agentic Loop

while True: call LLM → if function_call → execute → loop. Stops when the model returns no tool calls. Instructions, tools, and memory are the three pillars.

loopmemorytool dispatch
Agentic

Agent Frameworks

toyaikit auto-generates tool schemas from type hints and docstrings. Same pattern across OpenAI SDK, PydanticAI, LangChain.

toyaikitschema generation
Production

Data Ingestion

Separate ingestion from querying. Ingest once to persistent storage; query as often as needed. Avoids re-indexing on every restart.

separation of concernssqlitesearch

RAG vs Agentic RAG

Plain RAG

User Query
    ↓
  Search (once, fixed)
    ↓
Build Prompt
    ↓
   LLM
    ↓
  Answer

Agentic RAG

User Query
    ↓
   LLM ──→ Search
    ↑          ↓
  results ←────┘
    ↓
Final Answer