# dev07060/mobile_rag_engine architecture

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

- Interactive diagram: https://gitdiagram.com/dev07060/mobile_rag_engine
- Repository: https://github.com/dev07060/mobile_rag_engine

## Overview

Mobile RAG Engine is a Flutter package whose Rust core supports private, on-device document retrieval. The main workflow is local document input → extraction and chunking → embedding → persistent indexing → hybrid search → hydrated, budgeted context for the host app’s LLM. The graph also preserves collection/index management and the simple RAG API. Dart implementation files are absent from the supplied tree, so the Flutter facade and embedding orchestration are represented only as documented host-app responsibilities; implementation edges are limited to documented or indexed relationships.

Main entry points: [`rust_builder/rust/src/api/source_rag.rs`](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/source_rag.rs) (Source RAG API), [`rust_builder/rust/src/api/hybrid_search.rs`](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/hybrid_search.rs) (Hybrid search), [`rust_builder/rust/src/api/db_pool.rs`](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/db_pool.rs) (SQLite connection pool), [`rust_builder/rust/src/frb_generated.rs`](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/frb_generated.rs) (Flutter Rust bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document ingestion"]
  node_doc_input["Document input"]
  node_parser["Document parser<br/>[document_parser.rs]"]
  node_chunker["Semantic chunker"]
  node_session["Ingest session<br/>[ingest_session.rs]"]
  node_source_api["Source RAG API<br/>[source_rag.rs]"]
  node_tokenizer["Tokenizer<br/>[tokenizer.rs]"]
end

subgraph group_retrieve["Retrieval and context"]
  node_hybrid["Hybrid search<br/>[hybrid_search.rs]"]
  node_bm25["BM25 search<br/>[bm25_search.rs]"]
  node_math["Vector math<br/>[vector_math.rs]"]
  node_simple_rag["Simple RAG API<br/>[simple_rag.rs]"]
  node_context["Context assembly<br/>[source_rag.rs]"]
end

subgraph group_storage["Persistence and indexing"]
  node_hnsw["HNSW index<br/>[hnsw_index.rs]"]
  node_quant["Vector quantization<br/>[vector_quant.rs]"]
  node_db[("SQLite connection pool<br/>[db_pool.rs]")]
  node_mmap[("Memory-mapped store<br/>[mmap_store.rs]")]
  node_migration["Index migration<br/>[migration_meta.rs]"]
end

subgraph group_runtime["Rust and Flutter bridge"]
  node_bridge["Flutter Rust bridge<br/>[frb_generated.rs]"]
end

node_app(("Flutter host app"))
node_embedder["On-device embedder"]

node_app -->|"provides documents"| node_doc_input
node_doc_input -->|"ingests locally"| node_source_api
node_source_api -->|"extracts text"| node_parser
node_parser -->|"chunks text"| node_chunker
node_source_api -->|"prepares ingestion"| node_session
node_session -->|"requests embeddings"| node_embedder
node_embedder -->|"returns vectors"| node_session
node_session -->|"commits chunks"| node_db
node_source_api -->|"persists sources"| node_db
node_app -->|"calls Rust API"| node_bridge
node_bridge -->|"dispatches calls"| node_source_api
node_bridge -->|"dispatches search"| node_hybrid
node_hybrid -->|"runs keyword search"| node_bm25
node_hybrid -->|"runs vector search"| node_hnsw
node_hybrid -->|"reads search data"| node_db
node_hnsw -->|"uses quantization"| node_quant
node_hybrid -->|"scores vectors"| node_math
node_hnsw -.->|"loads mapped index"| node_mmap
node_source_api -->|"assembles context"| node_context
node_context -->|"budgets tokens"| node_tokenizer
node_bridge -->|"dispatches simple API"| node_simple_rag
node_simple_rag -->|"stores documents"| node_db
node_simple_rag -->|"rebuilds keyword index"| node_bm25
node_migration -->|"uses pooled connection"| node_db
node_app -->|"scopes collections"| node_source_api

click node_parser "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/document_parser.rs"
click node_chunker "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/semantic_chunker.rs"
click node_session "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/ingest_session.rs"
click node_bridge "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/frb_generated.rs"
click node_source_api "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/source_rag.rs"
click node_hybrid "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/hybrid_search.rs"
click node_bm25 "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/bm25_search.rs"
click node_hnsw "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/hnsw_index.rs"
click node_quant "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/vector_quant.rs"
click node_math "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/vector_math.rs"
click node_db "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/db_pool.rs"
click node_mmap "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/mmap_store.rs"
click node_simple_rag "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/simple_rag.rs"
click node_tokenizer "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/tokenizer.rs"
click node_context "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/source_rag.rs"
click node_migration "https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/migration_meta.rs"

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_doc_input,node_parser,node_chunker,node_session,node_source_api,node_tokenizer toneBlue
class node_hybrid,node_bm25,node_math,node_simple_rag,node_context toneAmber
class node_hnsw,node_quant,node_db,node_mmap,node_migration toneMint
class node_bridge toneRose
class node_app,node_embedder toneIndigo
```

## Components

### Document ingestion

- **Document input**
- [Document parser](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/document_parser.rs): `rust_builder/rust/src/api/document_parser.rs`
- [Semantic chunker](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/semantic_chunker.rs): `rust_builder/rust/src/api/semantic_chunker.rs`
- [Ingest session](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/ingest_session.rs): `rust_builder/rust/src/api/ingest_session.rs`
- [Source RAG API](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/source_rag.rs): `rust_builder/rust/src/api/source_rag.rs`
- [Tokenizer](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/tokenizer.rs): `rust_builder/rust/src/api/tokenizer.rs`

### Retrieval and context

- [Hybrid search](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/hybrid_search.rs): `rust_builder/rust/src/api/hybrid_search.rs`
- [BM25 search](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/bm25_search.rs): `rust_builder/rust/src/api/bm25_search.rs`
- [Vector math](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/vector_math.rs): `rust_builder/rust/src/api/vector_math.rs`
- [Simple RAG API](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/simple_rag.rs): `rust_builder/rust/src/api/simple_rag.rs`
- [Context assembly](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/source_rag.rs): `rust_builder/rust/src/api/source_rag.rs`

### Persistence and indexing

- [HNSW index](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/hnsw_index.rs): `rust_builder/rust/src/api/hnsw_index.rs`
- [Vector quantization](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/vector_quant.rs): `rust_builder/rust/src/api/vector_quant.rs`
- [SQLite connection pool](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/db_pool.rs): `rust_builder/rust/src/api/db_pool.rs`
- [Memory-mapped store](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/mmap_store.rs): `rust_builder/rust/src/api/mmap_store.rs`
- [Index migration](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/api/migration_meta.rs): `rust_builder/rust/src/api/migration_meta.rs`

### Rust and Flutter bridge

- [Flutter Rust bridge](https://github.com/dev07060/mobile_rag_engine/blob/main/rust_builder/rust/src/frb_generated.rs): `rust_builder/rust/src/frb_generated.rs`

### Other components

- **Flutter host app**
- **On-device embedder**

## Connections

- Flutter host app → Document input: provides documents
- Document input → Source RAG API: ingests locally
- Source RAG API → Document parser: extracts text (evidence: `rust_builder/rust/src/frb_generated.rs`)
- Document parser → Semantic chunker: chunks text (evidence: `rust_builder/rust/src/api/document_parser.rs`)
- Source RAG API → Ingest session: prepares ingestion (evidence: `rust_builder/rust/src/api/ingest_session.rs`)
- Ingest session → On-device embedder: requests embeddings
- On-device embedder → Ingest session: returns vectors
- Ingest session → SQLite connection pool: commits chunks (evidence: `rust_builder/rust/src/api/ingest_session.rs`)
- Source RAG API → SQLite connection pool: persists sources (evidence: `rust_builder/rust/src/api/source_rag.rs`)
- Flutter host app → Flutter Rust bridge: calls Rust API
- Flutter Rust bridge → Source RAG API: dispatches calls (evidence: `rust_builder/rust/src/frb_generated.rs`)
- Flutter Rust bridge → Hybrid search: dispatches search (evidence: `rust_builder/rust/src/frb_generated.rs`)
- Hybrid search → BM25 search: runs keyword search (evidence: `rust_builder/rust/src/api/hybrid_search.rs`)
- Hybrid search → HNSW index: runs vector search (evidence: `rust_builder/rust/src/api/hybrid_search.rs`)
- Hybrid search → SQLite connection pool: reads search data (evidence: `rust_builder/rust/src/api/hybrid_search.rs`)
- HNSW index → Vector quantization: uses quantization (evidence: `rust_builder/rust/src/api/hnsw_index.rs`)
- Hybrid search → Vector math: scores vectors (evidence: `rust_builder/rust/src/api/hybrid_search.rs`)
- HNSW index → Memory-mapped store: loads mapped index (evidence: `rust_builder/rust/src/api/hnsw_index.rs`)
- Source RAG API → Context assembly: assembles context (evidence: `rust_builder/rust/src/api/source_rag.rs`)
- Context assembly → Tokenizer: budgets tokens (evidence: `rust_builder/rust/src/api/source_rag.rs`)
- Flutter Rust bridge → Simple RAG API: dispatches simple API (evidence: `rust_builder/rust/src/frb_generated.rs`)
- Simple RAG API → SQLite connection pool: stores documents (evidence: `rust_builder/rust/src/api/simple_rag.rs`)
- Simple RAG API → BM25 search: rebuilds keyword index (evidence: `rust_builder/rust/src/api/simple_rag.rs`)
- Index migration → SQLite connection pool: uses pooled connection (evidence: `rust_builder/rust/src/api/migration_meta.rs`)
- Flutter host app → Source RAG API: scopes collections
