# rashed9810/langchain-with-rag architecture

> Architecture diagram of the GitHub repository rashed9810/langchain-with-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rashed9810/langchain-with-rag
- Repository: https://github.com/rashed9810/langchain-with-rag

## Overview

##### Main Components
- PDF Document Storage and Loader: Show the PDF directory as the storage area and include the “PDF Loader” component (using PyPDFLoader) that reads these documents.
- Text Processing and Chunking: Represent the “Text Splitter” (implemented with RecursiveCharacterTextSplitter) that processes the documents into chunks.
- Vector Storage: Illustrate the FAISS vector store where these embeddings are stored for similarity search.
- Query Processing & Retrieval: Include the user query intake, likely via a function (as shown in testing.py) that converts the query into an embedding, retrieves relevant chunks from FAISS, and routes them to the next component.
- Answer Generation: Add the LLM component (ELYZA’s Japanese Llama-2 model) that processes retrieved chunks to generate the final answer.
- Web Interface Integration: Highlight the integration with Chainlit (configured inside the .chainlit directory and via Chainlit command “chainlit run app.py”) which provides the UI for users to interact with the system. Also mention the multilingual support and localization assets (translations in .chainlit/translations).

##### Out the Data Flow
- Transition from embedding generation into the FAISS vector store.
- Query Pipeline: A user query is transformed into an embedding, which is then used for FAISS-based retrieval.
- Finally, the retrieved text chunks are fed into the LLM for answer generation.
- For the web-based interaction, indicate that the Chainlit interface is the front end that triggers these interactions.

##### Architectural Patterns and Technologies
- That the project leverages LangChain as the framework linking the components.
- Demonstrate the separation of concerns between document processing, embedding and storage, query retrieval, and answer generation.
- Use of GPU acceleration (via PyTorch and CUDA) in model inference.
- Modular design: each step (loading, splitting, embedding, retrieval, generation) is a distinct module/pipeline.

- If applicable, include a small inset for the LLM pipeline to detail how the system transforms retrieved text into a response.
- Error checking or fallback strategies (if any, as suggested by the instructions in the README).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Document Ingestion Pipeline"
        A["PDF Repository"]:::storage
        B["PDF Loader (PyPDFLoader)"]:::processing
        C["Text Splitter (RecursiveCharacterTextSplitter)"]:::processing
        D["Embedding Generator (HuggingFace multilingual-e5-large)"]:::processing
        E["FAISS Vector Store"]:::database
    end

    subgraph "Query Pipeline"
        F["Chainlit Web UI"]:::interface
        G["Query Processor & Retrieval"]:::processing
        H["LLM Model (ELYZA's Japanese Llama-2)"]:::processing
    end

    A -->|"loads"| B
    B -->|"parses"| C
    C -->|"splits"| D
    D -->|"embeds"| E

    F -->|"captures"| G
    G -->|"searches"| E
    E -->|"retrieves"| H
    H -->|"returns"| F

    click A "https://github.com/rashed9810/langchain-with-rag/tree/main/Langchain_RAG/PDF"
    click B "https://github.com/rashed9810/langchain-with-rag/tree/main/Langchain_RAG/PDF"
    click C "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/testing.py"
    click D "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/testing.py"
    click E "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/testing.py"
    click G "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/testing.py"
    click H "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/testing.py"
    click F "https://github.com/rashed9810/langchain-with-rag/blob/main/Langchain_RAG/.chainlit"

    classDef storage fill:#a2d9ce,stroke:#239b56,stroke-width:2px;
    classDef processing fill:#f9e79f,stroke:#d4ac0d,stroke-width:2px;
    classDef database fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef interface fill:#aed6f1,stroke:#2980b9,stroke-width:2px;
```
