This repository contains a Google Colab notebook that demonstrates how to build a Retrieval-Augmented Generation (RAG) system using LLAMAIndex, FAISS, and the OpenAI API. The system processes text from H.P. Lovecraft's story "The Colour Out of Space", stores the embedded text in a vector database, and uses it to enhance query responses with relevant context.
- Clone this repository or download the notebook file.
- Open the notebook in Google Colab.
- Follow the steps in the notebook to install the necessary libraries and set up the environment.
- Google Colab
- OpenAI API key
The notebook installs the following libraries:
llama-index
faiss-cpu or faiss-gpu
openai
requests
Set your OpenAI API key to authenticate and use the OpenAI API for embeddings and completions.
The notebook downloads the text of "The Colour Out of Space" from the provided URL and chunks it into smaller, configurable pieces.
Each text chunk is embedded using OpenAI's text embedding model.
The embeddings are stored in a FAISS index for efficient similarity search.
The notebook sets up a RAG system to process a query, retrieve relevant chunks from the vector database, and enhance the query response with the top K results.
- Text Chunking: The text is divided into smaller chunks to make it manageable for embedding and retrieval.
- Embedding: Each chunk is converted into a vector representation using OpenAI's embedding model.
- Vector Storage: The vectors are stored in a FAISS index, which allows for efficient similarity searches.
- Query Processing: When a query is made, the system searches the FAISS index to find the most relevant chunks.
- Context Enhancement: The top K results from the search are used to enhance the context of the query response.
- Open the notebook in Google Colab.
- Run each cell step-by-step to process the text, embed it, store the vectors, and set up the RAG system.
- Modify the query as needed and observe the enhanced responses.
The example query used in the notebook is:
What happened on November 1st, 1907?
The system will provide a contextually enhanced answer based on the most relevant text chunks retrieved from the vector database.
This project is licensed under the MIT License. See the LICENSE file for more details.