๐Ÿง Agentic RAG Playground
GitHub
Open source ยท MIT license

Try Agentic RAG on your own documents

Upload PDFs, then search inside them or chat with them. The LLM decides by itself what to search, and shows the sources with every answer.

127.0.0.1:8000
Demo of the web UI: asking questions in Chat

What it does

A small but complete app, made for learning. Clone it, play with it, break it and improve it.

๐Ÿ“„

Upload PDFs

Text is read page by page and cut into chunks. Each chunk keeps its page number.

๐Ÿ”Ž

Search by meaning

Embeddings and pgvector find the closest chunks, even when the words are different.

๐Ÿค–

Agentic chat

The LLM has a search tool. It searches again with new words if the first results are weak.

๐Ÿณ

One command

Docker Compose starts the app and Postgres, and runs the migrations for you.

How it works

Three flows, and each one is simple.

Upload

  1. The PDF is saved and pypdf reads the text
  2. Text is cut into chunks, page by page
  3. LiteLLM makes an embedding for each chunk
  4. Document and chunks are saved in Postgres

Search

  1. The query is converted to an embedding
  2. pgvector finds the nearest chunks
  3. Chunks come back with file, page and score

Chat

  1. The agent asks the LLM, with a search tool
  2. The LLM searches, again if needed
  3. It answers only from the found chunks
  4. The answer comes back with its sources

Architecture

The web UI, the API, the database and the LLM provider, in one picture.

Click the picture to open it full size. Read more in the architecture doc below.

Quick start

Docker and an OpenAI API key are all that is needed.

git clone https://github.com/stackblogger/agentic-rag-playground.git
cd agentic-rag-playground
cp .env.example .env        # set OPENAI_API_KEY in it
docker compose up -d --build

Then open http://127.0.0.1:8000 for the web UI.

MCP Inspector

The MCP server can be tried in the MCP Inspector, a browser page to call the tools by hand.

npx @modelcontextprotocol/inspector -e PYTHONPATH=$PWD/src .venv/bin/python -m agentic_rag.mcp_server

Run it from the project folder, with Postgres running. Read more in the MCP doc below.

Click a picture to open it full size.

Built with

Python 3.11 FastAPI PostgreSQL + pgvector SQLAlchemy Alembic LiteLLM pypdf Docker Compose Tabler UI pytest

Docs

The same docs that are in the repo, shown here.

Loading...