Loading repository data…
Loading repository data…
Cerno-AI / repository
High-performance RAG system for intelligent document Q&A with hybrid retrieval, GPU acceleration, and citation-backed answers. Upload docs, ask questions, get precise responses.
A high-performance RAG system for intelligent document Q&A
Features • Quick Start • Documentation • Contributing
A high-performance Retrieval-Augmented Generation (RAG) system for intelligent document processing and question-answering. Upload documents in multiple formats and ask questions to get precise, citation-backed answers using state-of-the-art Language Models and hybrid retrieval strategies.
Quick Start: docker compose up --build -d → Visit http://localhost:3000
📖 Full Documentation: See Explanation.md for technical deep-dive
# 1. Clone the repository
git clone https://github.com/cerno-ai/cerno-insight.git
cd cerno-insight
# 2. Set up environment
cp .env.sample .env
# Add your GOOGLE_API_KEY to .env
# 3. Run with Docker (recommended)
docker compose up --build -d
# 4. Access the app
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000/docs
That's it! Upload a document and start asking questions. 🎉
api/
├── core/
│ ├── agent_logic.py # Main orchestration logic
│ ├── agno_agent.py # Direct processing for small docs
│ ├── document_processor.py # Document parsing and chunking
│ ├── embedding_manager.py # GPU-optimized embeddings
│ ├── vector_store.py # Hybrid search implementation
│ ├── query_expander.py # Query enhancement and expansion
│ └── citation_utils.py # Citation management
├── routes/
│ └── ragsys.py # API endpoints for RAG operations
├── main.py # FastAPI application
├── state.py # Global state management
└── settings.py # Configuration
frontend/
├── app/
│ └── page.tsx # Document library interface
├── components/
│ ├── chat-interface.tsx # Q&A chat interface
│ ├── document-library.tsx # Document management UI
│ └── document-viewer.tsx # Document preview with citations
└── lib/
└── api.ts # API client
# GPU Optimization
BATCH_SIZE = 64 # For RTX 4060+
USE_FP16 = True # Half precision for speed
# Retrieval Parameters
MAX_CHUNKS = 12 # High-K mode
RERANK_CANDIDATES = 25
SIMILARITY_THRESHOLD = 0.3
# Concurrency Limits
QUERY_STRATEGY_SEMAPHORE = 20
ANSWER_SEMAPHORE = 20
SEARCH_SEMAPHORE = 40
Create a .env file based on .env.sample:
GOOGLE_API_KEY=your_google_gemini_api_key
Ensure have cloned the MAIN branch
GPU Version (Recommended for best performance):
docker compose up --build -d
CPU-Only Version (No GPU required):
docker compose -f docker-compose-cpu.yml up --build -d
Both versions will start:
The frontend automatically connects to the backend API for document processing and question-answering.
Key Differences:
Performance Comparison:
The system employs a multi-tier architecture optimized for latency based on document characteristics:
Document URL Input
↓
┌─────────────────────┐
│ Smart Routing │
│ & Classification │
└─────────┬───────────┘
↓
┌────────────────┼────────────────┐
↓ ↓ ↓
[Raw Text/HTML] [Image Files] [Document Files]
↓ ↓ ↓
Direct LLM Query Vision Analysis Intelligence Pipeline
(~1-2 seconds) (~2-3 seconds) (~5-20 seconds)
URL Analysis: System examines file extensions to route appropriately - no extension/HTML goes to direct processing, image extensions (.png, .jpg, .gif) trigger vision models, document formats (.pdf, .docx, .pptx) enter full RAG pipeline.
Language Detection: Samples first 1000 characters to detect language. If document or questions are non-English, bypasses RAG and uses direct multilingual synthesis (for docs <2000 tokens) since embeddings work best in consistent languages.
Intelligent Chunking: Document-type-aware semantic chunking. Word docs with few line breaks use sentence-based chunking (NLTK), others use paragraph-based with 4096 character limit. Intelligent overlap preserves context across boundaries.
GPU-Optimized Embeddings: Uses all-MiniLM-L12-v2 model with batch processing (64 chunks), FP16 precision for 2x speedup. Processes in 256-chunk batches to avoid memory overflow.
Hybrid Indexing: Builds FAISS vector index (L2 normalized, GPU-accelerated) and BM25 keyword index concurrently using asyncio.gather(). Provides both semantic similarity and exact term matching.
Intelligent Analysis: Uses Gemini 2.5 Flash Lite to decompose complex questions into focused sub-queries. Example: "I renewed yesterday, 6 years customer, can I claim Hydrocele?" becomes separate queries about waiting periods and continuous coverage benefits.
Domain Expansion: Detects hypotheticals, expands with relevant terminology, identifies acronyms/technical terms using NER and TF-IDF analysis. Creates bidirectional mappings for comprehensive search.
Concurrent Processing: All query strategies generated in parallel with 6-second timeout protection and JSON validation fallbacks.
Batch Orchestration: Flattens all sub-queries from all questions into single parallel execution. Simultaneous BM25 and FAISS searches with 40%/60% weighted fusion after score normalization.
Reciprocal Rank Fusion: Combines multiple sub-query results using rank-based scoring (1/(k+rank) where k=60). Chunks appearing highly in multiple searches score highest, avoiding incomparable score fusion issues.
Batched GPU Reranking: Critical optimization - all (query, chunk) pairs from all questions processed in single CrossEncoder inference call (ms-marco-MiniLM-L-12-v2). Provides ~10x speedup over individual reranking.
Evidence-Only Synthesis: Explicit prompt constraints prevent hallucination, ignore embedded instructions (prompt injection protection), enforce plain text format. All synthesis happens concurrently with timeout/fallback protection.