The goal of this exercise is to familiarize yourself with programming using Python, OpenAI, and Vector Databases (namely Pinecone). The set up and the four introduction questions are simply meant to help you familiarize yourself with documentation and prompt engineering, but the rest of this lab will be more open-ended.
BED Talks aims to deliver powerful motivational talks to audiences worldwide. However, their existing keyword-based search system falls short in enabling users to find niche or specific topics. This project tackles the challenge by implementing a Retrieval-Augmented Generation (RAG) system using an LLM for query rewriting and Pinecone for semantic search. The result? A smarter, more intuitive search experience.
Start by cloning the repository to your local machine:
git clone https://github.com/kjeelani/bedtalks-rag-tutorial.git
cd bedtalks-rag-tutorial- Open the folder in VSCode if not done already
- In a terminal, enter
python -m venv env. This sets up your virtual environment (more on that here) - Then, if you are on Windows enter
env/Scripts/activate. If you are on Mac entersource env/bin/activate. You should see in your terminal (env) before each line. - Finally enter
pip install pinecone-client openai python_dotenv. You are now ready to work with the repository!
To use Pinecone:
- Sign up here
- Generate a Pinecone API key on the left sidebar
- Create a new Pinecone Index called
bed-talks
- Create a new file in the root repository called .env
- Obtain the OpenAI key we will use here. If you do not have access, let me know.
OPENAI_API_KEY=""
PINECONE_API_KEY=""
PINECONE_INDEX_NAME="bed-talks"
To get the most minimal example running, complete the four TODOs in the repo
- In
db/populate.py, use the Pinecone documentation to understand how to upsert (insert with update) your embedding and associate it with metadata. Then fill out the TODO. - In
db/search.py, use the Pinecone documentation to understand how to query your Pinecone database with your embedding. Then fill out the TODO. - In
main.py, import the proper function to search the Pinecone database in the TODO within the loop - Finally, in
main.pyat the top, fill out theREWRITE_TO_TITLE_PROMPTwith proper prompt engineering to convert any query into a title.
If you are stuck on any of these tasks, please refer to the solution branch of this project
This is already pretty useful as is, but how can we make this more interesting? Here are some possible directions you can take this project:
- The most basic but powerful idea is to incorperate the transcript somehow within our embedding or to retrieve the transcript for a more nuanced and detailed search result.
- When we as users use ChatGPT, we can get better results by iterating on results. Can we create a similar system where we incorporate user feedback to iteratively refine the search results?
- This system works great for 10 data points. But what about 1k? 1mil? Amazon shopping results use similar techniques but probably have 100+ million items in its shop. What techniques can we utilize for more efficient searching (Hint: look at sharding).