This project lets you chat with your own documents using:
- LangChain for orchestration
- Chroma as the vector database
- OpenAI API for LLMs and embeddings
- Gradio for the user interface
You upload your documents into a knowledge base folder, the system indexes them, and then you can ask questions in natural language. The chatbot retrieves the most relevant chunks from your docs and answers using AI.
- Chat directly with your own documents
- Uses RAG (Retrieval-Augmented Generation) for accurate answers
- Interactive Gradio chat UI
- Document ingestion and chunking with metadata
- Configurable via
.env(no keys in code)
.
├── config.py # API keys, models, system message
├── gradio_rag_chatbot.py # Gradio web chatbot
├── rag_chatbot.py # Console chatbot runner
├── helper.py # Document loading + chunking
├── requirements.txt # Python dependencies
└── knowledge-base/ # 📌 Upload your documents here
All documents must go inside the knowledge-base/ folder.
- Supported format: Markdown (
.md) - You can organize documents into subfolders. Each subfolder name becomes the
doc_typemetadata.
Example:
knowledge-base/
├── policies/
│ ├── hr_policy.md
│ └── vacation_rules.md
├── products/
│ ├── productA_specs.md
│ └── productB_specs.md
The chatbot will automatically:
- Read all
.mdfiles insideknowledge-base/ - Split them into chunks
- Store them in the Chroma vectorstore
- Use them to answer your questions
-
Clone the repo
git clone https://github.com/Walid-Ahmed/langchain-docs-chatbot.git cd langchain-docs-chatbot -
Create a virtual environment
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up
.envfile Create a.envfile in the project root:# Required OPENAI_API_KEY=your_openai_api_key_here # Optional (used if you want weather + image generation features) OPENWEATHER_API_KEY=your_openweather_api_key_here
Never commit your .env file to GitHub (it contains your private API keys).
Make sure .env is included in your .gitignore file:
# .gitignore
.env
Run:
python gradio_rag_chatbot.pyOpen the link (default: http://127.0.0.1:7860) and start chatting with your documents.
Run:
python rag_chatbot.pyAsk a single query in the terminal against your knowledge base.
If your knowledge-base/ folder contains:
knowledge-base/
└── policies/
└── hr_policy.md
You can ask in the chatbot:
"What are the vacation rules in our HR policy?"
The system will retrieve the relevant chunk from hr_policy.md and answer conversationally.
See requirements.txt.