seriesaphoto/niko-bot-gradio
0
RAG Chatbot with LangGraph
A conversational RAG (Retrieval-Augmented Generation) chatbot built with LangGraph, Gemini, and ChromaDB.
Features
- Contextual conversation with memory of past interactions
- Query enhancement based on conversation history
- Document retrieval with dynamic strategies based on query type
- Document reranking for improved relevance
- First-person responses in the style of the knowledge base author
- References to source documents
Architecture
The application is structured in three main files:
app.py: Application entry point, configuration, and Gradio UIgraph.py: LangGraph state definition and node functionsrag_utils.py: RAG utilities including document retrieval, reranking, and formatting
Setup
- Clone the repository
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile with the following variables:
GOOGLE_API_KEY=your_google_api_key
CHROMA_PATH=./chromadb
DEBUG_LEVEL=1- Run the application:
python app.pyRequirements
See requirements.txt for the complete list of dependencies.
Environment Variables
GOOGLE_API_KEY: Your Google API key for accessing GeminiCHROMA_PATH: Path to your ChromaDB vector databaseDEBUG_LEVEL: Debug level (0 = no debug, 1 = basic debug info)
How It Works
- The chatbot processes user queries through a LangGraph workflow
- User queries are enhanced based on conversation history
- The enhanced query is used to retrieve relevant documents from ChromaDB
- Documents are reranked for relevance
- The top documents are used as context for generating a response
- The response is presented in the first person with references
Query Types
The system recognizes three types of queries:
- New topic: A fresh question unrelated to previous conversation
- Follow-up: A question that extends a previous topic
- Clarification: A request for more detail about a previous response
Each query type triggers different retrieval and enhancement strategies.
Extending
To extend the chatbot with new capabilities:
- Add new utility functions to
rag_utils.py - Create new node functions in
graph.py - Update the graph structure in
app.py
License
MIT License
