Skip to main content
Glama
kronvex-ai-rag

kronvex-ai-rag

Official
by KRONVEX
README.md
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="./assets/hero-dark.svg" />
  <source media="(prefers-color-scheme: light)" srcset="./assets/hero-light.svg" />
  <img alt="KRONVEX AI & Agentic RAG Core" src="./assets/hero-dark.svg" width="100%" />
</picture>

<p align="center">
  <strong>Apache-2.0 Golden Template · Category 6 of 7 — AI Systems, Agentic RAG, Guardrails &amp; Code-Mode MCP</strong><br/>
  Zero API keys required locally · Live SSE Streaming Studio · 6 Languages + Native Arabic RTL · Production <code>pgvector</code> HNSW + RLS SQL
</p>

---

## Why This Template Exists

Most AI starter kits stop at a single chat box calling one LLM SDK with zero retrieval grounding, zero prompt-injection defense, bloated MCP tool schemas, and zero automated evaluation gates.

**`kronvex-template-ai`** ships a complete, clean-room production core that runs **100% locally at \$0 cost** out of the box and scales cleanly to PostgreSQL 16 + `pgvector`, Google Gemini, Anthropic Claude, OpenAI, or sovereign local Ollama:

- **Real Hybrid RAG (`src/modules/rag/hybrid-engine.ts`)**: Token-aware overlapping chunking + **BM25 sparse retrieval** + **64-dim vector cosine similarity** fused via **Reciprocal Rank Fusion (`k=60`)**, with live document ingestion (`POST /v1/rag/ingest`) and inline `[1][2]` source citations.
- **4-Layer AI Security Firewall (`src/modules/guardrails/firewall.ts`)**:
  1. Direct & indirect prompt-injection, jailbreak, and tool-smuggling detection (`INJ-01`–`INJ-04`).
  2. Pre-LLM PII & cloud secret redaction (Stripe `sk_live_`, Anthropic `sk-ant-`, GitHub `ghp_`, AWS `AKIA`, credit cards, emails, phone numbers).
  3. Per-call random-UUID `<untrusted-data-...>` instruction-sandwich sandboxing.
  4. Faithfulness & grounding validation.
- **ZeroBurn 3-Band Multi-LLM Effort Router (`src/modules/router/llm-router.ts`)**: Classifies prompts into `FAST`, `BALANCED`, or `DEEP` across **Gemini 2.5**, **Claude 3.7 / Opus 4**, **OpenAI GPT-4o / o3**, and **Ollama Local (`\$0`)**.
- **Stateful 4-Stage Multi-Agent DAG + Live SSE Streaming (`src/modules/agents/orchestrator.ts` & `src/app.ts`)**: Streams `trace`, `citations`, `token`, and `done` SSE events over `POST /v1/chat/stream`.
- **Zero-Dependency Code-Mode Stdio MCP Server (`mcp/server.mjs`)**: Collapses 50 classic tool schemas (`~34,500` tokens/turn) into **2 Code-Mode tools (`~620` tokens/turn — 98.2% savings)** with pure `stdout` JSON-RPC 2.0 framing, `readOnlyHint` annotations, `--read-only` / `--lockdown` enforcement, and UUID untrusted boundaries.
- **Automated Golden Eval CI Gate (`pnpm eval`)**: Grades RAG Precision@2, Red-Team Block Rate, PII Redaction Accuracy, and Effort Routing; fails CI if pass rate drops below `100%`.
- **Zero-Downtime PostgreSQL 16 + `pgvector` Migrations (`sql/`)**: `SET lock_timeout = '2s'`, strict tenant Row-Level Security (`app.current_tenant`), and `CREATE INDEX CONCURRENTLY` GIN + HNSW vector indexes.

---

## Architecture

<picture>
  <source media="(prefers-color-scheme: dark)" srcset="./assets/architecture-dark.svg" />
  <source media="(prefers-color-scheme: light)" srcset="./assets/architecture-light.svg" />
  <img alt="KRONVEX AI & Agentic RAG Core Architecture" src="./assets/architecture-dark.svg" width="100%" />
</picture>

---

## Quick Start (< 60 Seconds, \$0 API Cost)

```bash
pnpm install
pnpm dev
```

Open **`http://localhost:8788/`** to launch the interactive **KRONVEX AI & RAG Studio** (Dark/Light optical themes + `EN`, `العربية RTL`, `FR`, `ES`, `DE`, `ZH`), or inspect **`http://localhost:8788/openapi.json`**.

### Verification Commands

```bash
pnpm typecheck   # Strict TypeScript 5.8 check
pnpm test        # Unit, Hybrid RAG, Red-Team, Hono SSE & Live Stdio MCP integration tests
pnpm eval        # Automated Golden Eval CI Gate (exits 0 only at 100%)
pnpm build       # Production ESM build into dist/
```

---

## Connect Code-Mode MCP Server (Antigravity / Claude / Cursor / VS Code)

```json
{
  "mcpServers": {
    "kronvex-ai-rag": {
      "command": "node",
      "args": ["mcp/server.mjs", "--mode", "codemode", "--read-only"]
    }
  }
}
```

Use `--mode classic` to expose individual tools (`rag_search`, `agent_execute`, `guardrail_scan`, plus `rag_ingest` when `--read-only` is omitted).

---

## Production Database & Container Deployment

- **Database**: Apply `sql/001_init_rag_pgvector.sql` followed by `sql/002_indexes_concurrently.sql` (outside a transaction block).
- **Container**: Multi-stage pinned `node:22.15.0-alpine3.21` `Dockerfile` running as non-root `USER node` with `HEALTHCHECK` on `/healthz`.

---

## License & Enterprise Engineering

Released under the **Apache-2.0 License** by **KRONVEX**.

Need custom Agentic RAG architectures, private sovereign LLM clusters, NexusMCP enterprise gateways, or Red-Team AI security audits? Contact **[kronvex.dev](https://kronvex.dev)**.