This repo hosts the code implementation of an end-to-end agentic RAG system.
async web crawler
ꜜ
ann index
ꜜ
retrieve/rerank
ꜜ
MCP tool serve
ꜜ
FastAPI chat (streaming/sync)
I wrote this agentic RAG system to learn and get hands on experience on:
- asynchronous processing & concurrency
- web crawler
- how to handle
robots.txtproperly, by using urllib.robotparser - html content parsing via BeautifulSoup or trafilatura
- discover links and keep track of links crawled, based on http status code
- detect and filter irrelevant
mime_types - handle retry and backoff
- write file to disk
- a naive BFS solution, and a
asyncioqueue + worker approach
- how to handle
- RAG (Retrieval-Augmented Generation)
- use ChromaDB to build a local ANN index, by Sentence Transformer's text embedding model
- indexer to index crawled contents stored locally
- retriever to retrieve
top_kindexed documents that are close to user's input in the embedding space, based on cosine similarity - a simple re-ranker to re-rank retrieved documents for better result accuracy
- local LLM hosting
- use ollama to host
qwen2.5:7b, and optionally,gemma4:26b
- use ollama to host
- agent
- a simple agent class to establish connections with local hosted LLM, using OpenAI python SDK
- configure custom tools
fetch_url
- ReAct loop to trigger/handle tool usages
- MCP server
- understand what tool means in mcp/agent
- use MCP python library to build a simple MCP server locally
- MCP client that establishes connections to locally hosted MCP server
- FastAPI based API server for streaming chat UI
- expose
/chatand/chat/streamAPI - use pydantic
BaseModelto define JSON parsable request/response
- expose
This repo uses uv to manage python dependencies.
Please refer to each sub folder's readme file for additional contexts and commands to run components locally.
Claude Opus 4.8 was used for code review and constructing Git commit messages.
To customize the pipeline, simply swap the crawl seed (I use Books to Scrape to safely crawl the internet) with other sources you may want, change to a larger model, such as gemma-4-26B-A4B, to better suit your hardware capacity.
- make each component configurable
- dockerize
- organize blog posts