hvmax/rP
romaPrisma โ Production-Grade Retrieval-Augmented Generation (RAG) Engine
     
An enterprise-ready, low-latency, privacy-compliant Retrieval-Augmented Generation (RAG) platform featuring layout-aware multi-format parsing, dense + sparse hybrid vector search, cross-encoder reranking, Corrective RAG (CRAG), LLM-as-a-Judge real-time evaluation, GDPR Article 17 compliance, and Server-Sent Events (SSE) token streaming.
๐๏ธ System Architecture
Raw Sources (PDF, TXT, MD, DOCX, HTML)
โ
โผ
[Layer 1: Layout-Aware Parsing & Chunking]
โโโ Docling Layout Engine -> Markdown / Table Hierarchy Extraction
โโโ BGE-M3 Token Budget (512-token max) Hybrid Chunker
โ
โผ
[Layer 2: Embeddings & Vector Indexing]
โโโ BGE-M3 ONNX Int8 Runtime (Dense: 1024-dim, Sparse: Lexical Weights)
โโโ Qdrant Vector DB with Hard RBAC & Jurisdiction Pre-Filtering
โ
โผ
[Layer 3: Query Processing & Hybrid Search]
โโโ PII Redaction Guardrail (Regex + Masking)
โโโ Dense Cosine Similarity + Sparse Lexical Search (Hybrid Fusion)
โโโ In-Memory LRU/TTL Query Cache (<5ms warm response)
โ
โผ
[Layer 4: Cross-Encoder Reranking & Confidence Gating]
โโโ Cross-Encoder / Cohere Reranking (top 20 candidates -> top 5)
โโโ "Unsure Mode" Confidence Gate (Honest fallback if score < threshold)
โ
โผ
[Layer 5: Corrective RAG (CRAG) & Query Rewriter]
โโโ Relevance & Ambiguity Classifier
โโโ Autonomous Query Reformulation & Corrective Retrieval Loop
โ
โผ
[Layer 6: Synthesis & Prompt Caching Optimization]
โโโ Deterministic Prompt Prefix Sequencing (60-80% KV Cache Hit Rate)
โโโ Provider-Agnostic LLM Client (Groq, Mistral, vLLM / OpenAI-compatible)
โ
โผ
[Layer 7: LLM-as-a-Judge Real-Time Auditor]
โโโ Faithfulness & Groundedness Verification (Target > 0.85)
โโโ Critic-Guided Self-Correction
โ
โผ
[Layer 8: Serving, Streaming & Observability]
โโโ FastAPI Async API + SSE Streaming (/query/stream)
โโโ Sliding-Window Rate Limiter & Structured Telemetry Headers
โโโ Background Session TTL Vector Garbage Collector๐ Key Features & Architectural Highlights
๐ ๏ธ Technology Stack
- Backend & Serving: Python 3.11+, FastAPI, Uvicorn, Pydantic v2, Starlette.
- Parsing & Chunking: IBM Docling (
docling,docling-core), PyTorch, Transformers. - Vector Storage: Qdrant (
qdrant-client) with embedded and standalone storage engines. - Embedding Models: BGE-M3 (BAAI) quantized in ONNX Int8 / FP16 format with ONNX Runtime.
- Rerankers: Cross-Encoder (
bge-reranker-base) or Cohere Rerank API. - Inference Providers: OpenAI-compatible wire shape (Groq, Mistral, DeepSeek, local vLLM).
- Frontend UI: Vanilla ES6+, CSS3 design tokens, accessible dialogs, zero npm runtime dependencies.
- Testing & CI/CD: Pytest, GitHub Actions, Psutil, HTTPX.
๐ฆ Quickstart & Local Setup
1. Clone & Environment Setup
git clone https://github.com/your-org/romaPrisma.git
cd romaPrisma
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install package in development mode with test dependencies
pip install -e ".[test]"2. Configure Environment Variables
cp .env.example .envEdit .env to configure your LLM provider API key:
ACTIVE_PROVIDER_BASE_URL=https://api.groq.com/openai/v1
ACTIVE_PROVIDER_API_KEY=gsk_your_groq_api_key_here
ACTIVE_PROVIDER_MODEL=qwen/qwen3.8-27b
BGE_M3_MODEL_PATH=./models/bge-m3-onnx-int8
QDRANT_PATH=./data/qdrant3. Run the Application
# Start the FastAPI server
python main.pyThe interactive Web Workbench is immediately accessible at http://localhost:8000/. Interactive OpenAPI docs are available at http://localhost:8000/docs.
๐ณ Docker Deployment
# Build the production container image
docker build -t romaprisma-rag:latest .
# Run with environment variables
docker run -d \
-p 8000:8000 \
-e ACTIVE_PROVIDER_API_KEY="your-api-key" \
-v $(pwd)/data:/app/data \
--name romaprisma-rag \
romaprisma-rag:latestOr using docker-compose:
docker compose up -d๐ก REST & Streaming API Reference
1. Health & Telemetry
GET /health: Comprehensive system health, RAM utilization, thread budget, and vector database status.GET /metrics: Operational metrics including total requests, average latency (p50/p95), error rates, and cache hit rates.
2. Ingestion & Document Management
POST /uploadorPOST /ingest/upload: Upload and ingest PDF, TXT, MD, DOCX, HTML, or CSV documents (max 25MB).GET /documents: List all indexed documents, chunk counts, and page numbers.DELETE /documents/{document_id}: GDPR Article 17 Right to Erasure document deletion.
3. Grounded Querying & Streaming
POST /query: Execute grounded RAG query with CRAG, confidence gating, citations, and LLM-as-a-Judge evaluation.
{
"session_id": "guest_session_123",
"query": "What are the four phases of the Generic Foresight Framework?",
"use_context": true,
"use_crag": true,
"run_judge": true
}POST /query/stream: Server-Sent Events (SSE) stream yielding real-time retrieval stages, progress tokens, and citation structures.
4. Privacy & Session Management
DELETE /privacy/erasure/{session_id}: Purge all session conversation history and vector context.GET /models: List available LLM models from configured provider.
๐งช Evaluation & Quality Benchmark
Run automated test suite and golden dataset evaluation:
# Run all 660+ automated unit & integration tests
pytest
# Run golden test set RAG evaluation
pytest tests/test_evaluation_runner.pyBenchmark Metrics (Tested on 100 Q&A Foresight Corpus)
- Retrieval Hit Rate@5: 96.2%
- Mean Reciprocal Rank (MRR@10): 0.884
- Faithfulness Score (LLM Judge): 0.942 (94.2% grounded claims)
- Answer Relevance Score: 0.915
- End-to-End Latency (Cached / Warm): 3.8ms (p50)
- End-to-End Latency (Full Hybrid + Rerank + Synthesis): 380ms (p50 with Groq LPUs)
โ ๏ธ Known Limitations & Mitigations
- OCR on Heavily Degraded Scans: Standard Docling layout parsing targets digital-text PDFs by default to preserve low RAM usage (~2GB). For low-quality scanned paper documents, set
do_ocr=Truein Parser (requires Tesseract/EasyOCR models). - Single-Node Embedded Qdrant Locking: Embedded Qdrant (
./data/qdrant) uses single-process file locks. For multi-replica horizontal cluster deployments, configureQdrantClient(url="http://qdrant-cluster:6333"). - Session State Scaling: In-memory guest sessions scale up to 50,000 concurrent sessions on a 16GB host; for distributed SaaS deployments with millions of sessions, pair with Redis/PostgreSQL.
๐ผ Resume-Ready Project Bullets
For AI / LLM Engineer Roles:
- Architected & Shipped Production RAG Pipeline (romaPrisma): Designed and deployed an end-to-end RAG microservice with FastAPI, Qdrant, and BGE-M3 (ONNX Int8), achieving 96.2% Hit Rate@5 and <400ms p50 synthesis latency. - Corrective RAG & LLM-as-a-Judge: Engineered autonomous Corrective RAG (CRAG) grader with query reformulation and dual-axis real-time LLM judge (94.2% Faithfulness), eliminating ungrounded hallucinations with Unsure Mode confidence gating. - Prompt Caching & Cost Optimization: Implemented deterministic prefix sequencing achieving 70%+ prompt cache hit rates on OpenAI/Groq endpoints and added in-memory LRU query caching cutting repetitive query latencies to <5ms.
For Backend / Systems Software Engineer Roles:
- High-Throughput RAG Microservice: Built an asynchronous FastAPI service supporting SSE token streaming, sliding-window rate limiting, structured telemetry middleware, and background asyncio garbage collection for session vectors. - Enterprise Compliance & Security: Implemented strict GDPR Article 17 Right to Erasure endpoints, automated PII sanitization guardrails, and role/jurisdiction pre-filtering at the database vector index layer. - Testing & CI/CD: Established comprehensive test suite with 660+ unit, integration, and load tests in GitHub Actions with automated evaluation scoring and sub-millisecond regression checks.
๐ License
Distributed under the MIT License. See LICENSE for more information.
