A simple but powerful Retrieval Augmented Generation (RAG) system built with Python and OpenAI. This system helps you build an AI-powered question-answering system that uses your own documents as context.
- Document loading and processing
- Text chunking for better context management
- OpenAI embeddings integration
- Similarity-based retrieval system
- Easy-to-use RAG interface
- Configurable chunk sizes and retrieval parameters
- Clone the repository:
git clone https://github.com/mazyaryousefinia/python-rag.git
cd python-rag- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up your environment variables:
cp .env.example .env
# Edit .env and add your OpenAI API key-
Add your documents to
data/documents/ -
Run a test:
python test.pyrag-project/
│
├── src/
│ ├── __init__.py
│ ├── document_loader.py
│ ├── text_processor.py
│ ├── embeddings_manager.py
│ ├── retrieval_system.py
│ └── rag_system.py
│
├── data/
│ └── documents/
│
├── requirements.txt
├── README.md
├── test.py
└── .env
Here's a simple example of how to use the RAG system:
from src.rag_system import RAGSystem
# Initialize the RAG system
rag = RAGSystem()
# Ask a question
question = "What was the answer to the guardian’s riddle, and how did it help Kai?"
answer = rag.answer_question(question)
print(answer)The system can be configured through environment variables:
OPENAI_API_KEY=your_api_key_here- Large documents may take time to process due to API rate limits
- Memory usage can be high with many documents
- No built-in caching system yet
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for their powerful API
- The open-source community for inspiration and tools
- Create an issue for bug reports or feature requests
- Pull requests are welcome!
Made with ❤️ by [Mazyar]