In this pilot course, you'll build a Naive RAG-based question-answer agent that supports the following HTML documents:
Understanding Naive RAG architecture is the first step towards understanding more advanced architectures and techniques appropriate for production settings.
.
├── .devcontainer # Docker environment config files
├── 1 query_qa_rag_agent.ipynb # Start here. Use to check your environment works.
├── 2 indexer.ipynb # Tutorial 2
├── 3 retriever.ipynb # Tutorial 3
├── 4 generator.ipynb # Tutorial 4
├── 5 summary.ipynb # Tutorial 5
├── LICENSE
├── README.md
├── cheat_code # Completed, working code you can cheat off of if you get stuck
├── data # Nothing useful in here for now
├── requirements.txt # Python packages
└── workshop_code # The code you will edit in the tutorials
Your development environment will be in a VSCode Dev Container to eliminate "works on my machine" issues.
If you want to push your changes to your own fork, note that your SSH settings won't be copied to your Dev Container. Use a non-VSCode terminal to push your changes.
If you want to inspect the environment configuration, check out the folder ".devcontainer/". Feel free to ask any questions.
We will use VSCode for this tutorial because it supports both Python Notebooks and standard Python editing. Although other editors have their merits, VSCode is also the most standard editor in 2024. The containerized development environment is only tested to work with VSCode. If you want to use other editors like Pycharm, Jupyter, or Colab, you'll have to do some non-trivial devops work upfront.
You will use this extension to develop within the Docker container dev environment.
Open VSCode > Extensions. Search for "Remote Containers". Click install.
If you're not sure, check if you have git
installed already. Copy and paste this commmand into your terminal:
if command -v git &>/dev/null; then echo "Git is installed and on the PATH"; else echo "Git is not installed or not on the PATH"; fi
If it's not installed, install git using Homebrew, Apt, etc as appropriate.
Easy option: install Git Bash
Microsoft Official Option:
- Install Windows Subsystem for Linux
- Open Ubuntu shell
apt install git
- Go to the Github repo for this course
- Click Fork
- Clone your forked repo with a terminal
cd
into therag-mini-bootcamp
repo folder
We will use OpenAI embeddings, GPT3.5, and Couchbase Capella vector database for this tutorial, so you will need to securely store your API keys in a .env
file. This file is in .gitignore
so it doesn't accidentally get committed to the repo where your keys would be exposed.
Create a .env
file in the root of the repo from this template. You will fill it in in the next steps.
# Replace this with Connection String from SDKs page in Couchbase console
CB_ENDPOINT="couchbases://cb.xxxxxxxxxxxxxxxx.cloud.couchbase.com"
# From database access credentials in Couchbase console
CB_USERNAME="RAG_WORKSHOP"
# From database access credentials in Couchbase console
CB_PASSWORD="<<password>>"
# From the OpenAI API console
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Go to OpenAI API settings. Create a new API key and copy it to the .env
file. If you're out of free trial credits, purchase $5 of credits.
- Sign up for a Couchbase account. Select any cloud provider and region. Click "Deploy Now".
- [Trial - Cluster Console] Go to "Connect"
- [SDKs Page] Add the Public Connection String to your .env file like so:
COUCHBASE_CLUSTER_URI=couchbases://cb.xxxxxxxxxxxxxxxx.cloud.couchbase.com
- [SDKs Page] Click the Allowed IP Addresses > Add Allowed IP > Allow Access from Anywhere > Add Allowed IP.
- [SDKs Page] Click Database Access > Create Database Access. Database Access Name: RAG_WORKSHOP. Bucket: All Buckets. Scope: All Scopes. Access: Read/Write.
- [SDKs Page] Select your database credentials
- [SDKs Page] Choose Python
Important notes if you adapt this configuration for production:
- Only whitelist IPs that are trusted
- Use the principle of least priviledge when creating database access
- Go to your console for Trial - Cluster
- Go to Data Tools > Search
- Click Create Search Index > Advanced Mode > Index Definition > Import from File
- Upload
couchbase-index-definition.json
from the root of the workshop repo - Click Create Index
Couchbase Reference Docs: Import a Search Index Definition with the Capella UI
Open the folder "rag-mini-bootcamp" in VSCode. Open the folder in Dev Container mode by using Cmd/Ctrl + Shift + P > Dev Containers: Open Folder in Container. The first time, the container will take some time to build while it downloads the required packages.
Once the container is finished building, open ./query_qa_rag_agent.ipynb
in VSCode. Click "Run All". The notebook should display a GPT3.5 completion to the question about the paper. If you get an error, try to diagnose it or flag one of us for help.