This repository contains a Streamlit-based chatbot powered by Google Gemini AI and FAISS vector search. The chatbot utilizes Retrieval-Augmented Generation (RAG) to answer user queries based on the content of a PDF document.
- Document Embedding: Converts a PDF document into vector embeddings using GoogleGenerativeAIEmbeddings.
- Vector Search: Stores document embeddings in FAISS for fast retrieval.
- Chatbot Interface: Provides a simple UI using Streamlit.
- Retrieval-Augmented Generation (RAG): Uses a retriever to fetch relevant document sections and generate responses.
- Memory: Retains conversation history using ConversationBufferMemory.
Before running the application, ensure you have the following installed:
- Python 3.8+
- pip (Python package manager)
-
Clone the repository:
git clone <repository-url> cd <repository-name>
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in the project directory. - Add the following line:
GOOGLE_API_KEY=your_google_api_key_here
- Create a
The following libraries are required:
pip install streamlit langchain langchain_community langchain_google_genai faiss-cpu python-dotenv|-- app.py # Main application script
|-- requirements.txt # Required Python libraries
|-- .env # Environment variables
|-- README.md # Documentation
- Loads the specified PDF file using
PyPDFLoader. - Splits the document into chunks using
RecursiveCharacterTextSplitter.
- Converts text chunks into embeddings using
GoogleGenerativeAIEmbeddings. - Stores the embeddings in a FAISS vector database for similarity search.
- Uses
ChatGoogleGenerativeAIas the main LLM. - Defines a retrieval function to fetch the most relevant document chunks.
- Implements memory using
ConversationBufferMemory.
- The user inputs a query in the Streamlit app.
- The system retrieves relevant document sections and generates a response using
ChatGoogleGenerativeAI. - The response is displayed in the UI, and conversation history is retained.
Run the Streamlit app using:
streamlit run app.py- Ensure your
.envfile contains a validGOOGLE_API_KEY. - If FAISS installation fails, try:
pip install faiss-cpu
- If
langchain_google_genaithrows an error, ensure you have the latest version installed:pip install --upgrade langchain_google_genai
- Implement user authentication.
- Enhance UI/UX.
- Allow multiple document uploads.
This project is licensed under the MIT License.
Job Kiptoo