How shubhammandowara/llm_rag works
Project type and purpose
• This is a lightweight full-stack (client + server logic) web application built with Streamlit.
• Its purpose is to let users upload a PDF, automatically extract and index its contents with FAISS, and answer user questions by invoking a large language model via the Hugging Face Inference API.
File structure
• Top level:
• app.py – the single entry point containing UI, PDF handling, FAISS indexing, and API calls
• requirements.txt – Python dependencies (Streamlit, FAISS, Hugging Face SDK, PDF parser)
• secrets.toml – Streamlit‐specific secret store for the Hugging Face token
• .github/workflows/ci.yaml – CI pipeline (install, lint, possibly test)
• No separate “frontend” or “backend” code directories: the app bundles both UI and processing in one Python script.
Key architectural components
a. Streamlit UI
• Renders the web interface in the user’s browser.
b. PDF ingestion & text extraction
• Uses a PDF library (PyPDF2/pdfplumber) to parse raw text and tables.
c. Text chunking & vectorization
• Splits the full text into segments (“chunks”).
• Generates embeddings for each chunk (embedded locally or via Hugging Face Embedding API).
d. FAISS vector store
• Stores and indexes chunk embeddings for fast similarity search.
e. Query pipeline
• User question → embed query → FAISS retrieves top-k related chunks → combine with user prompt.
f. Hugging Face Inference API
• Sends prompt+context to a chosen LLM (e.g., Mistral-7B) → receives generated answer.
g. Secrets management & configuration
• Hugging Face API token loaded from Streamlit secrets or environment.
h. CI workflow (optional to show)
• Validates code style and dependencies on each commit.
Relationships & data flow
1. User (browser) → Streamlit frontend (app.py)
2. Upload PDF → PDF extraction module → raw text
3. Text → chunker → embedding generator → FAISS index
4. User submits question → question embedding → FAISS similarity search → retrieve context chunks
5. Streamlit orchestrates context + question → Hugging Face Inference API → LLM answer
6. Streamlit displays answer back to user
Architectural patterns & design principles
• Single-process, event-driven web UI (Streamlit)
• Modular separation within a single script: ingestion, indexing, retrieval, API integration
• Externalized secret management for API tokens (separation of config vs code)
• Use of a vector database (FAISS) as a retrieval-augmented generation (RAG) pattern
Detail
• Every major responsibility as its own component—even if all live in app.py—to make dependencies explicit.
• Directional data flows for PDF ingestion, indexing, query retrieval, and LLM invocation.