A fully custom chatbot built with Agentic RAG (Retrieval-Augmented Generation), combining OpenAI models with a local knowledge base for accurate, context-aware, and explainable responses. Features a lightweight, dependency-free frontend and a streamlined FastAPI backend for complete control and simplicity.
- Pure HTML/CSS/JavaScript frontend with no external dependencies
- FastAPI backend with OpenAI integration
- Agentic RAG implementation with:
- Context retrieval using embeddings and cosine similarity
- Step-by-step reasoning with Chain of Thought
- Function calling for dynamic context retrieval
- Comprehensive error handling and logging
- Type-safe implementation with Python type hints
- Configurable through environment variables
agentic_rag/
├── backend/
│ ├── embeddings.py # Embedding and similarity functions
│ ├── rag_engine.py # Core RAG implementation
│ └── server.py # FastAPI server
├── frontend/
│ └── index.html # Web interface
├── requirements.txt # Python dependencies
├── .env.sample # Sample environment variables
└── README.md # Documentation
- Python 3.11 or higher
- OpenAI API key
- Git (for version control)
- Clone the repository:
git clone https://github.com/AndrewNgo-ini/agentic_rag.git
cd agentic_rag- Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install Python dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.sample .envThen edit .env with your configuration:
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gpt-4o-mini # or another compatible model
OPENAI_EMBEDDING_MODEL=text-embedding-3-small # or another compatible model
- Start the backend server:
cd backend
python server.py- Access the frontend:
- Option 1: Open
frontend/index.htmldirectly in your web browser - Option 2: Serve using Python's built-in server:
cd frontend
python -m http.server 3000Then visit http://localhost:3000 in your browser.
- Type your question in the input field
- The system will:
- Retrieve relevant context using embeddings
- Generate a step-by-step reasoning process
- Provide a final answer based on the context and reasoning
- View the intermediate steps and reasoning process in the response
The application can be configured through environment variables:
| Variable | Description | Default |
|---|---|---|
| OPENAI_API_KEY | Your OpenAI API key | Required |
| OPENAI_MODEL | OpenAI model to use | gpt-4o-mini |
| HOST | Backend server host | 0.0.0.0 |
| PORT | Backend server port | 8000 |
The application includes comprehensive error handling:
- API errors are logged and returned with appropriate status codes
- Frontend displays user-friendly error messages
- Detailed logging for debugging and monitoring
- Graceful fallbacks for common failure scenarios
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
Please ensure your code:
- Includes appropriate tests
- Follows the existing code style
- Updates documentation as needed
- Includes type hints
- Has meaningful commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Never commit your
.envfile or API keys - Keep dependencies updated
- Follow security best practices for production deployment
- Report security issues through GitHub's security advisory
Common issues and solutions:
-
OpenAI API Error
- Verify your API key is correct
- Check your API usage limits
- Ensure the model name is valid
-
Backend Connection Failed
- Confirm the backend server is running
- Check the port is not in use
- Verify firewall settings
-
Embedding Errors
- Ensure input text is not empty
- Check for proper text encoding
- Verify numpy installation
- OpenAI for their API and models
- FastAPI framework
- Contributors and maintainers
