Meridian: Agentic Orchestration & Corrective RAG Server
Self-contained FastAPI and LangGraph 1.2 agent server with Corrective RAG (CRAG) query rewriting, hybrid PostgreSQL tsvector BM25 + pgvector RRF retrieval, <15ms cosine semantic caching, FastMCP tool discovery, Postgres-checkpointed HITL resume flows, guardrails, and automated RAGAS evaluation.
Overview
Meridian is a deployable AI agent orchestration server built around FastAPI 0.136, LangGraph 1.2, FastMCP 1.27, and PostgreSQL pgvector. It combines Corrective RAG (CRAG) self-grading, hybrid lexical-plus-dense retrieval, low-latency semantic caching, deterministic input/output guardrails, human-in-the-loop checkpoints, and per-query RAGAS evaluation behind a unified HTTP and SSE API.
Live deployment: meridian.ahad.works
System Architecture
Core Subsystems
1. Corrective RAG (CRAG) State Graph
The LangGraph StateGraph executes six deterministic stages:
- Classify — A fast-path classifier (
~2ms) separates conversational turns from corpus-grounded queries. - Retrieve — Executes PostgreSQL full-text search (
tsvectorBM25) alongsidepgvectordense similarity (all-MiniLM-L6-v2) and merges rankings with Reciprocal Rank Fusion (k = 60). - Grade — Scores retrieved chunks on
[0, 1]; documents below0.7trigger query rewriting. - Rewrite — Rewrites ambiguous or under-specified queries up to
MAX_CRAG_RETRIES=2before re-retrieving. - Generate — Produces citations strictly constrained to verified context chunks.
- Hallucination Check — Validates answer grounding against retrieved evidence prior to streaming.
2. Semantic Caching & Hybrid RRF
- Semantic Cache: Queries with cosine similarity
>= 0.92against prior embeddings return in under 15ms, skipping retrieval and LLM inference. - RRF Fusion: Combines lexical precision for exact identifiers with semantic recall:
1RRF_score(d) = 1 / (60 + rank_bm25(d)) + 1 / (60 + rank_vector(d))3. Protocol-Native Tooling, HITL & Guardrails
- FastMCP Tool Discovery: Exposes tools over
stdioand/v1/mcp/toolsJSON-RPC (mcp>=1.27). - Human-in-the-Loop (HITL): High-risk tool executions pause via
interrupt_before, persist thread state to PostgreSQL with Row-Level Security (RLS) multi-tenant isolation, and resume throughPOST /v1/chat/resume. - Guardrails & RAGAS Evals: Screens incoming payloads for prompt injection, SQL injection, and role hijacking; redacts emails, API keys, SSNs, phone numbers, and credit card patterns from outputs; tracks faithfulness, context precision, and answer relevancy via
ragas.
API Surface
| Method | Endpoint | Purpose |
|---|---|---|
POST | /v1/chat | Execute agent turn (JSON or text/event-stream SSE) |
POST | /v1/chat/resume | Resume a HITL-suspended thread after approval |
GET | /v1/mcp/tools | MCP JSON-RPC tool discovery endpoint |
POST | /v1/ingest | Ingest Markdown and PDF documents into pgvector + tsvector |
POST | /v1/eval/run | Trigger automated RAGAS evaluation over Q&A datasets |
GET | /v1/eval/results | Fetch historical faithfulness and precision scores |
GET | /health | Embedder, LangGraph, and database readiness probe |