GuideIntermediate

Production Rag And Document Ingestion

This guide builds the data plumbing of a production RAG system on top of real Reservo documents — thirteen documents across three raw formats: markdown, HTML, and a deliberately "dirty" `.txt` file that simulates a PDF/OCR extraction — and wires it up to an agent as just another tool. It covers the full ingestion pipeline: parsing each raw format, cleaning real artifacts (repeated headers/footers, broken hyphenation, page breaks), chunking with actual criteria, and attaching the metadata needed to cite the source later. Those chunks get indexed with a BM25 index built from scratch ($0, deterministic, always labeled as real lexical retrieval — the same algorithm behind Elasticsearch/OpenSearch — and never as semantic search), and search is exposed as the `search_docs(query, k)` tool that the agent calls from inside its own loop: agentic retrieval, not a monolithic single-pass RAG pipeline, with the agent deciding when to search and combining that search with Reservo's business tools in the same turn. The guide also covers incremental, idempotent ingestion (re-ingesting changed documents without duplicating them, detecting additions/changes/deletions by content hash), evaluating retrieval quality with a fixed ground-truth query set and form-based metrics — recall@k, precision@k, never a semantic judge — and operating the system: citing sources, handling zero results without hallucinating, filtering irrelevant chunks, and estimating pipeline cost. All the engineering actually runs on Python 3.14 and `numpy`; the LLM's decision is treated as a concept. It doesn't teach embedding theory or build a vector database — that's named as the next step in AI Engineering.

64
lessons
8
modules
English · Spanish
available in
Yes
certificate
Free
access
NIEVA

Outcomes

What you'll be able to do

  • Parse raw document formats — HTML, markdown, "dirty" text like a PDF/OCR extraction — and clean real artifacts: repeated headers and footers, broken hyphenation, page breaks
  • Apply chunking with actual criteria (fixed size, structure-aware, sentence-bounded) and understand the trade-off between small chunks (precise, no context) and large ones (contextual, diluted relevance)
  • Attach the metadata each chunk needs to cite its source later: source document, title, section, and position
  • Build a BM25 search index from scratch — inverted index, term frequency, IDF, scoring — and honestly recognize its limit against semantic search (it doesn't capture synonyms or paraphrasing)
  • Expose search as a tool (`search_docs`) with its JSON Schema contract, pluggable into an agent's loop exactly like any other tool
  • Implement agentic retrieval: decide when it's worth calling `search_docs`, rephrase a query that didn't return useful results, and combine it with other tools in the same turn
  • Build incremental, idempotent ingestion: re-ingest the corpus without duplicating it, detect new, modified, or deleted documents by content hash, and update only what changed
  • Evaluate retrieval quality with a fixed ground-truth query set and deterministic metrics — recall@k, precision@k — including a trap case that exposes the real limit of lexical search
  • Operate the system in production: cite the source in every answer, handle zero results without making things up, filter irrelevant chunks with a score threshold, and estimate pipeline cost
  • Assemble the complete pipeline — ingestion, index, tool, agentic retrieval, evaluation — into a document search tool ready for a Reservo agent to use

Before you start

What you need to bring

It's for you if...

  • Developers who already have an agent with tool calling and need to give it reliable access to real documents: policies, FAQs, manuals
  • Backend or AI engineers responsible for ingesting "dirty" documents (PDFs, HTML, extracted text) for a production search system
  • Anyone who needs to understand BM25 and production-grade lexical retrieval before jumping to embeddings and vector databases
  • Developers who want to learn agentic retrieval — the agent decides when to search — instead of a monolithic, single-pass RAG pipeline

Requirements and materials

  • Agent Fundamentals and Tool Calling Guide completed (or equivalent: a tool's contract, the `tool_use`/`tool_result` protocol)
  • Basic to intermediate Python: regular expressions, `dataclasses`, a first idea of `sqlite3`
  • Python 3.14 with its standard library and `numpy` (already installed); no API key, internet connection, or embedding/vector database libraries required

Content

The syllabus, module by module

Open any of them to see its lessons.

Common questions

What people usually ask

Start whenever you like

Reviews

What students say

These reviews are from enrolled students who completed at least 50% of the course. We moderate reviews only on content grounds (spam, offensive language, personal data), never for being critical or negative.

No approved reviews yet.

Be the first to share your experience!