Maxwell is an adaptive, self-correcting search engine designed to solve the Hallucination Problem in Enterprise AI. Unlike standard RAG systems that simply summarize search results, Maxwell audits its own answers using a multi-signal verification pipeline.
Maxwell introduces a 5-phase pipeline that treats LLM generation as an "Untrusted Draft" until verified.
graph LR
A[User Query] --> B(Phase 1: Adaptive Plan);
B --> C(Phase 2: Surgical Search);
C --> D(Phase 3: Synthesize);
D --> E(Phase 4: Temporal Verify);
E --> F(Phase 5: Reconstruct);
F --> G[Verified Answer];
| Feature | Description |
|---|---|
| Multi-Endpoint Architecture | Pipeline split into 5 serverless functions for Vercel. Each phase under 60s timeout. |
| Vercel Blob for Large Payloads | Embeddings (~12MB) stored in Blob Storage, passed as URL. Bypasses 4.5MB payload limit. |
| Pre-Embedding Optimization | Embeddings computed during search, not verification. Reduces verify from ~45s to ~8s. |
| Adaptive Compute | Analyzes query complexity. Simple β Gemini Flash (fast). Complex β Claude Sonnet (precise). |
| Temporal Verification | NLI enforces "Recency Superiority" β old evidence cannot contradict current status. |
| Reasoning Bridge | Uses hedging language for unverified data instead of deleting it. |
| Glass Box UI | Visualizes the "thinking" process with per-claim confidence scores. |
app/
βββ api/
β βββ chat/route.ts # Standard chat endpoint
β βββ maxwell/ # Maxwell Multi-Endpoint API
β βββ route.ts # Legacy monolithic (local dev)
β βββ decompose/route.ts # Phase 1: Query decomposition
β βββ search/route.ts # Phase 2: Search + pre-embedding
β βββ synthesize/route.ts # Phase 3: SSE synthesis
β βββ verify/route.ts # Phase 4: SSE verification
β βββ adjudicate/route.ts # Phase 5: SSE adjudication
βββ components/
β βββ maxwell/ # Maxwell Canvas UI components
β βββ InputInterface.tsx # Main input with mode toggle
βββ hooks/
β βββ use-maxwell.ts # Client orchestrator for multi-endpoint
βββ lib/
βββ maxwell/
βββ index.ts # 5-phase orchestrator (local dev)
βββ api-types.ts # Multi-endpoint request/response types
βββ configFactory.ts # Adaptive compute configuration
βββ decomposer.ts # Phase 1: Query β Sub-queries
βββ searcher.ts # Phase 2: Surgical search
βββ synthesizer.ts # Phase 3: Draft synthesis
βββ verifier.ts # Phase 4: Multi-signal verification
βββ adjudicator.ts # Phase 5: Reconstruction
βββ embeddings.ts # Saturated pipeline embeddings
βββ blob-storage.ts # Vercel Blob utilities
βββ prompts.ts # All LLM prompts
| Layer | Technology |
|---|---|
| Framework | Next.js 16 (App Router, Turbopack) |
| Architecture | Multi-endpoint serverless (5 functions) |
| Orchestration | Client-side hook + Vercel AI SDK 5.0 |
| Search | Tavily API (Context-Aware w/ Raw Content) |
| Models | Google Gemini 3 Flash (Speed) / Claude Sonnet 4.5 (Reasoning) |
| Embeddings | Google Gemini Embedding 001 (Primary) / Qwen 3 (Fallback) |
| Large Payloads | Vercel Blob Storage (bypasses 4.5MB limit) |
| Streaming | Server-Sent Events (SSE) for real-time UI |
| State | Zustand + IndexedDB (idb-keyval) |
API keys required:
- OpenRouter (access to Gemini/Claude)
- Tavily (search API)
# Clone the repository
git clone https://github.com/dmbernaal/maxwell.git
cd maxwell
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env.local
# Add OPENROUTER_API_KEY and TAVILY_API_KEY
# Run development server
npm run devMaxwell includes comprehensive tests organized by type:
# Run all unit tests (no API keys required)
npm run test:unit
# Run with coverage report
npm run test:coverage__tests__/
βββ unit/ # No external dependencies (176 tests)
β βββ blob-storage.test.ts # Embedding encoding/decoding
β βββ embeddings-math.test.ts # Cosine similarity, top matches
β βββ verifier-signals.test.ts # Numeric extraction, normalization
β βββ config-factory.test.ts # Adaptive compute configuration
β βββ constants.test.ts # Threshold & model validation
β βββ decomposer-validation.test.ts # Query decomposition validation
β βββ passage-chunking.test.ts # Sentence segmentation
β βββ evidence-retrieval.test.ts # Best-match finding logic
β βββ api-types.test.ts # API contract validation
β βββ error-handling.test.ts # Edge cases & defensive coding
βββ integration/ # Requires API keys
βββ api-endpoints.test.ts # Full pipeline E2E
| Command | Description | API Keys? |
|---|---|---|
npm run test:unit |
Unit tests only | β No |
npm run test:integration |
Integration tests | β Yes |
npm test |
All tests | β Yes |
npm run test:coverage |
Unit tests with coverage | β No |
Unit Tests (176 tests across 10 files):
- Blob Storage: Base64 encoding/decoding, round-trip precision for embeddings
- Embeddings Math: Cosine similarity, orthogonal/opposite vectors, top-N matching
- Verifier Signals: Number extraction, normalization (billions/millions/%), confidence aggregation
- Config Factory: Adaptive compute for all complexity levels (simple/standard/deep_research)
- Constants: Model IDs, thresholds, multipliers, entailment scores validation
- Decomposer Validation: Sub-query validation, duplicate ID detection, bounds checking
- Passage Chunking: Sentence segmentation, window sizes, edge cases
- Evidence Retrieval: Best-match finding, citation mismatch detection
- API Types: Request/response contract validation, Blob URL formats
- Error Handling: Malformed inputs, edge cases, defensive coding patterns
Integration Tests (requires OPENROUTER_API_KEY + TAVILY_API_KEY):
- Full 5-phase pipeline: Decompose β Search β Synthesize β Verify β Adjudicate
- Real API calls to Tavily and OpenRouter
Original phase-by-phase tests from initial development are preserved in tests/legacy/ for reference.
Optimized for Vercel with multi-endpoint architecture:
- Push to GitHub
- Import project in Vercel
- Add environment variables in Vercel Dashboard:
OPENROUTER_API_KEYTAVILY_API_KEYBLOB_READ_WRITE_TOKEN(from Vercel Blob Storage)
- Deploy
Blob Storage Setup: In Vercel Dashboard β Storage β Create Blob Store β Copy token to env vars.
The Maxwell pipeline is split into 5 serverless functions to stay within Vercel's 60-second timeout:
| Endpoint | Purpose | Timeout |
|---|---|---|
/api/maxwell/decompose |
Query analysis | 30s |
/api/maxwell/search |
Search + pre-embed | 60s |
/api/maxwell/synthesize |
Answer generation | 30s |
/api/maxwell/verify |
Claim verification | 60s |
/api/maxwell/adjudicate |
Final verdict | 30s |
The key optimization: pre-embedding passages during search so verification only embeds claims (~5-30 texts, not ~3000).
This project was built using a structured AI collaboration workflow:
- Consulted Claude Opus 4.5 and Gemini to design the 5-phase pipeline architecture
- Iteratively refined the verification strategy through architectural discussions
- Planning Phase: Before any code is written, the AI constructs an implementation plan (
.mdfile) that I must approve - Review & Edit: I review the plan, make corrections, and provide feedback
- Execution: Only after approval does the AI write code using Cursor or Antigravity
- Verification:
- For logic: Run unit tests
- For UI: Visual inspection via browser + console logs
- Iteration: Back-and-forth refinement with AI assistants
| Task Type | Model Used |
|---|---|
| Logic & Architecture | Claude Opus 4.5 |
| Frontend & Design | Gemini 3.0 |
| Code Generation | Cursor Agent / Antigravity |
This approach ensures:
- β Human oversight at every decision point
- β Structured, reviewable implementation plans
- β Clear separation between design and execution
- β Iterative refinement based on testing feedback
Detailed technical documentation is available in /documentation:
MAXWELL.md- Complete architectural overviewMAXWELL_ARCHITECTURE.md- Visual pipeline breakdownPROMPTS.md- All LLM prompts explained
Diego I. Medina-Bernal
π§ dmbernaal@gmail.com