How armaanseth/chatpdf works
Project type and purpose
• This is a specialized RAG-powered “PDF Intelligence System” with a lightweight front-end (Streamlit) and a back-end pipeline (in app.py + htmlTemplates.py).
• Its purpose is to ingest one or more PDF files, index them into a FAISS vector store using Hugging Face embeddings, maintain conversational memory, and forward context plus user queries to OpenAI’s GPT-3.5 Turbo for answer generation.
File structure
• Top level files only:
• app.py – orchestrates the Streamlit UI, PDF ingestion, vector store creation, memory, and LLM calls.
• htmlTemplates.py – contains HTML templates or helper functions for rendering within Streamlit.
• requirements.txt – declares dependencies (Streamlit, FAISS, Hugging Face, OpenAI SDK, etc.).
• README, LICENSE, .gitignore – documentation and config.
• No separate “backend” or “frontend” folders; the architecture is embedded in app.py.
README for additional insights
• Workflow steps are clearly described: PDF → VectorStore (FAISS + all-MiniLM-L6-v2) → Memory Buffer → GPT-3.5 Turbo → Streamlit UI.
• Technologies: FAISS, Hugging Face Embeddings, OpenAI API, Streamlit.
a. Main components
• User Interface (Streamlit front-end)
• PDF Ingestion & Parser
• Chunker & Embedding Service (Hugging Face)
• Vector Store (FAISS)
• Conversation Memory (Buffer to track history)
• LLM Client (OpenAI GPT-3.5 Turbo API)
• Static Helpers (htmlTemplates.py)
• External Services (OpenAI, Hugging Face, FAISS library runtime)
b. Relationships & interactions
1. UI → PDF Ingestion: User uploads PDF(s) and submits a query.
2. Parser → Chunk & Embed: PDF text is chunked and passed to the Embedding Service.
3. Embedding Service → Vector Store: Embeddings are stored in FAISS.
4. On query: UI passes query + conversation history → Vector Store → retrieves top‐k relevant chunks.
5. Retrieved chunks + memory buffer → LLM Client → response.
6. LLM response → UI via htmlTemplates for display.
c. Architectural patterns & design principles
• Pipeline Pattern: clearly delineated stages (ingest → embed → index → retrieve → generate → display).
• Modularity: separation of concerns between UI, processing logic, storage, and third-party integrations.
• Retrieval-Augmented Generation: tightly couples retrieval (FAISS) with generation (GPT-3.5).
d. Key technologies/frameworks
• Streamlit for UI
• PyPDF (or similar) PDF parsing libraries inside app.py
• Hugging Face’s all-MiniLM-L6-v2 Embeddings model
• FAISS vector store
• OpenAI Python SDK (GPT-3.5 Turbo)
• Python standard libraries and helper templates in htmlTemplates.py