# mohamedyaakoubi/rbg-arsii-rag architecture

> Architecture diagram of the GitHub repository mohamedyaakoubi/rbg-arsii-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamedyaakoubi/rbg-arsii-rag
- Repository: https://github.com/mohamedyaakoubi/rbg-arsii-rag

## Overview

This is a bilingual French/English RAG search application for bakery-product technical sheets. Users submit a question through the Streamlit UI or CLI; search embeds query variants, retrieves and ranks fragments by cosine similarity, and returns up to three results. A separate ingestion workflow extracts and chunks PDFs, creates original and enriched embeddings, and stores them in PostgreSQL with pgvector. The README documents entity-aware chunking, bilingual dosage labels, translation, and multi-entity query handling. Those details are represented at their owning modules; unsampled internals are not expanded into unsupported call edges.

Main entry points: [`services/ingestion_data.py`](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/ingestion_data.py) (Ingestion and embedding enrichment), [`services/search_service.py`](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/search_service.py) (Bilingual search and query decomposition), [`database/models.py`](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/database/models.py) (Embedding persistence and cosine search), [`app.py`](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/app.py) (Streamlit UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_streamlit["Streamlit UI<br/>[app.py]"]
  node_cli["Interactive CLI<br/>[main.py]"]
end

subgraph group_retrieval["Semantic retrieval"]
  node_search["Bilingual search and query decomposition<br/>[search_service.py]"]
  node_embedding["Sentence embeddings"]
end

subgraph group_ingestion["PDF ingestion"]
  node_ingestion["Ingestion and embedding enrichment<br/>[ingestion_data.py]"]
  node_pdf_processor["PDF extraction and entity chunking<br/>[pdf_processor.py]"]
end

subgraph group_persistence["Vector persistence"]
  node_models["Embedding persistence and cosine search<br/>[models.py]"]
  node_connection["PostgreSQL connection<br/>[connection_pg.py]"]
  node_postgres[("PostgreSQL with pgvector")]
  node_settings["Runtime configuration<br/>[settings.py]"]
  node_logger["Application logging<br/>[logger.py]"]
end

node_user(("Questioner"))
node_pdf_corpus["Bakery PDF corpus"]

node_user -->|"asks through"| node_streamlit
node_user -->|"asks through"| node_cli
node_streamlit -->|"submits query"| node_search
node_streamlit -->|"requests re-ingestion"| node_ingestion
node_cli -->|"submits query"| node_search
node_cli -->|"starts ingestion"| node_ingestion
node_search -->|"embeds query variants"| node_embedding
node_search -->|"requests cosine search"| node_models
node_pdf_corpus -->|"supplies PDFs"| node_ingestion
node_ingestion -->|"processes PDFs"| node_pdf_processor
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"creates and inserts embeddings"| node_models
node_models -->|"opens database connection"| node_connection
node_connection -->|"connects to"| node_postgres
node_models -->|"stores and ranks vectors"| node_postgres

click node_pdf_corpus "https://github.com/mohamedyaakoubi/rbg-arsii-rag/tree/main/data_pdf"
click node_streamlit "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/app.py"
click node_cli "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/main.py"
click node_search "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/search_service.py"
click node_embedding "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/embedding_service.py"
click node_ingestion "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/ingestion_data.py"
click node_pdf_processor "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/pdf_processor.py"
click node_models "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/database/models.py"
click node_connection "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/database/connection_pg.py"
click node_settings "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/config/settings.py"
click node_logger "https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/utils/logger.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_streamlit,node_cli toneBlue
class node_search,node_embedding toneAmber
class node_ingestion,node_pdf_processor toneMint
class node_models,node_connection,node_postgres,node_settings,node_logger toneRose
class node_user toneIndigo
class node_pdf_corpus toneTeal
```

## Components

### User interfaces

- [Streamlit UI](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/app.py): `app.py`
- [Interactive CLI](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/main.py): `main.py`

### Semantic retrieval

- [Bilingual search and query decomposition](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/search_service.py): `services/search_service.py`
- [Sentence embeddings](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/embedding_service.py): `services/embedding_service.py`

### PDF ingestion

- [Ingestion and embedding enrichment](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/ingestion_data.py): `services/ingestion_data.py`
- [PDF extraction and entity chunking](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/services/pdf_processor.py): `services/pdf_processor.py`

### Vector persistence

- [Embedding persistence and cosine search](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/database/models.py): `database/models.py`
- [PostgreSQL connection](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/database/connection_pg.py): `database/connection_pg.py`
- **PostgreSQL with pgvector**
- [Runtime configuration](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/config/settings.py): `config/settings.py`
- [Application logging](https://github.com/mohamedyaakoubi/rbg-arsii-rag/blob/main/utils/logger.py): `utils/logger.py`

### Other components

- **Questioner**
- [Bakery PDF corpus](https://github.com/mohamedyaakoubi/rbg-arsii-rag/tree/main/data_pdf): `data_pdf`

## Connections

- Questioner → Streamlit UI: asks through (evidence: `app.py`)
- Questioner → Interactive CLI: asks through (evidence: `main.py`)
- Streamlit UI → Bilingual search and query decomposition: submits query (evidence: `app.py`)
- Streamlit UI → Ingestion and embedding enrichment: requests re-ingestion (evidence: `app.py`)
- Interactive CLI → Bilingual search and query decomposition: submits query (evidence: `main.py`)
- Interactive CLI → Ingestion and embedding enrichment: starts ingestion (evidence: `main.py`)
- Bilingual search and query decomposition → Sentence embeddings: embeds query variants (evidence: `services/search_service.py`)
- Bilingual search and query decomposition → Embedding persistence and cosine search: requests cosine search (evidence: `services/search_service.py`)
- Bakery PDF corpus → Ingestion and embedding enrichment: supplies PDFs (evidence: `README.md`)
- Ingestion and embedding enrichment → PDF extraction and entity chunking: processes PDFs (evidence: `services/ingestion_data.py`)
- Ingestion and embedding enrichment → Sentence embeddings: embeds chunks (evidence: `services/ingestion_data.py`)
- Ingestion and embedding enrichment → Embedding persistence and cosine search: creates and inserts embeddings (evidence: `services/ingestion_data.py`)
- Embedding persistence and cosine search → PostgreSQL connection: opens database connection (evidence: `database/models.py`)
- PostgreSQL connection → PostgreSQL with pgvector: connects to (evidence: `database/connection_pg.py`)
- Embedding persistence and cosine search → PostgreSQL with pgvector: stores and ranks vectors (evidence: `database/models.py`)
