Master a technique that integrates relevant documents into the generation process, enhancing the quality and contextuality of LLM responses. This repo demonstrates a simple RAG example and more advanced implementations.
- Docker (for containerized usage - recommended)
- Python 3.11 (for local setup)
- Pinecone account (free tier is sufficient)
Before running the application, you need to set up a Pinecone index:
- Log in to your Pinecone account at https://app.pinecone.io/
- Navigate to the "Indexes" section and click "Create Index"
- Fill in the following details:
- Name: Choose a name for your index (e.g., "rag-project-index")
- Dimensions: Set to
3072
- Metric: Choose
cosine
- For Environment and Region:
- Cloud Provider: Select
aws
- Region: Choose
us-east-1
(Note: These last two options are required for a free instance)
- Cloud Provider: Select
- Click "Create Index" to confirm
- If you wish to run
RAG_fusion_101.ipynb
you must create a separate Pinecone index - For this second index, follow the above procedure but set the
Dimensions
to1536
, and give the index a name of your choice - Make sure and enter this second index into the
.env
file
Remember the names you gave to your indices, as you'll need them for the .env
file.
- Copy the sample environment file:
cp .env.sample .env
- Edit the
.env
file and add your API keys and other required variables:Make sure to use the relevant index names you created forOPENAI_API_KEY=your-secret-key LANGCHAIN_API_KEY=your-secret-key LANGCHAIN_TRACING_V2=true LANGCHAIN_PROJECT=gauntlet_class_3 PINECONE_API_KEY=your-secret-key PINECONE_INDEX=your-3072-dimension-index-name PINECONE_INDEX_TWO=your-1536-dimension-index-name
PINECONE_INDEX
andPINECONE_INDEX_TWO
, respectfully.
-
Run the upload script:
docker compose run --rm upload_service
-
Run the main RAG example:
docker compose run --rm rag_app
-
Start Jupyter for notebook examples:
docker compose up jupyter
-
Run a specific script (any new
.py
file you may add):docker compose run --rm rag_app python <script_name.py>
Note: The Docker setup will automatically use the environment variables from your .env
file. You don't need to export them to your system environment when using Docker.
You can use the provided run.sh
script for easier execution.
Make sure to make the script executable with chmod +x run.sh
before using:
./run.sh upload
./run.sh main
./run.sh jupyter
./run.sh <your_new_py_file>
If you prefer to run the examples locally:
- Ensure you have Python 3.10+ installed.
- Clone the repository:
git clone [repository-url] cd [repository-name]
- Set up the environment:
python3 -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate` pip install -r requirements.txt
- Configure environment variables as described in the Setup section.
- Export the environment variables (python-dotenv should handle this automatically in the ):
export $(cat .env | xargs)
- Run an example:
python3 upload.py
- Ensure you're using Python 3.11.0 or later for local setup.
- For Docker issues, check your Docker installation and version.
- If you encounter package issues, try updating pip:
pip install --upgrade pip
- Make sure all required environment variables are set in your
.env
file. - If you're having issues with environment variables in Docker, ensure your
.env
file is in the same directory as yourdocker-compose.yml
file. - If you encounter issues with Pinecone, double-check that your index is created correctly and that you're using the correct API key and index name(s) in your
.env
file.
Refer to the project documentation or reach out to the learning assistant