# amr-abdellatif/rag-application-multiple-pdf-s-with-langchain architecture

> Architecture diagram of the GitHub repository amr-abdellatif/rag-application-multiple-pdf-s-with-langchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain
- Repository: https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain

## Overview

##### Project type and purpose
- This is a small Python-based Retrieval-Augmented Generation (RAG) application.
- Purpose: Ingest multiple PDF documents, build a vector-embedding database, and answer user questions by retrieving relevant context and querying a local LLM (Ollama llama3:8b).

##### File structure
- Top-level scripts:
- get_embedding_function.py – wraps the LLM’s embedding API.
- populate_database.py – loads PDFs, computes embeddings, and populates a vector store.
- query_data.py – CLI entry point: takes a user question, retrieves nearest embeddings, and prompts the LLM.
- test_rag.py – pytest suite exercising end-to-end flow.
- Supporting files:
- requirements.txt – lists Python dependencies (e.g., langchain, chromadb, PyPDF).
- README.md – usage instructions.
- .gitignore
- Implied directory:
- data/ – user-provided PDFs reside here.

##### README for additional insights
- Installation: sets up Ollama, installs Python requirements.
- Workflow:
1. Drop PDFs into data/
2. Run populate_database.py → builds embedding DB
3. Run query_data.py "question" → returns an answer
4. Optionally run pytest on test_rag.py

##### Main components
a. PDF Ingestion & Parsing
- Component: PDF Loader
- Inputs: data/*.pdf
- Outputs: raw text chunks
b. Embedding Service
- Component: get_embedding_function
- Technology: Ollama llama3:8b via local CLI/API
- Function: Converts text chunks → high-dim vectors
c. Vector Store / Database
- Component: ChromaDB (or whichever vector DB is in requirements)
- Stores: {chunk_id, text_chunk, embedding_vector}
d. Retrieval & Query Pipeline
- Component: query_data.py
- Steps:
1. Accept CLI input “question”
2. Get question embedding via embedding_function
3. Perform similarity search on vector store → top-k text chunks
4. Assemble prompt: user question + retrieved context
5. Send prompt to LLM (Ollama) → generate answer
e. External Service
- Ollama local LLM server (llama3:8b)

##### Relationships & Data Flow
- data/*.pdf → PDF Loader → Text Chunks
- Text Chunks → Embedding Service → Vectors
- Vectors/Text → Vector Store
- User Question → Embedding Service → Query Embedding
- Query Embedding → Vector Store (Similarity Search) → Retrieved Chunks
- Retrieved Chunks + Question → LLM → Answer → CLI Output

##### Architectural patterns & design principles
- Separation of concerns: ingestion, embedding, storage, retrieval, LLM inference.
- Modularity: each major step lives in its own script/function.
- Reproducibility: test_rag.py ensures end-to-end correctness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Preparation
    subgraph "Data Preparation"
        PDFData["data/*.pdf"]:::docs
        PDFLoader["populate_database.py"]:::compute
        EmbService["get_embedding_function.py"]:::compute
        VectorStore(("ChromaDB")):::db
    end

    %% Query Runtime
    subgraph "Query Runtime"
        QueryCLI["query_data.py"]:::compute
        LLM["Ollama LLM (llama3:8b)"]:::external
    end

    %% Documentation
    subgraph "Project Docs & Setup"
        README["README.md"]:::docs
        Req["requirements.txt"]:::docs
    end

    %% Test Harness
    Test["test_rag.py"]:::compute

    %% Data Preparation Flow
    PDFData -->|"PDF files"| PDFLoader
    PDFLoader -->|"raw text chunks"| EmbService
    EmbService -->|"embeddings"| VectorStore

    %% Query Runtime Flow
    QueryCLI -->|"user question"| EmbService
    EmbService -->|"query embedding"| VectorStore
    VectorStore -->|"retrieved context"| QueryCLI
    QueryCLI -->|"prompt"| LLM
    LLM -->|"answer"| QueryCLI

    %% Test Harness invokes full pipeline
    Test -.-> PDFLoader
    Test -.-> QueryCLI

    %% Click Events
    click PDFLoader "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/populate_database.py"
    click EmbService "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/get_embedding_function.py"
    click VectorStore "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/populate_database.py"
    click QueryCLI "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/query_data.py"
    click Test "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/test_rag.py"
    click README "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/README.md"
    click Req "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/blob/main/requirements.txt"
    click PDFData "https://github.com/amr-abdellatif/rag-application-multiple-pdf-s-with-langchain/tree/main/data/"

    %% Styles
    classDef compute fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px
    classDef db fill:#bbdefb,stroke:#0d47a1,stroke-width:1px
    classDef external fill:#ffe0b2,stroke:#e65100,stroke-width:1px
    classDef docs fill:#eeeeee,stroke:#616161,stroke-width:1px,stroke-dasharray: 5 5
```
