Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎓 Simple RAG: FastAPI + LangGraph + LangChain

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.


🏛️ Architecture & Workflow

The project is designed to show students the "Life of a Query":

  1. API Layer (FastAPI): Receives the user request and manages the asynchronous execution.
  2. Orchestration (LangGraph): Manages the state and logic flow (e.g., should I retrieve documents?, is the context sufficient?).
  3. RAG Logic (LangChain): Handles document loading, splitting, embedding, and vector search.

Key Educational Concepts Included:

  • 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.

🛠️ Tech Stack

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.

🚀 Getting Started

1. Environment Setup

Install UV

curl -LsSf https://astral.sh/uv/install.sh | sh

Clone the repo and install dependencies:

git clone https://github.com/rikDei/simple_rag.git
cd simple_rag
uv sync

2. Configuration

Create a .env file with your credentials:

NVIDIA_API_KEY=****
TAVILY_API_KEY=****

3. Running the API

Loading the document into the VectorDB

python -m embed_documents.py

4. Running the API

Start the FastAPI server:

fastapi run app:app

Once running, you can access the interactive Swagger UI at: http://127.0.0.1:8000/docs.


📂 Project Structure

├── 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

🎓 For Students: Things to Explore

  • Modify the Prompt: Look at prompts/chat_bot.md and see how changing the System Message affects the agent's behavior.
  • Add a Node: Try adding a "Tools" node in tools module to allow the agent more capabilities.

Created for educational purposes by rikDei

About

Simple RAG Agent implementation for educational purpose.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages