This repository contains a Local Retrieval-Augmented Generation (RAG) System designed as a learning project. The goal is to build a simplified version of a RAG system from scratch to understand the underlying components and their interactions. It is not intended to be a fully optimized or production-ready solution but serves as an educational tool to explore concepts like embedding, vector storage, and query handling using a build-from-scratch approach.
- Docker and Docker Compose installed on your machine.
- An OpenAI API key for accessing OpenAI services as the model used for embeddings and generations is currently OpenAI-based.
Before starting, ensure you have set the following environment variables:
export OPENAI_API_KEY="your-openai-api-key"Or include this variable in a local .env file.
Replace your-openai-api-key with your actual OpenAI API key.
- Navigate to the project directory:
- Build and start the Docker containers:
docker compose up -d
A tutorial on how the database is set up and explanations for the settings can be found here.
Copy the example configuration file and edit it to specify your markdown source paths:
cp project_config_example.yaml project_config.yamlOpen project_config.yaml and replace the example paths with the paths to your desired markdown sources. Ensure the paths are correctly indented as shown in the example file.
Set up a local virtual environment and install the Python requirements using uv:
uv installThis command will create a virtual environment and install all dependencies specified in the pyproject.toml file.
Alternatively, you can use another tool like poetry to install the needed libraries found as dependencies in the pyproject.toml file.
- Run the database setup script:
This script will populate the RAG database with the necessary data.
python rag_setup.py
-
Run the frontend script to start the Gradio application:
python frontend.py
This will start a local server where you can interact with the chat application. Please keep in mind that every single query picks out the most similar embedding from the database and generates an answer, even if no embedding is relevant to the query.
Once the setup is complete, open your browser and navigate to the local server URL provided by Gradio to start using the chat application.