How d-nithinteja/ragforge works
1. Purpose and Runtime Entry Points
RAGForge is an API-first, multi-tenant multimodal RAG system: users upload documents, asynchronously ingest text/tables/images, then query scoped document collections through streaming chat. FastAPI starts from src/ragforge/main.py; repository-level launch support is also present in main.py. Route aggregation is centralized in src/ragforge/routes/index.py.
2. API, Authentication, and Tenant Boundary
HTTP routes expose authentication, file lifecycle, processing, and conversations. JWT authentication and database-session injection establish the authenticated user boundary before service execution. User ownership must flow through document, chunk, and conversation operations to enforce isolation.
• src/ragforge/routes/auth_routes.py
• src/ragforge/routes/file_routes.py
• src/ragforge/routes/conversation_routes.py
• src/ragforge/dependencies/auth.py
3. Relational Metadata and Conversation State
SQLAlchemy models persist users, uploaded documents, chunk metadata, conversations, and messages. Documents/chunks track ingestion state and vector linkage; conversations retain selected document IDs and message history. The ORM is designed for SQLite or PostgreSQL, with sessions supplied at request boundaries.
• src/ragforge/db/base.py
• src/ragforge/db/session.py
• src/ragforge/models/document.py
• src/ragforge/models/chunk.py
• src/ragforge/models/conversation.py
4. Upload and Ingestion Pipeline
File APIs delegate storage and processing orchestration to services. Processing runs as FastAPI background work rather than a separate queue. The ingestion stage partitions supported files through Unstructured, classifies multimodal elements, then prepares text, table, and image content for chunking/summarization. This is the primary boundary between raw uploaded files and retrieval-ready records.
• src/ragforge/services/file_service.py
• src/ragforge/services/process_service.py
• src/ragforge/services/ingestion_service.py
• src/ragforge/services/unstructured_service.py
• src/ragforge/routes/process_routes.py
5. Multimodal Enrichment and Hybrid Indexing
Chunks preserve original content in a DocStore-oriented layer while generated summaries become embedded vector records. Text/table summaries use the configured LLM; image processing uses a vision-capable model and base64-oriented content handling. Vector IDs connect SQL chunk metadata to ChromaDB embeddings, allowing metadata filtering and original-content resolution.
• src/ragforge/services/chunk_service.py
• src/ragforge/services/document_service.py
• src/ragforge/services/llm_service.py
• src/ragforge/services/vector_service.py
6. Retrieval-Augmented Conversation Flow
For an authenticated conversation question, retrieval searches vectorized summaries using user and optional conversation-document scope, then resolves originals for high-fidelity context. The RAG chain combines retrieved context, bounded recent history, and system prompts; final assistant messages and citations are persisted against the conversation.
• src/ragforge/services/retrieval_service.py
• src/ragforge/services/rag_chain.py
• src/ragforge/services/conversation_service.py
• src/ragforge/models/message.py
• src/ragforge/config/prompts.py
7. Streaming and External Infrastructure
Generation is token-streamed over SSE, including handling for reasoning tokens and Mermaid sanitization. Material external dependencies are Ollama (default pluggable text/vision LLM backend), Sentence-Transformers embeddings, Unstructured high-resolution parsing, ChromaDB vector storage, and SQLite/PostgreSQL relational storage. Environment-backed Pydantic settings configure these runtime integrations, limits, secrets, and model choices.
• src/ragforge/services/streaming_service.py
• src/ragforge/config/environment.py
• src/ragforge/config/constants.py
Main entry points: session.py SQLAlchemy session · index.py Route aggregation · conversation_routes.py Conversation APIs · chunk_service.py Chunk & document service
Components 20
API boundary
Authenticated HTTP entry points and route composition.
- FastAPI app
src/ragforge/main.py - Route aggregation
src/ragforge/routes/index.py - JWT & session dependency · Establishes authenticated user and database session per request.
src/ragforge/dependencies/auth.py - File APIs
src/ragforge/routes/file_routes.py - Processing APIs
src/ragforge/routes/process_routes.py - Conversation APIs
src/ragforge/routes/conversation_routes.py
Metadata & state
Tenant-owned relational records and conversation state.
- SQLAlchemy session · Supports SQLite or PostgreSQL request-scoped persistence.
src/ragforge/db/session.py - Documents, chunks & conversations · Stores ownership, ingestion state, vector links, selected documents, and messages.
src/ragforge/models/document.py
Ingestion pipeline
Background processing turns uploads into retrieval-ready chunks.
- File lifecycle service
src/ragforge/services/file_service.py - Background processing · Runs ingestion as FastAPI background work.
src/ragforge/services/process_service.py - Multimodal ingestion · Classifies parsed text, tables, and images for enrichment.
src/ragforge/services/ingestion_service.py - Unstructured parsing
src/ragforge/services/unstructured_service.py - Chunk & document service · Preserves originals while preparing multimodal chunks and summaries.
src/ragforge/services/chunk_service.py
Retrieval & generation
Scoped retrieval, context assembly, and streamed answers.
- Scoped retrieval · Filters vector search by user and optional conversation documents.
src/ragforge/services/retrieval_service.py - RAG chain · Combines retrieved originals, prompts, and bounded history.
src/ragforge/services/rag_chain.py - Conversation service · Persists assistant messages and citations.
src/ragforge/services/conversation_service.py - SSE streaming · Streams generation tokens and sanitizes Mermaid output.
src/ragforge/services/streaming_service.py
Runtime infrastructure
Configured external persistence and AI integrations.
- ChromaDB vector index · Stores summary embeddings keyed by vector IDs.
src/ragforge/services/vector_service.py - LLM & embeddings · Ollama text/vision models and Sentence-Transformers embeddings.
src/ragforge/services/llm_service.py - Environment settings · Configures models, secrets, limits, and infrastructure.
src/ragforge/config/environment.py
Connections 28
- FastAPI app → Route aggregation: mounts
- Route aggregation → File APIs: exposes
- Route aggregation → Processing APIs: exposes
- Route aggregation → Conversation APIs: exposes
- File APIs → JWT & session dependency: requires
- Conversation APIs → JWT & session dependency: requires
- JWT & session dependency → SQLAlchemy session: injects
- File APIs → File lifecycle service: delegates
- Processing APIs → Background processing: starts
- File lifecycle service → SQLAlchemy session: persists uploads
- Background processing → Multimodal ingestion: orchestrates
- Multimodal ingestion → Unstructured parsing: partitions files
- Multimodal ingestion → Chunk & document service: sends elements
- Chunk & document service → SQLAlchemy session: writes chunk metadata
- Chunk & document service → ChromaDB vector index: indexes summaries
- Chunk & document service → LLM & embeddings: summarizes content
- Conversation APIs → Conversation service: delegates
- Conversation service → Scoped retrieval: queries with scope
- Scoped retrieval → ChromaDB vector index: searches summaries
- Scoped retrieval → SQLAlchemy session: resolves originals
- Conversation service → RAG chain: builds answer
- RAG chain → LLM & embeddings: generates
- Conversation service → SQLAlchemy session: persists history
- Conversation APIs → SSE streaming: streams SSE
- SSE streaming → RAG chain: streams tokens
- Environment settings → SQLAlchemy session: configures
- Environment settings → ChromaDB vector index: configures
- Environment settings → LLM & embeddings: configures