A Retrieval-Augmented Generation (RAG) chatbot built with LangChain that supports conversational memory for follow-up questions. Features FastAPI backend and Streamlit frontend with document upload capabilities.
- Document Upload: Supports PDF, DOCX, HTML files (200MB limit per file)
- Conversational Memory: Maintains context for follow-up questions
- Multiple Models: Choose between GPT-4o-mini and other model options
- Vector Storage: Efficient document retrieval with ChromaDB
- Interactive API: FastAPI backend with Swagger documentation
- LangSmith Integration: Built-in tracing and monitoring
Create a .env file in the root with the following variables:
OPENAI_API_KEY=your_openai_api_key
LANGSMITH_API_KEY=your_langsmith_api_keyRAG-CHATBOT/
├── api/ # FastAPI backend server
│ ├── __pycache__/ # Python bytecode cache
│ ├── chroma_db/ # ChromaDB vector storage
│ ├── app.log # Logging file
│ ├── chroma_utils.py # ChromaDB utilities
│ ├── db_utils.py # Chat history & metadata DB logic
│ ├── langchain_utils.py # LangChain RAG pipeline
│ ├── main.py # FastAPI entry point
│ ├── pydantic_models.py # Request/response validation
│ └── rag_app.db # SQLite DB
├── app/ # Streamlit frontend
│ ├── __pycache__/ # Python bytecode cache
│ ├── api_utils.py # FastAPI client utils
│ ├── chat_interface.py # Chat UI
│ ├── sidebar.py # File upload & model switch
│ └── streamlit_app.py # Streamlit app
├── docs/ # Sample documents
├── documentation/ # Guides & screenshots
│ ├── screenshots/ # UI screenshots
│ ├── api_reference.md # API docs
│ └── user_guide.md # Manual
├── .env # Env variables
├── .gitignore # Git ignore rules
├── LICENSE # MIT License
├── notes.txt # Dev notes
├── README.md # This file
└── requirements.txt # Dependencies
- Python 3.9+
- OpenAI API Key
- LangSmith API Key (optional)
-
Clone the repository
git clone https://github.com/YOUR-USERNAME/rag-chatbot.git cd rag-chatbot -
Install dependencies
pip install -r requirements.txt
-
Configure environment
Create a
.envfile using the sample and add your keys:cp .env.example .env
-
Run the FastAPI backend
cd api uvicorn main:app --reload --port 8000 -
Run the Streamlit frontend
In a new terminal:
cd app streamlit run streamlit_app.py --server.port 8500 -
Access the application
- Streamlit UI: http://localhost:8500
- Swagger Docs: http://localhost:8000/docs
- Open the Streamlit UI
- Use the sidebar to upload PDF, DOCX, or HTML files
- Uploaded docs are indexed into ChromaDB
- Ask a question related to the uploaded content
- Ask follow-up questions — context is remembered
- Switch models via the sidebar dropdown
import requests
# Upload a document
files = {'file': open('document.pdf', 'rb')}
upload_res = requests.post('http://localhost:8000/upload-doc', files=files)
# Chat with the document
chat_payload = {
"message": "What is this document about?",
"session_id": "user123"
}
chat_res = requests.post('http://localhost:8000/chat', json=chat_payload)
print(chat_res.json())| Endpoint | Method | Description |
|---|---|---|
/chat |
POST | Chat with uploaded documents |
/upload-doc |
POST | Upload and index documents |
/list-docs |
GET | List all uploaded documents |
/delete-doc |
POST | Delete a specific document |
- Document Ingestion: Files are split into text chunks
- Embedding: Text is embedded using OpenAI embeddings
- Storage: Embeddings are stored in ChromaDB
- Retrieval: Relevant chunks are fetched for user queries
- Generation: LangChain passes context and query to LLM
- Memory: Session IDs preserve conversation history
-
Copy template and configure
cp .env.example .env
-
Edit
.envand add keys- Get your OpenAI API key from: https://platform.openai.com/account/api-keys
- (Optional) Get LangSmith API key from: https://smith.langchain.com/
-
Keep
.envprivate.envis included in.gitignoreto avoid committing secrets.
- OPENAI_API_KEY: Required for embeddings and completions
- LANGSMITH_API_KEY: For request tracing and logging
Screenshots are located in:
documentation/screenshots/
We welcome contributions!
- Fork the repository
- Create a feature branch
- Make your changes and commit
- Open a pull request
This project is licensed under the MIT License.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
...
See the full LICENSE file for more details.
- Built with LangChain
- Vector storage by ChromaDB
- UI by Streamlit
- Backend by FastAPI
- Observability via LangSmith
Have feedback, issues, or ideas?
- Open an issue on GitHub
- Submit a pull request
- Contact the maintainer (aryanmahawar205@gmail.com)