How mihirmaru22/global_mind works
Purpose and entry points
GlobleMind/LocalMind is a FastAPI-backed RAG system for ingesting enterprise documents, performing hybrid retrieval, and streaming cited answers. Primary runtime entry point: src/main.py; command-line entry point: src/cli.py. The built React SPA is served by the backend from frontend/; editable UI source is under LocalMind_UI/src/main.jsx.
API and interaction boundary
FastAPI separates document ingestion, query execution, and UI/state endpoints:
• src/api/upload.py accepts batch uploads and emits ingestion progress through SSE.
• src/api/query.py exposes RAG queries with metadata filters.
• src/api/ui.py supports chat CRUD, persisted settings, document listing, provider selection, and UI-oriented streaming.
The browser communicates through LocalMind_UI/src/services/api.js; client-wide chat/session state is held in LocalMind_UI/src/store/store.js.
Ingestion orchestration and identity
src/pipeline/ingestion.py coordinates the sequential stages and should only commit successful documents. src/core/ingestion_registry.py establishes SHA-256 content-addressed identity, preventing duplicate processing while allowing same-named but different files. src/pipeline/folder_ingestion.py is the boundary for inbox scanning and concurrent folder ingestion. Uploaded/path-derived files are protected by src/core/paths.py.
Document transformation pipeline
The ingestion pipeline is decomposed into atomic stages:
• Detect/classify/parse: src/stages/s01_file_detection.py, src/stages/s02_classification.py, src/stages/s03_parsing.py.
• Enrich difficult content through OCR, layout, tables, and visual descriptions: src/stages/s04_ocr.py, src/stages/s05_layout.py, src/stages/s06_tables.py, src/stages/s07_s08_visuals.py.
• Build indexable records through chunking, embeddings, and vector commit: src/stages/s09_chunking.py, src/stages/s10_embeddings.py, src/stages/s11_vector_store.py.
Typed cross-stage contracts reside in src/models/schemas.py; extraction quality is gated by src/core/confidence.py.
Query, retrieval, and generation
src/pipeline/query.py controls the answer path: embed query, hybrid dense/sparse retrieval, rerank, context construction, and streaming generation. Retrieval/generation behavior is consolidated in src/stages/s12_s13_s14_retrieval.py; Jina supplies embeddings and cross-encoder reranking, while Qdrant provides dense+sparse vector storage and Reciprocal Rank Fusion. Answers stream over SSE and are rendered with Markdown, citations, thinking traces, and diagrams in LocalMind_UI/src/components/Message.jsx, LocalMind_UI/src/components/ThinkingTrace.jsx, and LocalMind_UI/src/components/MermaidDiagram.jsx.
Provider resiliency and configuration
src/core/provider_client.py implements provider routing across Gemini, Groq, NVIDIA NIM, OpenRouter, and Jina-dependent capabilities. It applies task-specific chains defined in config/providers.yaml, optional session soft-pinning, and fallback on provider failures. src/core/rate_limiter.py tracks free-tier RPM/RPD budgets and backoff; src/core/config.py binds environment configuration and operational limits.
Structured-data and persistence boundaries
Optional text-to-SQL is separate from vector RAG: src/stages/s12b_sql_retrieval.py generates and validates read-only SQL, while src/core/db_client.py executes against SQLite or MySQL and src/core/sql_dialects.py defines engine-specific behavior. Application/UI state uses JSON-backed storage via src/core/state.py, while document vectors live in Qdrant; the local SQLite database is only for structured-data retrieval. Deployment targets Python 3.11+, FastAPI, React/Vite, Docker (Dockerfile), and Render (render.yaml).
Main entry points: api.js API client · query.py Query pipeline · s01_file_detection.py Transformation stages · ui.py UI/state API
Components 20
Browser UI
- React SPA · Built UI is served by the backend.
- API client
LocalMind_UI/src/services/api.js - Chat/session state
LocalMind_UI/src/store/store.js - Answer rendering · Renders Markdown, citations, traces, and diagrams.
LocalMind_UI/src/components/Message.jsx
FastAPI boundary
- FastAPI runtime · Serves API routes and built SPA.
src/main.py - Upload API · Accepts batches and reports ingestion progress.
src/api/upload.py - Query API
src/api/query.py - UI/state API · Chat, settings, documents, providers, and UI streaming.
src/api/ui.py
Document ingestion
- Ingestion orchestrator · Commits only successfully processed documents.
src/pipeline/ingestion.py - Document identity · SHA-256 deduplication permits same-named changed files.
src/core/ingestion_registry.py - Transformation stages · Detection, parsing, OCR, layout, tables, visuals, chunking, embeddings, and vector commit.
src/stages/s01_file_detection.py - Stage contracts and quality · Typed records and extraction confidence gates.
src/models/schemas.py - Folder ingestion · Scans and concurrently ingests protected local files.
src/pipeline/folder_ingestion.py
Retrieval and generation
- Query pipeline · Builds context and streams cited answers.
src/pipeline/query.py - Hybrid retrieval and generation · Dense/sparse retrieval, RRF, reranking, and streaming generation.
src/stages/s12_s13_s14_retrieval.py - Text-to-SQL · Generates and validates read-only structured-data queries.
src/stages/s12b_sql_retrieval.py
Providers and storage
- Provider router · Routes and falls back across Gemini, Groq, NVIDIA NIM, OpenRouter, and Jina.
src/core/provider_client.py - Qdrant · Dense and sparse document vectors.
- SQLite / MySQL · Used only for structured-data retrieval.
src/core/db_client.py - JSON application state · Persists UI and application state.
src/core/state.py
Connections 24
- React SPA → API client: uses
- Chat/session state → API client: drives requests
- API client → Upload API: uploads
- API client → Query API: queries
- API client → UI/state API: chat and settings
- Query API → Query pipeline: RAG request
- UI/state API → Query pipeline: UI streaming
- Query pipeline → Hybrid retrieval and generation: retrieve and generate
- Hybrid retrieval and generation → Provider router: embeddings, reranking, LLM
- Hybrid retrieval and generation → Qdrant: hybrid search
- Query pipeline → Text-to-SQL: optional structured query
- Text-to-SQL → SQLite / MySQL: read-only SQL
- Upload API → Ingestion orchestrator: documents and progress
- Folder ingestion → Ingestion orchestrator: local documents
- Ingestion orchestrator → Document identity: deduplicate
- Ingestion orchestrator → Transformation stages: process accepted files
- Transformation stages → Stage contracts and quality: validated records
- Transformation stages → Provider router: enrichment and embeddings
- Transformation stages → Qdrant: commit vectors
- UI/state API → JSON application state: persist UI state
- Query pipeline → Answer rendering: SSE answer stream
- FastAPI runtime → Upload API: mounts
- FastAPI runtime → Query API: mounts
- FastAPI runtime → UI/state API: mounts