This repository serves as a didactic reference for implementing a production-ready RAG (Retrieval-Augmented Generation) agent. It demonstrates how to orchestrate complex LLM logic using LangGraph and serve it as a high-performance API via FastAPI.
The project is designed to show students the "Life of a Query":
- API Layer (FastAPI): Receives the user request and manages the asynchronous execution.
- Orchestration (LangGraph): Manages the state and logic flow (e.g., should I retrieve documents?, is the context sufficient?).
- RAG Logic (LangChain): Handles document loading, splitting, embedding, and vector search.
- State Management: Using LangGraph to maintain context across the agentic workflow.
- Vector Embeddings: How documents are transformed and stored for semantic search.
- RESTful AI: Serving model outputs through standard HTTP endpoints.
| Component | Technology | Role |
|---|---|---|
| Framework | LangChain | RAG primitives and LLM integration. |
| Orchestration | LangGraph | Cyclic/Acyclic graph-based agent logic. |
| API | FastAPI | Asynchronous web server and OpenAPI documentation. |
| Vector Store | Chroma | Local vector database for document retrieval. |
Install UV
curl -LsSf https://astral.sh/uv/install.sh | shClone the repo and install dependencies:
git clone https://github.com/rikDei/simple_rag.git
cd simple_rag
uv syncCreate a .env file with your credentials:
NVIDIA_API_KEY=****
TAVILY_API_KEY=****Loading the document into the VectorDB
python -m embed_documents.pyStart the FastAPI server:
fastapi run app:appOnce running, you can access the interactive Swagger UI at: http://127.0.0.1:8000/docs.
├── app/
│ ├── __init__.py # FastAPI entry point
│ ├── router.py # Router to handle HTTP Requests
│ └── validators.py # Pydantic BaseModel to validate user input
├── agent/ # All the agent logic
│ ├── __init__.py # Initialize model instance
│ └── agent.py # Langgraph agent
├── embeddings/ # Embedding model
│ └── __init__.py # Initialize instance
├── tools/ # Custom tools
│ ├── __init__.py # Lists tools
│ ├── vector_store.py # Tools to interact with the vector store
│ └── web_search.py # Tavily built in tool
├── embed_documents.py # Python script to load the documents inside the vector DB
└── config.py # Gets all the environment variables
- Modify the Prompt: Look at
prompts/chat_bot.mdand see how changing the System Message affects the agent's behavior. - Add a Node: Try adding a "Tools" node in
toolsmodule to allow the agent more capabilities.
Created for educational purposes by rikDei