# platzi/curso-langchain-qa-documents architecture

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

- Interactive diagram: https://gitdiagram.com/platzi/curso-langchain-qa-documents
- Repository: https://github.com/platzi/curso-langchain-qa-documents

## Overview

##### Main Components
- User Interface (UI): Represented by app.py which is launched via Streamlit. This component provides the front-end where users can input queries and view results.
- Ingestion Engine: The ingest.py script is used to load and perhaps index documents. This script likely calls helper functions from the src (specifically src/langchain_docs_loader.py) to process and prepare documents.
- Core LangChain Components: The src directory (and its langchain_docs_loader module) embodies the logic for handling document retrieval – especially since the course is titled “Curso de LangChain para Manejo y Recuperación de Documentos.”
- External APIs: Highlight external services that are integrated into the project. The README mentions OpenAI, Docugami, and Cohere API keys. These services provide the underlying NLP capabilities (language models, semantic processing, etc.).
- Documentation & Notebooks: Although not part of runtime, the notebooks (both exercises and resolved versions in notebooks_ejercicios and notebooks_resueltas) and docs directories play an important educational role. They show various retrieval patterns (e.g., context-aware extraction, text splitting, semantic reranking, multi-query, ensemble retrievers, etc.) and should be noted in the architecture as examples of different strategies.

##### Relationships & Data Flow
- Start at the User Interface (Streamlit – app.py). When the user submits a query, this interface triggers calls to the backend.
- The backend logic (which may involve aspects from ingest.py and the src modules) processes the query. This might include selecting and applying a specific retrieval algorithm discussed in the notebooks.
- External API calls (to OpenAI, Docugami, Cohere) would be invoked as part of the processing – for example, to obtain embeddings, perform semantic ranking, or language modeling.
- Once processing is complete, results flow back to the UI to be rendered for the user.
- The ingestion process (if run separately via ingest.py) sets up the document database (or vector indexing) that the UI and retrieval logic will use.

##### Important Architectural Patterns
- Layered Architecture: Clearly separate UI/presentation (Streamlit) from ingestion and processing logic.
- Modular Design: The src module, notebooks (as experimental and learning modules), and separate ingestion script illustrate modularity.
- Integration with External Services: Emphasize how external language APIs are integrated into the process.
- Educational Variants: The existence of multiple notebooks demonstrating different retrieval mechanisms suggests a divergence of strategies (perhaps akin to different “plugins” or configuration options) utilized in similar overall workflows.

##### Relevant Technologies & Frameworks
- Python as the main language.
- Streamlit for the front-end web app.
- LangChain (implicitly used within src/langchain_docs_loader.py and others) for document retrieval chains.
- External NLP APIs from OpenAI, Docugami, and Cohere.
- Poetry & pyenv for dependency and Python version management.
- Jupyter notebooks demonstrating various strategies should be mentioned as experimental/learning modules.

- Start at a high level, then break each piece down into its subcomponents.
- To capture the layered architecture (UI, processing, external services) clearly.
- With technology details, for instance, list “Streamlit” below app.py and “LangChain & Custom Loader” below the core processing module.
- Clearly label any external API integrations and how these are triggered on-demand by the processing layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    subgraph "User Interaction"
        UI["Streamlit UI (app.py)"]:::ui
    end

    %% Backend Processing Layer
    subgraph "Backend Processing"
        ING["Document Ingestion (ingest.py)"]:::backend
        LC["LangChain Integration (src/langchain_docs_loader.py)"]:::backend
    end

    %% External Services Layer
    subgraph "External Services"
        OAI["OpenAI API"]:::external
        DOC["Docugami API"]:::external
        COH["Cohere API"]:::external
    end

    %% Educational Modules Layer
    subgraph "Educational Modules"
        NB_EX["Notebooks (Exercises) (notebooks_ejercicios)"]:::tutorial
        NB_RES["Notebooks (Resolved) (notebooks_resueltas)"]:::tutorial
        DOCS["Documentation & Examples (docs)"]:::tutorial
    end

    %% Relationships: UI to Backend
    UI -->|"submits_query"| LC
    UI -->|"triggers_ingestion"| ING

    %% Data flow from Ingestion to LangChain Integration
    ING -->|"feeds_data"| LC

    %% LangChain Integration interacts with External APIs
    LC -->|"calls_api"| OAI
    LC -->|"calls_api"| DOC
    LC -->|"calls_api"| COH

    OAI -->|"returns_data"| LC
    DOC -->|"returns_data"| LC
    COH -->|"returns_data"| LC

    %% Processed results flow back to UI
    LC -->|"renders_results"| UI

    %% Educational modules demonstrate retrieval strategies
    NB_EX -.->|"demonstrates"| LC
    NB_RES -.->|"demonstrates"| LC
    DOCS -.->|"provides_docs"| UI

    %% Click Events
    click UI "https://github.com/platzi/curso-langchain-qa-documents/blob/main/app.py"
    click ING "https://github.com/platzi/curso-langchain-qa-documents/blob/main/ingest.py"
    click LC "https://github.com/platzi/curso-langchain-qa-documents/blob/main/src/langchain_docs_loader.py"
    click NB_EX "https://github.com/platzi/curso-langchain-qa-documents/tree/main/notebooks_ejercicios"
    click NB_RES "https://github.com/platzi/curso-langchain-qa-documents/tree/main/notebooks_resueltas"
    click DOCS "https://github.com/platzi/curso-langchain-qa-documents/tree/main/docs"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFEFD5,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef tutorial fill:#FFB6C1,stroke:#000,stroke-width:2px;
```
