# shreedharsmurnal/chat-with-multiple-pdfs-llama2 architecture

> Architecture diagram of the GitHub repository shreedharsmurnal/chat-with-multiple-pdfs-llama2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2
- Repository: https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2

## Overview

##### Project Type and Purpose
- This is a Python-based, full-stack (or end-to-end) interactive application that lets users load multiple PDF documents, process them (via text extraction and chunking), generate vector representations using a language model, perform similarity matching to find relevant content, and then respond to user queries.
- The README also indicates that it is deployed via Streamlit and integrates with external dependencies like the Ollama library and the LLAMA2 chat model.

##### File Structure
- Top-level files:
- app.py: Likely the main entry point where the Streamlit interface is launched and core application logic is handled.
- htmlTemplates.py: May contain helper functions or code for rendering HTML snippets or customized UI elements.
- .env.example, .gitignore, .python-version, requirements.txt: Standard configuration and dependency management files.
- There are no separate folders for backend or frontend – the logic is consolidated in a few files; however, the README describes distinct processing steps, implying a clear internal separation of concerns (e.g., PDF Loading, Text Chunking, Language Model integration, and Response Generation).

##### Detailing the Architecture
- Main Components:
- User Interface (UI):
▫ The Streamlit-based front end (launched via app.py). Represents the browser’s view where users upload PDFs and ask questions.
▫ htmlTemplates.py may support custom HTML rendering.
- PDF Processing Component:
▫ A module (likely part of app.py) for loading PDF documents and extracting text.
▫ Handles splitting the extracted text into manageable chunks.
- Semantic Processing & Embedding Generator:
▫ Integrates with the language model (via the Ollama library pulling LLAMA2) to generate vector embeddings for each text chunk.
- Similarity Matching & Response Generation:
▫ Once the user’s query is received, this component compares the query’s embedding with the pre-generated embeddings to identify semantically similar text chunks.
▫ Passes selected chunks to the language model in order to produce a relevant response.
- External Integration:
▫ The Ollama library and LLAMA2 model accessed externally as a service, ensuring that the heavy lifting in natural language understanding and text similarity is effectively outsourced.

- Data Flow & Interactions:
- The user interacts with the UI (Streamlit front end).
- Uploaded PDF files are processed by the PDF Loader, which extracts and chunks text.
- Each text chunk is processed by the embedding generator, integrating with the language model service.
- When a question is asked, the system computes the similarity between the query and stored chunk embeddings.
- The most relevant text segments are passed to the response generator (powered by the language model) to formulate an answer.
- Results are then rendered back on the UI in an interactive chat format.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Although the codebase is compact, conceptually separate functionalities (UI handling, PDF processing, language model integration) should be visualized as distinct components or modules.
- Data Flow Orientation:
- External Service Integration:
- Clearly denote the external language model service (LLAMA2 via Ollama) as a separate block with an indication of asynchronous or API-based interaction if applicable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI["User Interface (Streamlit Front End)"]:::frontend
    end

    subgraph "Processing Pipeline"
        PDF["PDF Loading & Text Extraction"]:::processing
        Chunk["Text Chunking Module"]:::processing
        Embed["Embedding Generator & Language Model Interface"]:::processing
        Similarity["Similarity Matching & Response Generation"]:::processing
    end

    External["External Language Model Service (Ollama/LLAMA2)"]:::external

    subgraph "Documentation"
        Docs["Project Documentation & Architecture References"]:::docs
    end

    UI -->|"uploadsPDF"| PDF
    PDF -->|"extractsText"| Chunk
    Chunk -->|"createsTextChunks"| Embed
    Embed -->|"queriesAPI"| External
    Embed -->|"passesEmbeddings"| Similarity
    Similarity -->|"returnsResponse"| UI

    click UI "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/blob/main/app.py"
    click UI "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/blob/main/htmlTemplates.py"
    click PDF "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/blob/main/app.py"
    click Embed "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/blob/main/app.py"
    click Similarity "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/blob/main/app.py"
    click Docs "https://github.com/shreedharsmurnal/chat-with-multiple-pdfs-llama2/tree/main/docs/"

    classDef frontend fill:#FFD700,stroke:#DAA520,stroke-width:2px;
    classDef processing fill:#87CEFA,stroke:#4682B4,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
    classDef docs fill:#98FB98,stroke:#32CD32,stroke-width:2px;
```
