An enterprise-ready, serverless Retrieval-Augmented Generation (RAG) application engineered to transform static PDF documentation into an interactive, context-aware knowledge network. This system eliminates local computational bottlenecks by decoupling front-end presentation from heavy AI operations, relying on a robust LangChain Expression Language (LCEL) pipeline, in-memory Chroma vector matrix indexing, and high-availability cloud-managed inference endpoints.
Experience the full-screen interactive web application live on Hugging Face Spaces: π Launch Production Interface
The dynamic flowchart below models the structured architecture of the systemβdetailing the explicit transactional flow from document extraction down to the stateful, conversational user tracking layer.
flowchart TD
%% Global Styling Configurations
classDef source fill:#f5f6fa,stroke:#7f8c8d,stroke-width:2px,stroke-dasharray: 2;
classDef processing fill:#dff9fb,stroke:#0984e3,stroke-width:1px;
classDef storage fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px;
classDef engine fill:#fff3e0,stroke:#f39c12,stroke-width:2px;
classDef output fill:#f1f2f6,stroke:#2f3542,stroke-width:2px;
%% Data Ingestion Phase
subgraph INGESTION & DOCUMENT PIPELINE
A[Target PDF Document]:::source --> B[PyPDF Ingestion Loader]:::processing
B --> C[Recursive Character Text Segmentation]:::processing
C --> D[Sentence-Transformers Vector Compiler]:::processing
D --> E[(Chroma DB Structural Matrix)]:::storage
end
%% Inference Phase
subgraph INFERENCE & STATE ROUTING
F[Multi-Turn Chat Input]:::source --> G[Intent & History Context Condenser]:::engine
G --> H[Vector Similarity Matrix Query]:::processing
E -.->|Semantic Extraction| H
H --> I[Qwen-2.5-7B Chat Model Endpoint]:::engine
I --> J[Gradio 6.0 Presentation Interface]:::output
end
- Structural Extraction Pipeline: Integrates
PyPDFLoaderto seamlessly ingest multi-page document layers, preserving layout data and textual coherence across page structures. - Recursive Safe Segmentation: Text matrices are split into structured blocks via
RecursiveCharacterTextSplitterconfigured with a chunk size of 1,000 characters and a 200-character overlapping safe boundary. This dual-tiered boundary ensures critical topics do not suffer semantic fragmentation across rigid section markers.
- Dense Coordinate Mapping: Raw data strings are transformed into spatial floating-point representations using the
all-MiniLM-L6-v2Sentence-Transformers platform. - Vector Array Registry: Multi-dimensional coordinate mappings are securely cached inside an active, in-memory instance of
Chroma DB, optimized for sub-second cosine similarity lookups during queries.
- Object Traversal Safeguards: Built to natively intercept contemporary Gradio
ChatMessageobjects, explicitly parsing conversation logs by targeting internal.roleand.contentproperties to prevent data-unpacking crashes. - Query Contextualization: Conversational history is passed through a pre-retrieval pipeline (
ChatPromptTemplate | llm). This layer automatically rewrites short or implicit follow-up entries into rich standalone queries before searching the vector database.
- Serverless Execution Architecture: The backend relies entirely on Hugging Face Free CPU Basic container nodes (16GB RAM / 2 vCPUs), presenting zero local hosting overhead.
- Secure Environment Secret Isolation: Access tokens remain isolated via native Hugging Face Space Secrets configured under the exact variable
HUGGINGFACEHUB_API_TOKEN. This parameter is systematically accessed viaos.getenv()at initialization to strictly maintain infrastructure protection limits. - Model Endpoint Access: Implements a direct API handshake to fetch remote models from Hugging Face's global serverless worker layer, guaranteeing instant execution cycles.
- Asynchronous File Handling: Employs
gr.Filefor isolated document uploading, binding events directly to background processes while leaving the UI thread fully interactive. - Modern State Handlers: Uses
gr.ChatInterfaceto capture, track, and maintain multi-turn context objects natively, removing the need for manual connection pools or complex custom arrays. - Reactive Components: Includes interactive state blocks (
gr.Textbox) to communicate pipeline tracking stages and vector generation progress directly to the active browser interface.
The platform architecture utilizes clean, modern standalone abstractions to replace deprecated legacy tools:
langchain-core: Drives the core LCEL compilation primitives (|) linking the contextual prompt maps to the inference pipeline.langchain-huggingface: Handles the explicit API transport mapping from the raw local input strings up to the cloud-native model workers.sentence-transformers: Processes deep mathematical text vectorization using the optimizedall-MiniLM-L6-v2parameter pipeline.chromadb: Acts as the local similarity indexing matrix, matching natural queries to the nearest relevant document coordinates in real-time.
The application embeds granular, rule-based analytics to capture systemic execution data:
- Token Budget & Truncation Guardrails: Configured with a
max_new_tokens=512boundary limit to structure generation constraints and avoid timeout exceptions. - Context Ingestion Metrics: Features a fixed spatial constraint (
search_kwargs={"k": 3}) to limit the vector payload data sent during prompt synthesis, balancing extraction context with performance. - Deterministic Inference Monitoring: Set to a steady
temperature=0.7index point to stabilize generative variety and ensure responses remain factual to the uploaded document data.
| Module View | Interface Capabilities |
|---|---|
| Document Ingestion Hub | Single-click file processing pipeline equipped with real-time status feedback tracking logs. |
| Conversational Matrix Space | Streaming response panels optimized with multi-turn intent tracking using robust Gradio 6 standard tokens. |
βββ app.py # Core interface definition & LangChain LCEL pipeline
βββ requirements.txt # Structural software dependency landscape requirements
βββ .gitignore # Security rules blocking secret and cache tracking leakage
βββ README.md # Aesthetic architectural documentation
git clone https://github.com/rchinmay91/pdf-chatbot.git
cd pdf-chatbotpip install -r requirements.txtpython app.pyOpen http://127.0.0.1:7860 inside your web browser to interact with your local chatbot sandbox.
Distributed under the terms of the MIT License.
MIT License
Copyright (c) 2026 rchinmay91
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE