This project implements a Retrieval-Augmented Generation (RAG) system using the Google Gemini API and a simple FAISS vector database. The system processes PDF documents, creates vector embeddings, and allows semantic search and question answering based on the document content.
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- Windows:
venv\Scripts\activate
- Linux/Mac:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Add your Google API key to the
.envfile:GOOGLE_API_KEY=your_google_api_key_here
data/- Directory containing PDF documentssrc/- Source coderag_gemini.py- Full RAG implementation with Gemini APIsimple_vector_search.py- Simple vector database searchload_vector_db.py- Load a previously saved vector databasestreamlit_app.py- Streamlit web interface for the RAG systemlist_models.py- Utility to list available Google AI models
The easiest way to use the RAG system is through the Streamlit web interface:
streamlit run src/streamlit_app.pyThis will:
- Load and process the PDF document
- Create a vector database of document chunks
- Provide a chat interface for asking questions about the document content
- Display the source documents used to generate answers
To use the full RAG system with question answering:
python src/rag_gemini.pyThis will:
- Load and process the PDF document
- Create a vector database of document chunks
- Set up a question-answering chain using Gemini API
- Allow you to ask questions about the document content
For a simpler approach that just uses vector similarity search:
python src/simple_vector_search.pyThis will:
- Load and process the PDF document
- Create and save a vector database
- Allow you to search for relevant document sections
If you've already created a vector database:
python src/load_vector_db.pyThis loads a previously saved vector database and allows you to perform searches.
- Document Processing: The PDF is loaded and split into smaller chunks.
- Embedding Generation: Each chunk is converted into a vector embedding using Google's embedding model.
- Vector Storage: Embeddings are stored in a FAISS vector database for efficient similarity search.
- Retrieval: When a query is received, the system finds the most relevant document chunks.
- Generation: For the full RAG system, the retrieved chunks are passed to the Gemini model to generate an answer.
- Python 3.8+
- langchain
- langchain_community
- langchain-google-genai
- google-generativeai
- faiss-cpu
- python-dotenv
- pypdf
- sentence-transformers