# rararapi/rag-galirage architecture

> Architecture diagram of the GitHub repository rararapi/rag-galirage, 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/rararapi/rag-galirage
- Repository: https://github.com/rararapi/rag-galirage

## Overview

##### Main Components
- Input/Query Module: Representing where queries are fed (e.g., using sample_query.txt or other user input).
- Preprocessing Module: Where PDF ingestion occurs, text normalization happens (using normalize_text functions), and document splitting is handled (dynamic chunk_size and chunk_overlap settings).
- BM25 Scoring Module: The first-stage screening that quickly estimates document relevance.
- Embedding and Vector Search Module: Implements the secondary screening using embeddings stored in a Chroma vector store for precise retrieval.
- Few-shot Prompting/Answer Generation Module: Uses domain-specific Q&A examples and step-by-step thinking to produce a coherent final answer.
- Logging/Warning Control: Handling deprecation warnings and log levels for operational stability.
- (Optional) Data Refresh Module: The part that re-generates the embedding vector store to ensure the latest data is always in use.

##### Relationships and Interactions
- Flow starts with the Input/Query Module where a query is read.
- This query is passed to the Preprocessing Module to ensure that the input documents are properly ingested and normalized.
- The processed data goes into the BM25 Scoring Module to filter the top relevant documents.
- The documents from BM25 are forwarded to the Embedding and Vector Search Module, which refines the selection based on high-quality vector representations.
- The results are then delivered to the Answer Generation Module that utilizes few-shot prompts to produce the final answer.
- Throughout processing, Logging/Warning Control monitors the process, and the Data Refresh Module ensures the embedding store is up-to-date.

##### Architectural Patterns and Design Principles
- Two-stage retrieval architecture (quick coarse filtering with BM25 followed by fine-grained vector search).
- Modular design allowing each component (query processing, text preprocessing, BM25 search, vector search, and answer generation) to be developed and maintained independently.
- Emphasis on extensibility (such as easily updating prompt examples or dynamically adjusting document chunk sizes).
- Error handling and robustness, especially in components that deal with PDF processing and text normalization.

##### Relevant Technologies and Frameworks
- Python (as indicated by main.py and requirements.txt)
- BM25 algorithms for initial search ranking
- Chroma vector store and embedding libraries for the precision vector search
- Few-shot prompting techniques likely related to language model integrations
- Logging frameworks and custom error handling for PDF processing

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Main Pipeline"
    A["Query Input"]:::input
    B["Preprocessing (PDF Ingestion, Text Normalization, Document Splitting)"]:::processing
    C["BM25 Scorer"]:::processing
    D["Embedding & Vector Search (Chroma, Embeddings)"]:::vector
    E["Few-shot Answer Generation"]:::processing

    A -->|"process"| B
    B -->|"filter"| C
    C -->|"refine"| D
    D -->|"generate"| E
  end

  E -->|"final_output"| F["Final Answer Output"]:::output
  
  G["Logging/Warning Control"]:::logging
  H["Data Refresh Module"]:::processing
  
  %% Ancillary Logging Connections
  B ---|"log"| G
  C ---|"log"| G
  D ---|"log"| G
  E ---|"log"| G

  D -->|"refresh"| H

  I["Dependencies & Config"]:::config
  J["Documentation"]:::doc

  %% Click Events
  click A "https://github.com/rararapi/rag-galirage/blob/main/sample_query.txt"
  click B "https://github.com/rararapi/rag-galirage/blob/main/main.py"
  click C "https://github.com/rararapi/rag-galirage/blob/main/main.py"
  click D "https://github.com/rararapi/rag-galirage/blob/main/main.py"
  click E "https://github.com/rararapi/rag-galirage/blob/main/main.py"
  click I "https://github.com/rararapi/rag-galirage/blob/main/requirements.txt"
  click J "https://github.com/rararapi/rag-galirage/blob/main/README.md"

  %% Style Definitions
  classDef input fill:#F8C471,stroke:#333,stroke-width:2px;
  classDef processing fill:#AED6F1,stroke:#333,stroke-width:2px;
  classDef vector fill:#A9DFBF,stroke:#333,stroke-width:2px;
  classDef logging fill:#D7BDE2,stroke:#333,stroke-width:2px;
  classDef config fill:#F5B7B1,stroke:#333,stroke-width:2px;
  classDef doc fill:#FAD7A0,stroke:#333,stroke-width:2px;
  classDef output fill:#D5F5E3,stroke:#333,stroke-width:2px;
```
