Agentic-RAG-Platform

Technology Selection & Architectural Trade-off Analysis

Comprehensive evaluation and rationale for every foundational library, database engine, machine learning model, and framework chosen for the Agentic RAG Platform.


1. Executive Summary: The Core Stack

Architectural Concern Selected Technology Primary Trade-off Rationale Key Reference
Backend Runtime Python 3.11 + FastAPI + Pydantic v2 Async I/O concurrency, strict runtime typing, ML/PyTorch ecosystem synergy. src/
Unified Storage PostgreSQL 16 + pgvector 0.7 + GIN Single datastore for relational RBAC, vector embeddings, and full-text search. ADR-001
Dense Embeddings BAAI/bge-m3 (Local PyTorch) 1024-dim dense geometry, multilingual (100+ languages), zero external API cost. embeddings.md
Cross-Encoder Reranker BAAI/bge-reranker-v2-m3 Joint query-document attention scoring; improves Recall@5 from 62.4% to 84.2%. ADR-003
Agent Orchestration Custom State Machine Pure Python deterministic state transitions; eliminates framework lock-in. ADR-004
LLM Synthesis Engine OpenAI gpt-4o-mini + Provider Bridge High reasoning capability at low unit cost (~$0.0007/query); swappable via provider interface. src/llm/provider.py
User Interface Next.js 14 + React + Tailwind CSS Server-side rendering, responsive conversational chat, citation inspection inspector. apps/web/
Distributed Telemetry OpenTelemetry + Self-Hosted Langfuse Vendor-neutral wire protocol; local trace sovereignty and LLM cost accounting. ADR-007
Low-Latency Cache Redis 7 Alpine In-memory key-value caching of embedding vectors, query results, and rate limits. docker-compose.yml
Database Migrations Alembic + SQLAlchemy 2.0 Declarative asynchronous schema migrations with reversible downgrade operations. alembic/
Document Ingestion Docling (PDF) + Trafilatura (HTML) Layout-aware structural parsing of tables, headings, and Markdown conversion. src/ingestion/loaders.py
Evaluation Framework Ragas + Golden Benchmark Automated CI quality gates measuring Faithfulness, Recall@K, and Hallucination rate. rag-evaluation.md

2. In-Depth Architectural Evaluations

2.1. Unified PostgreSQL vs. Specialized Vector Databases (Pinecone / Qdrant)

2.2. Custom State Machine vs. LangChain / LangGraph

2.3. BGE-m3 & Local Cross-Encoder vs. Proprietary Cloud APIs (Cohere / OpenAI)

2.4. Streaming Architecture: Server-Sent Events (SSE)


3. Explicit Technology Rejections

  1. GraphQL: Rejected in favor of RESTful endpoints. The platform data model is well-defined and hierarchical; GraphQL adds unnecessary schema mapping overhead.
  2. LangSmith (Cloud SaaS): Rejected in favor of self-hosted Langfuse to preserve customer data sovereignty and eliminate per-trace SaaS subscription fees.
  3. Heavy Distributed Task Queues (Celery/RabbitMQ): For current ingestion volumes, asynchronous background workers using native Python asyncio queues provide sufficient throughput without message broker operational overhead.