Use this repository to explore common components of Retrieval Augmented Generation (RAG) applications. RAG allows you to bring your data to large language models, without needing to train or fine-tune the model itself.
Before you start, make sure you install the following:
- Python 3.11 or later
- An IDE with Python support (Visual Studio Code, PyCharm, Jupyter)
- Docker Desktop (to run the Community database for these exercises)
git clone https://github.com/intersystems/samples-rag.git
If you do not have Git installed, download the repository and extract into a new directory.
You can run a Community version of InterSystems IRIS data platform using Docker:
docker pull intersystemsdc/iris-community:latest
cd Samples-RAG-Application
docker-compose up
The docker composition maps ports 51972 and 52775 to the IRIS Container. You can modify the port mappings directly in the docker-compose.yml, and run the docker-compose up command again.
Before running the notebooks, create a Python environment to install all dependencies and packages:
cd samples-rag
python -m venv ./.rag-samples-venv
This will create a directory (.rag-samples-venv) in your cloned directory. Now you can install the Python packages in this environment, without affecting the global Python environment.
cd samples-rag
./.rag-samples-venv/Scripts/Activate.ps1 ## PowerShell
./.rag-samples-venv/Scripts/activate.bat ## Windows Command Prompt
source ./.rag-samples-venv/Scripts/activate ## Bash
pip install -r requirements.txt
Take a look at the requirements.txt file in the repo if you are unsure about any imported Python packages. You can check which packages are installed with:
pip list
In your IDE, choose .rag-samples-venv as your Python kernel before running any of the notebooks. In Visual Studio Code, once you open a notebook in the editor, you can click the kernel icon in the top bar:
Walk through the notebooks in this order:
- data_loader.ipynb
- chain_of_thought.ipynb
- memory.ipynb
- agents.ipynb
There is also a sample chatbot application in the ./notebooks/rag_app
directory.
In the .rag-samples-venv Python virtual environment, run the following command to start the application:
cd Samples-RAG-Application
streamlit run .\notebooks\rag_app\streamlit_app.py
The application will use host port 8501. You can query it on all the same information from the previous exercises.
Once you are finished, you can stop the IRIS Container and destroy all resources.
- Stop the container if it is running:
cd Samples-RAG-Application
docker-compose down
You can also stop the container from Docker Desktop.
- Remove dangling images
docker system prune