How 2bhavyasodhi7/hybrid_rag works
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 app.py · rag_chain.py RAG chain · pdf_processor.py PDF processor · embedding_manager.py Embeddings
Components 22
Presentation
Streamlit entrypoint and UI components
- app.py · Main Streamlit runtime entrypoint
app.py - Chat · Main conversational interface
ui/chat_interface.py - Sidebar · Controls and navigation
ui/sidebar.py - Filters · Query and result filtering controls
ui/filter_buttons.py - Metrics · Summary and telemetry-style dashboard UI
ui/dashboard_metrics.py - Styles · Visual styling for the app
ui/styles.py
Core
RAG orchestration, retrieval, memory, and model access
Ingestion
Document processing and indexing pipeline
- ingest.py · Offline or batch ingestion entrypoint
ingest.py - PDF processor · Routes PDFs into modality-specific processing
core/pdf_processor.py - Text pipeline · Text extraction and chunking
core/text_pipeline.py - Image pipeline · Image-oriented extraction or enrichment
core/image_pipeline.py - Table pipeline · Tabular data extraction and normalization
core/table_pipeline.py - Embeddings · Generates embeddings for processed content
core/embedding_manager.py - Vector store · Persists and queries embedded knowledge
core/vectorstore_manager.py
Integrations
External multimodal APIs and shared helpers
- Google AI · Google-based multimodal understanding support
utils/google_ai_mode_api.py - Google Lens · Image-based lookup or enrichment utility
utils/google_lens_api.py - Helpers · Common glue code and transformations
utils/helpers.py
Config
Runtime and application settings
- Config TOML · Streamlit presentation and runtime configuration
.streamlit/config.toml - Settings · Central application configuration
config/settings.py
Connections 30
- 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