Architecture for the enterprise

A robust, secure and scalable system: local users, personal workspaces, data connectors and isolated RAG for every account.

Complete RAG pipeline

Client
Web UI
WordPress Plugin
REST API
Flask
Multi-user auth
WorkspaceContext
Encrypted SecretStore
Workspace API keys
Ingestion
IMAP Email
Microsoft Drive
Rate limiting
RQ Jobs
RAG
Document Processing
Collection per workspace
Diversity + Reranking
Conversation Memory
LLM
Regolo.ai
Mistral AI
Local (Ollama, vLLM)

How each component works

๐Ÿ“„

Document Processing

PDF, TXT, Markdown and audio are automatically chunked. Manual uploads and connector snapshots land in the right workspace, with source metadata tracked.

๐Ÿ”

Retrieval + Candidate Diversity

Vector similarity on dedicated Chroma collections per workspace. Optional Source Diversity or MMR selects better candidates before BGE local, Regolo remote, or custom reranking. Namespaced cache prevents leakage.

๐Ÿ’ฌ

Conversation Memory

Contextual chat with auto-summary, namespaced by user and conversation. When history exceeds threshold, older messages are compressed into a summary.

๐ŸŽ™๏ธ

Audio Pipeline

Upload audio โ†’ STT (OpenAI-compatible) โ†’ automatic indexing. TTS for spoken responses. Supports MP3, WAV, M4A, WEBM, FLAC.

๐Ÿ”‘

Security

Local users with admin/user roles, password hashes, scoped API keys per workspace, encrypted connector SecretStore, rate limiting, input validation and XSS sanitization.

๐Ÿš€

Performance

Gunicorn async with thread pool, real-time NDJSON streaming, LRU retrieval cache, embedding caching, retry with backoff on provider failure.

Code you can read

# Main stack
Backend: Flask 3.1, Python 3.11+
Auth: JSON UserStore + personal workspaces
Vector DB: ChromaDB (persistent)
Embedding: sentence-transformers / Regolo cloud
Candidate selection: none / Source Diversity / MMR
Reranker: BAAI bge-reranker / Regolo / custom
LLM: Regolo.ai, Mistral, OpenAI-compatible
Server: Gunicorn (production)
Frontend: Flask templates + Vanilla JS
Ingestion: IMAP Email + Microsoft Graph
Plugin: WordPress PHP + workspace S2S API calls

REST API, streaming and more

๐Ÿ“ก

Endpoints

/api/v1/query, /api/v1/health, /api/v1/files, /api/v1/audio, /api/v1/tts, /api/v1/models

REST JSON OpenAPI
๐ŸŒŠ

Streaming

Token-by-token streaming in NDJSON. Meta events with model info, source references and token usage.

NDJSON SSE Real-time
๐Ÿ”‘

Granular Auth

API keys with scopes: query, ingest, speech. Every key always resolves to one user and one workspace.

Scoped API Keys Session

Robust single-server, ready to grow

RAGuardian scales from a single Gunicorn worker to a multi-process runtime with Redis, keeping user isolation, the same public APIs and zero state loss.

๐Ÿ—„๏ธ

Shared state with Redis

Rate limiter, retrieval cache, conversation memory, job state and active lock move to Redis. In-memory fallback for dev. No changes to public endpoints: only the storage layer changes.

โš™๏ธ

Non-blocking job queue

Index rebuild, PDF/audio upload and transcription become async jobs (RQ on Redis). User queries are never blocked by ingest. Admin shows status via polling; API returns 202 + job_id with ?async=true.

๐ŸŽ๏ธ

Scalable Gunicorn

Production default: workers=1, threads=16. Advanced profile: 2-4 workers, 8-16 threads after load testing. Multi-worker safe only with Redis: no lost conversations or jobs.

๐Ÿง 

Vector store adapter

Internal VectorStore interface with Chroma PersistentClient implementation. Ready for Qdrant, Chroma HTTP or managed vector DB when load tests require it. Zero refactoring at switch time.

๐Ÿ“Š

Load testing & observability

Locust suite: 50 concurrent users on queries, streaming, ingest and parallel rebuild. Metrics: error rate, p50/p95/p99 latency, queue depth, job time, CPU/RAM, separate Chroma and LLM latency.

๐Ÿฉบ

Health & readiness

/api/v1/health includes: redis_ready, queue_ready, queue_depth, active_jobs_count. Your orchestrator always knows if the service is ready and overloaded.

๐Ÿ“ Decision criterion

Chroma local stays as the initial vector store. Switching to Chroma server, Qdrant or managed vector DB only happens after real load tests identify the bottleneck. No premature optimization, only data-driven decisions.

# Production runtime
$ gunicorn -c gunicorn.conf.py wsgi:application
$ rq worker rag-default
# Redis: required for multi-worker scaling
# In-memory fallback: OK for dev/testing

Go deeper

Read the code on GitHub, explore API documentation and plan deployment.