# 2bhavyasodhi7/hybrid_rag architecture

> Architecture diagram of the GitHub repository 2bhavyasodhi7/hybrid_rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/2bhavyasodhi7/hybrid_rag
- Repository: https://github.com/2bhavyasodhi7/hybrid_rag

## Overview

1. **Overall shape**
   - This repository is a **Streamlit-based hybrid RAG application**. The architecture splits cleanly into:
     - a UI layer for interaction,
     - a document ingestion and parsing layer,
     - retrieval/LLM orchestration,
     - and supporting utilities for Google-based multimodal APIs.

2. **Primary entrypoint**
   - `app.py` is the runtime entrypoint for the Streamlit app.
   - The `.streamlit/config.toml` file indicates Streamlit-specific app configuration and presentation settings.

3. **UI layer**
   - The `ui/` package contains the user-facing components:
     - `chat_interface.py` for the main conversational experience,
     - `sidebar.py` for controls and app navigation,
     - `filter_buttons.py` for query/result filtering,
     - `dashboard_metrics.py` for summary/telemetry-style UI,
     - `styles.py` for visual styling.
   - This layer appears to be mostly presentation and user interaction, with business logic delegated to `core/`.

4. **Ingestion and document processing**
   - `ingest.py` is the likely entrypoint for offline or batch document ingestion.
   - `core/pdf_processor.py` suggests PDFs are a central source format.
   - The processing layer is split by modality:
     - `text_pipeline.py` for text extraction/chunking,
     - `image_pipeline.py` for image-oriented extraction or enrichment,
     - `table_pipeline.py` for tabular data extraction,
     - `pdf_processor.py` as the document-level orchestrator.
   - This is the key boundary where raw documents become structured retrieval assets.

5. **Embedding and vector storage**
   - `core/embedding_manager.py` handles generation of embeddings.
   - `core/vectorstore_manager.py` manages persistence and access to the vector index/store.
   - Together, these form the indexing side of the RAG system: processed content is embedded and stored for later similarity search.

6. **Retrieval layer**
   - `core/retriever.py` is the search boundary between stored knowledge and downstream generation.
   - `core/rag_chain.py` likely coordinates retrieval results with prompt construction and response generation.
   - The architecture suggests hybrid retrieval, meaning multiple content types or retrieval strategies may be combined before passing context to the LLM.

7. **LLM and memory orchestration**
   - `core/llm_manager.py` abstracts model access and response generation.
   - `core/memory_manager.py` manages conversational state or context continuity across turns.
   - This makes the chat experience stateful rather than single-shot QA, with memory feeding into the RAG chain.

8. **Multimodal / Google API utilities**
   - `utils/google_ai_mode_api.py` and `utils/google_lens_api.py` indicate integration with Google services for multimodal understanding or image-based lookup.
   - These utilities likely support the image/document side of the hybrid pipeline, especially where OCR-like or visual enrichment is needed.
   - `utils/helpers.py` likely contains shared glue code and common transformations.

9. **Configuration boundary**
   - `config/settings.py` is the central configuration module.
   - `config/__init__.py` suggests the rest of the app imports settings through a single config boundary, which is useful for keys, model names, paths, and environment-specific behavior.

10. **Runtime data flow**
   - The two main flows are:
     - **offline ingestion**: documents → PDF processor → modality pipelines → embeddings → vector store,
     - **online query handling**: user query in Streamlit → chat UI → retriever/RAG chain → LLM → response rendered back to UI.
   - Memory can sit alongside the query path to preserve conversational context across turns.

11. **Important architectural boundary**
   - `core/` contains the application logic and should be treated as the functional backend.
   - `ui/` is only the presentation layer.
   - `utils/` contains external integrations and helper functions.
   - `config/` isolates environment and runtime configuration.
   - This separation makes the system easy to diagram as four main zones: UI, orchestration, ingestion/indexing, and external services.

12. **Likely external dependencies**
   - Based on file names and the Streamlit configuration, the app almost certainly depends on:
     - Streamlit for the front end,
     - a vector database or vector index implementation for retrieval,
     - an embedding provider and an LLM provider,
     - and Google APIs for image/multimodal support.
   - These external pieces are architecturally important because they define the system’s runtime dependencies and data boundaries.

13. **How to draw the diagram**
   - A good architecture diagram would show:
     - user ↔ Streamlit UI,
     - UI ↔ RAG orchestration layer,
     - ingestion pipeline feeding the vector store,
     - retriever pulling context from the vector store,
     - LLM producing answers,
     - optional Google-based utilities supporting image-related enrichment,
     - and configuration controlling all components.

Main entry points: [`app.py`](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/app.py) (app.py), [`core/rag_chain.py`](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/rag_chain.py) (RAG chain), [`core/pdf_processor.py`](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/pdf_processor.py) (PDF processor), [`core/embedding_manager.py`](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/embedding_manager.py) (Embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_app_py["app.py<br/>streamlit app<br/>[app.py]"]
  node_chat_interface["Chat<br/>ui component<br/>[chat_interface.py]"]
  node_sidebar["Sidebar<br/>ui component<br/>[sidebar.py]"]
  node_filter_buttons["Filters<br/>ui component<br/>[filter_buttons.py]"]
  node_dashboard_metrics["Metrics<br/>ui component"]
  node_styles["Styles<br/>ui styling<br/>[styles.py]"]
end

subgraph group_core["Core"]
  node_rag_chain["RAG chain<br/>orchestrator<br/>[rag_chain.py]"]
  node_retriever["Retriever<br/>retrieval<br/>[retriever.py]"]
  node_llm_manager["LLM<br/>[llm_manager.py]"]
  node_memory_manager["Memory<br/>[memory_manager.py]"]
end

subgraph group_ingestion["Ingestion"]
  node_ingest_py["ingest.py<br/>ingest entrypoint<br/>[ingest.py]"]
  node_pdf_processor["PDF processor<br/>document orchestrator<br/>[pdf_processor.py]"]
  node_text_pipeline["Text pipeline<br/>text extraction<br/>[text_pipeline.py]"]
  node_image_pipeline["Image pipeline<br/>image enrichment<br/>[image_pipeline.py]"]
  node_table_pipeline["Table pipeline<br/>table extraction<br/>[table_pipeline.py]"]
  node_embedding_manager["Embeddings<br/>embedding manager"]
  node_vectorstore_manager[("Vector store<br/>vector index")]
end

subgraph group_integrations["Integrations"]
  node_google_ai_mode_api["Google AI<br/>multimodal api"]
  node_google_lens_api["Google Lens<br/>visual lookup<br/>[google_lens_api.py]"]
  node_helpers["Helpers<br/>shared utils<br/>[helpers.py]"]
end

subgraph group_config["Config"]
  node_streamlit_config["Config TOML<br/>streamlit config<br/>[config.toml]"]
  node_settings["Settings<br/>config<br/>[settings.py]"]
end

node_streamlit_config -.->|"configures"| node_app_py
node_settings -.->|"configures"| node_app_py
node_settings -.->|"configures"| node_rag_chain
node_settings -.->|"configures"| node_ingest_py
node_settings -.->|"configures"| node_embedding_manager
node_app_py -->|"renders"| node_chat_interface
node_app_py -->|"renders"| node_sidebar
node_app_py -->|"renders"| node_filter_buttons
node_app_py -->|"renders"| node_dashboard_metrics
node_app_py -->|"applies"| node_styles
node_chat_interface -->|"queries"| node_rag_chain
node_sidebar -->|"controls"| node_rag_chain
node_filter_buttons -->|"filters"| node_chat_interface
node_dashboard_metrics -->|"summarizes"| node_chat_interface
node_rag_chain -->|"retrieves"| node_retriever
node_rag_chain -->|"generates"| node_llm_manager
node_rag_chain -->|"tracks"| node_memory_manager
node_retriever -->|"searches"| node_vectorstore_manager
node_ingest_py -->|"ingests"| node_pdf_processor
node_pdf_processor -->|"extracts"| node_text_pipeline
node_pdf_processor -->|"extracts"| node_image_pipeline
node_pdf_processor -->|"extracts"| node_table_pipeline
node_text_pipeline -->|"embeds"| node_embedding_manager
node_image_pipeline -->|"enriches"| node_google_ai_mode_api
node_image_pipeline -->|"looks up"| node_google_lens_api
node_image_pipeline -->|"embeds"| node_embedding_manager
node_table_pipeline -->|"embeds"| node_embedding_manager
node_embedding_manager -->|"indexes"| node_vectorstore_manager
node_helpers -->|"supports"| node_pdf_processor
node_helpers -->|"supports"| node_rag_chain

click node_app_py "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/app.py"
click node_streamlit_config "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/.streamlit/config.toml"
click node_chat_interface "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/chat_interface.py"
click node_sidebar "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/sidebar.py"
click node_filter_buttons "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/filter_buttons.py"
click node_dashboard_metrics "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/dashboard_metrics.py"
click node_styles "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/styles.py"
click node_rag_chain "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/rag_chain.py"
click node_retriever "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/retriever.py"
click node_llm_manager "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/llm_manager.py"
click node_memory_manager "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/memory_manager.py"
click node_ingest_py "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ingest.py"
click node_pdf_processor "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/pdf_processor.py"
click node_text_pipeline "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/text_pipeline.py"
click node_image_pipeline "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/image_pipeline.py"
click node_table_pipeline "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/table_pipeline.py"
click node_embedding_manager "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/embedding_manager.py"
click node_vectorstore_manager "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/vectorstore_manager.py"
click node_google_ai_mode_api "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/google_ai_mode_api.py"
click node_google_lens_api "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/google_lens_api.py"
click node_helpers "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/helpers.py"
click node_settings "https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/config/settings.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_py,node_chat_interface,node_sidebar,node_filter_buttons,node_dashboard_metrics,node_styles toneBlue
class node_rag_chain,node_retriever,node_llm_manager,node_memory_manager toneAmber
class node_ingest_py,node_pdf_processor,node_text_pipeline,node_image_pipeline,node_table_pipeline,node_embedding_manager,node_vectorstore_manager toneMint
class node_google_ai_mode_api,node_google_lens_api,node_helpers toneRose
class node_streamlit_config,node_settings toneIndigo
```

## Components

### Presentation

Streamlit entrypoint and UI components

- [app.py](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/app.py): streamlit app · Main Streamlit runtime entrypoint · `app.py`
- [Chat](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/chat_interface.py): ui component · Main conversational interface · `ui/chat_interface.py`
- [Sidebar](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/sidebar.py): ui component · Controls and navigation · `ui/sidebar.py`
- [Filters](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/filter_buttons.py): ui component · Query and result filtering controls · `ui/filter_buttons.py`
- [Metrics](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/dashboard_metrics.py): ui component · Summary and telemetry-style dashboard UI · `ui/dashboard_metrics.py`
- [Styles](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ui/styles.py): ui styling · Visual styling for the app · `ui/styles.py`

### Core

RAG orchestration, retrieval, memory, and model access

- [RAG chain](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/rag_chain.py): orchestrator · Coordinates retrieval, memory, and generation · `core/rag_chain.py`
- [Retriever](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/retriever.py): retrieval · Search boundary over indexed knowledge · `core/retriever.py`
- [LLM](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/llm_manager.py): llm manager · Model access and response generation · `core/llm_manager.py`
- [Memory](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/memory_manager.py): conversation memory · Conversation state and context continuity · `core/memory_manager.py`

### Ingestion

Document processing and indexing pipeline

- [ingest.py](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/ingest.py): ingest entrypoint · Offline or batch ingestion entrypoint · `ingest.py`
- [PDF processor](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/pdf_processor.py): document orchestrator · Routes PDFs into modality-specific processing · `core/pdf_processor.py`
- [Text pipeline](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/text_pipeline.py): text extraction · Text extraction and chunking · `core/text_pipeline.py`
- [Image pipeline](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/image_pipeline.py): image enrichment · Image-oriented extraction or enrichment · `core/image_pipeline.py`
- [Table pipeline](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/table_pipeline.py): table extraction · Tabular data extraction and normalization · `core/table_pipeline.py`
- [Embeddings](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/embedding_manager.py): embedding manager · Generates embeddings for processed content · `core/embedding_manager.py`
- [Vector store](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/core/vectorstore_manager.py): vector index · Persists and queries embedded knowledge · `core/vectorstore_manager.py`

### Integrations

External multimodal APIs and shared helpers

- [Google AI](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/google_ai_mode_api.py): multimodal api · Google-based multimodal understanding support · `utils/google_ai_mode_api.py`
- [Google Lens](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/google_lens_api.py): visual lookup · Image-based lookup or enrichment utility · `utils/google_lens_api.py`
- [Helpers](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/utils/helpers.py): shared utils · Common glue code and transformations · `utils/helpers.py`

### Config

Runtime and application settings

- [Config TOML](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/.streamlit/config.toml): streamlit config · Streamlit presentation and runtime configuration · `.streamlit/config.toml`
- [Settings](https://github.com/2bhavyasodhi7/hybrid_rag/blob/main/config/settings.py): config · Central application configuration · `config/settings.py`

## Connections

- Config TOML → app.py: configures · Streamlit settings shape app runtime and presentation
- Settings → app.py: configures · Application settings are consumed by the Streamlit entrypoint
- Settings → RAG chain: configures · Model, path, and runtime settings flow into orchestration
- Settings → ingest.py: configures · Ingestion behavior is driven by central settings
- Settings → Embeddings: configures · Embedding provider and related parameters come from settings
- app.py → Chat: renders · Entrypoint mounts the main chat experience
- app.py → Sidebar: renders · Entrypoint includes sidebar controls
- app.py → Filters: renders · Entrypoint includes filtering controls
- app.py → Metrics: renders · Entrypoint includes dashboard summaries
- app.py → Styles: applies · App loads shared visual styling
- Chat → RAG chain: queries · Chat UI sends user questions to the RAG backend
- Sidebar → RAG chain: controls · Sidebar settings influence retrieval or chat behavior
- Filters → Chat: filters · Filters refine displayed questions or results
- Metrics → Chat: summarizes · Metrics reflect chat and retrieval activity
- RAG chain → Retriever: retrieves · Orchestrator fetches supporting context
- RAG chain → LLM: generates · Orchestrator delegates answer generation to the LLM layer
- RAG chain → Memory: tracks · Conversation state is incorporated into the chain
- Retriever → Vector store: searches · Retriever reads from the vector index
- ingest.py → PDF processor: ingests · Batch ingestion starts with document processing
- PDF processor → Text pipeline: extracts · PDF processing routes text to the text pipeline
- PDF processor → Image pipeline: extracts · PDF processing routes images to the image pipeline
- PDF processor → Table pipeline: extracts · PDF processing routes tables to the table pipeline
- Text pipeline → Embeddings: embeds · Processed text is converted into embeddings
- Image pipeline → Google AI: enriches · Image processing can call multimodal Google support
- Image pipeline → Google Lens: looks up · Image processing can use visual lookup support
- Image pipeline → Embeddings: embeds · Image-derived content is embedded for retrieval
- Table pipeline → Embeddings: embeds · Structured table content is embedded for indexing
- Embeddings → Vector store: indexes · Embeddings are persisted to the vector store
- Helpers → PDF processor: supports · Shared utilities assist document processing
- Helpers → RAG chain: supports · Shared utilities assist orchestration and formatting
