Skip to content

Commit 318edec

Browse files
committed
Readded Docs
1 parent 029d434 commit 318edec

File tree

3 files changed

+137
-11
lines changed

3 files changed

+137
-11
lines changed

PROJECT_EXPLANATION.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Project Explanation: Yuhasa History Tutor
2+
3+
## Overview
4+
5+
This project, "Yuhasa," is an intelligent chatbot designed to act as a history tutor. It leverages a technique called Retrieval-Augmented Generation (RAG) to answer user questions based specifically on the content of the provided "Grade 11 History Textbook" PDF. Instead of relying solely on its general knowledge, the chatbot first retrieves relevant passages from the textbook and then uses that information to generate a comprehensive and contextually accurate answer.
6+
7+
## Core Goal
8+
9+
The primary goal is to provide students with a tool to explore and understand their history textbook content interactively. Users can ask questions in natural language, and the chatbot will provide answers grounded in the specific information present in the document.
10+
11+
## Key Processes and Components
12+
13+
1. **Data Ingestion and Processing (`pdf_chunker.py`, `faiss_store.py`):**
14+
* **Loading:** The system first reads the `grade-11-history-text-book.pdf`.
15+
* **Chunking:** The text content is broken down into smaller, manageable chunks (paragraphs or sections). This is crucial for effective retrieval.
16+
* **Embedding:** Each text chunk is converted into a numerical representation called an "embedding" using a machine learning model (likely via `gemini_utils.py` or a dedicated embedding model). Embeddings capture the semantic meaning of the text.
17+
* **Vector Store Creation:** These embeddings (vectors) and their corresponding text chunks are stored in a specialized database called a vector store. This project uses FAISS (`faiss_store.py`), which allows for very fast searching of similar vectors. The store consists of `faiss_index.index` (for the vectors) and `faiss_metadata.pkl` (linking vectors back to text and metadata). This step only needs to be done once unless the source PDF changes.
18+
19+
2. **User Interaction (Web: `web.py`, `templates/index.html`; CLI: `cli_chat.py`):**
20+
* Users can interact with the chatbot through either a web-based graphical interface or a simple command-line interface.
21+
* The user types a question (e.g., "What were the main causes of World War 1 according to the textbook?").
22+
23+
3. **Retrieval-Augmented Generation (RAG) Pipeline (`agents/` directory):**
24+
* **Query Analysis (`agents/query_analyzer.py`):** The user's query is analyzed using basic regex to extract keywords and entities.
25+
* **Query Embedding:** The user's question is also converted into an embedding using the same model as the document chunks.
26+
* **Retrieval (`agents/retriever.py`, `faiss_store.py`):** The system searches the FAISS vector store for the text chunks whose embeddings are most similar (closest in vector space) to the query embedding. These retrieved chunks are considered the most relevant context from the textbook.
27+
* **Context Expansion (`agents/context_expander.py` - potentially):** The retrieved context might be expanded or refined.
28+
* **Prompt Formulation:** A prompt is constructed for the generative AI model (Gemini). This prompt typically includes:
29+
* The original user question.
30+
* The relevant text chunks retrieved from the textbook (the "context").
31+
* The recent conversation history (to maintain context in multi-turn conversations).
32+
* Instructions for the AI (e.g., "Answer the user's question using *only* the provided context.").
33+
* **Generation (`agents/generator.py`, `gemini_utils.py`):** The constructed prompt is sent to the Google Gemini API. Gemini reads the prompt, understands the question and the provided context, and generates a natural language answer.
34+
* **Reference Tracking (`agents/reference_tracker.py` - potentially):** The system might track which parts of the retrieved context were used to generate the answer, potentially for citation purposes (though this isn't explicitly shown in the UI).
35+
* **Orchestration (`agents/orchestrator.py`):** This component manages the flow between the different agents (retriever, generator, etc.) ensuring they work together correctly.
36+
37+
4. **Response Delivery:**
38+
* The generated answer is sent back to the user interface (web or CLI) and displayed.
39+
* Conversation history is saved (`chats/` directory) to maintain context for future interactions within the same session.
40+
41+
## Technology Stack
42+
43+
* **Language:** Python
44+
* **Web Framework:** Flask (`web.py`)
45+
* **Generative AI:** Google Gemini (`gemini_utils.py`)
46+
* **Vector Store:** FAISS (`faiss_store.py`)
47+
* **PDF Processing:** PyMuPDF (via `fitz` in `pdf_chunker.py`)
48+
* **Frontend:** HTML, CSS, JavaScript (`templates/`, `static/`)
49+
* **Core Dependencies:** `python-dotenv` (for environment variables), `numpy`.

README.md

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,81 @@
1-
```bash
2-
pip3 install faiss-cpu google-generativeai python-dotenv fastapi uvicorn pydantic
3-
```
4-
5-
## For Web UI
6-
```bash
7-
pip3 install flask
8-
```
9-
```bash
10-
python3 web.py
11-
```
1+
# Yuhasa - History Tutor Chatbot
2+
3+
This project implements a Retrieval-Augmented Generation (RAG) chatbot focused on answering questions about a Grade 11 History textbook. It uses Google's Gemini AI for language understanding and generation, and FAISS for efficient information retrieval from the textbook content. The project intentionally uses minimal dependencies (Flask, FAISS, Gemini, PyPDF) for simplicity, speed, and maintainability.
4+
5+
## Prerequisites
6+
7+
* **Python:** Version 3.10 or higher recommended.
8+
* **pip:** Python package installer.
9+
* **Google AI API Key:** You need an API key from Google AI Studio (or Google Cloud Vertex AI) for the Gemini models.
10+
* **Git:** (Optional) If cloning the repository.
11+
12+
## Setup
13+
14+
1. **Clone the Repository (if applicable):**
15+
```bash
16+
git clone <repository-url>
17+
cd <repository-directory>
18+
```
19+
20+
2. **Install Dependencies:**
21+
It's recommended to use a virtual environment:
22+
```bash
23+
python -m venv venv
24+
# On Windows
25+
.\venv\Scripts\activate
26+
# On macOS/Linux
27+
source venv/bin/activate
28+
29+
pip install -r requirements.txt
30+
```
31+
*(Note: The `requirements.txt` file lists the necessary dependencies: `flask`, `google-generativeai`, `faiss-cpu`, `pypdf`, `python-dotenv`, `numpy`)*
32+
33+
3. **Configure API Key:**
34+
* Create a file named `.env` in the root project directory.
35+
* Add your Google AI API key to the `.env` file:
36+
```
37+
GOOGLE_API_KEY=YOUR_API_KEY_HERE
38+
```
39+
* The `config.py` file likely loads this key.
40+
41+
4. **Process the PDF (if not already done):**
42+
The project needs to process the `grade-11-history-text-book.pdf` into a vector store. There might be a script for this, or it might happen automatically on the first run. Check `main.py`, `embed_store.py`, or `pdf_chunker.py` for clues. If a specific script exists (e.g., `python embed_store.py`), run it:
43+
```bash
44+
python faiss_store.py
45+
```
46+
This will create the `faiss_index.index` and `faiss_metadata.pkl` files (or similar).
47+
48+
## Running the Application
49+
50+
There seem to be multiple ways to interact with the chatbot:
51+
52+
1. **Web Interface (Recommended):**
53+
* Run the Flask web server:
54+
```bash
55+
python web.py
56+
```
57+
* Open your web browser and navigate to the address provided (usually `http://127.0.0.1:5000` or similar).
58+
59+
2. **Command-Line Interface:**
60+
* Run the CLI script:
61+
```bash
62+
python cli_chat.py
63+
```
64+
* Interact with the bot directly in your terminal. Type 'exit' or 'quit' to end the session.
65+
66+
## Project Structure Overview
67+
68+
* `web.py`: Runs the Flask web server for the GUI.
69+
* `cli_chat.py`: Provides a command-line interface.
70+
* `config.py`: Handles configuration (like API keys).
71+
* `faiss_store.py`: Manages the creation and querying of the FAISS vector store.
72+
* `gemini_utils.py`: Contains helper functions for interacting with the Gemini API.
73+
* `pdf_chunker.py`: Responsible for reading and splitting the PDF document.
74+
* `agents/`: Directory containing different components (agents) of the RAG pipeline (Retriever, Generator, Orchestrator, etc.).
75+
* `templates/index.html`: The HTML structure for the web interface.
76+
* `chats/`: Stores conversation history (JSON files).
77+
* `grade-11-history-text-book.pdf`: The source document.
78+
* `faiss_index.index`, `faiss_metadata.pkl`: The generated vector store files.
79+
* `requirements.txt`: Lists the project dependencies.
80+
* `README.md`: This file.
81+
* `PROJECT_EXPLANATION.md`: Detailed explanation of the project architecture.

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
flask
2+
google-generativeai
3+
faiss-cpu
4+
pypdf
5+
python-dotenv
6+
numpy
7+
gtts

0 commit comments

Comments
 (0)