TermTalk is an intelligent document analysis tool designed to help users understand and query Terms and Conditions (T&C) documents. It leverages Retrieval-Augmented Generation (RAG) to provide accurate, context-aware answers to user questions based on uploaded PDF documents.
- PDF Upload: Upload T&C documents (PDF format).
- Automated Processing: Background processing of PDFs to extract text, split into chunks, and generate embeddings.
- RAG-powered Chat: Ask questions about the uploaded documents and get answers with citations (source and page number).
- File Management: View and delete uploaded files.
- Framework: Next.js (React)
- Styling: Tailwind CSS
- UI Components: Radix UI, Lucide React (Icons)
- HTTP Client: Axios
- Framework: Flask (Python)
- Database: PostgreSQL (Metadata), ChromaDB (Vector Store)
- LLM: Google Gemini (
gemini-2.0-flash-exp) vialangchain-google-genai - Task Queue: APScheduler (for background PDF processing)
- PDF Processing:
pypdf,langchain-text-splitters
The backend is built with Flask and orchestrates the document processing and RAG pipeline.
When a PDF is uploaded, it enters a processing queue managed by APScheduler. The pipeline runs every 60 seconds:
- Ingestion: The system picks up files with
Uploadedstatus. - Extraction:
PyPDFLoaderextracts raw text from the PDF. - Chunking:
RecursiveCharacterTextSplitterbreaks text into manageable chunks (500 chars, 150 overlap) to preserve context. - Embedding & Storage: Chunks are embedded and stored in
ChromaDB(Vector Store) with metadata (page number, source file). - Completion: File status updates to
Completed.
When a user asks a question:
- Retrieval: The system queries
ChromaDBusing the user's question to find the top 3 most relevant document chunks. - Augmentation: A context window is constructed by combining the retrieved chunks.
- Generation: The context and the user's question are sent to Google's Gemini Pro model (
gemini-2.0-flash-exp). - Response: The LLM generates an answer based only on the provided context, citing sources.
- Node.js (v18 or higher)
- Python (v3.8 or higher)
- PostgreSQL (running and accessible)
- Google Gemini API Key
git clone <repository-url>
cd termTalkNavigate to the backend directory:
cd backendCreate and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activateInstall dependencies:
pip install -r requirements.txtSet up environment variables:
Create a .env file in the backend directory with the following variables:
GEMINI_API_KEY=your_gemini_api_key
DATABASE_URL=postgresql://user:password@localhost:5432/termtalk_db
UPLOAD_FOLDER=uploads
CHROMA_PATH=chroma_db(Note: Ensure your PostgreSQL database is created)
Run the backend server:
python server.pyThe server will start on http://localhost:5000.
Navigate to the frontend directory:
cd ../frontendInstall dependencies:
npm installRun the development server:
npm run devThe frontend will be available at http://localhost:3000.
- Open the frontend application in your browser.
- Upload a PDF document (e.g., a Terms and Conditions file).
- Wait for the status to change to "Completed" (processed by the background job).
- Select the file and start chatting to ask questions about its content.
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check |
GET |
/users |
List users |
POST |
/upload |
Upload a PDF file |
GET |
/files |
List all uploaded files |
DELETE |
/delete-file/<uid> |
Delete a file and its embeddings |
POST |
/chat |
Query a document (requires file_uid and question) |