Skip to main content
This guide serves as the foundation for a workshop on Retrieval-Augmented Generation (RAG). You will learn how to build a RAG system using cycls, chromadb, and openai, starting with a basic implementation and evolving it into an “Agentic” RAG that handles file uploads and dynamic visualization tools. You will learn how to:
  • Build a Basic RAG system with static documents.
  • Create an Attachment Handler to process user uploads (PDFs, etc.).
  • Implement an Agentic RAG that indexes content dynamically.
  • Add Tooling capabilities to generate interactive charts.

Prerequisites

  • Python 3.8+
  • cycls package installed
  • OpenAI API Key
  • Docker installed (for local testing)

Part 1: The Basic RAG

We start by creating a simple RAG system. This agent will have a pre-defined “knowledge base” hardcoded into it. It demonstrates the core loop of RAG: Embed -> Store -> Retrieve -> Generate. Create a file named basicrag.py.

Step 1.1: Setup and Dependencies

We initialize the agent with chromadb (vector database) and openai (embeddings and generation).

Step 1.2: The Core Logic

The handler function performs the RAG operations. Note that in this basic version, documents are hardcoded.
Why this is “Basic”:
  • The knowledge base is static and ephemeral (re-created on every run).
  • It cannot handle user files or new data.
  • It strictly retrieves text; it doesn’t do anything with it other than display it.

Part 2: Evolving to Agentic RAG

Now we move to agenticrag.py. An “Agentic” RAG doesn’t just look up info; it interacts with the environment. It will:
  1. Read files you upload (PDFs, etc.).
  2. Index them on the fly.
  3. Decide whether to answer with text or generate a visualization (Tool Use).

Helper Module: attach.py

To keep our agent clean, we move complex file handling to attach.py. This module handles:
  • Downloading files from Cycls URLs.
  • Extracting text from PDFs (PyPDF2).
  • Formatting messages for the LLM.
Ensure attach.py is in the same directory.

Step 2.1: Agent Configuration

We need more dependencies now, including PyPDF2 for parsing and httpx for downloading.

Step 2.2: Dynamic Indexing

Instead of hardcoded strings, we process the incoming message to find file content.

Step 2.3: Tool Use (Chart Generation)

This is what makes it “Agentic”. The model evaluates the user query. If the user asks for a “chart” or “plot”, it switches logic paths to generate HTML instead of just text.

Key Differences Summary

Full Code Reference

1. Basic RAG (basicrag.py)

2. Agentic RAG (agenticrag.py)

3. Attachment Handler (attach.py)