An interactive lab to observe, compare, evaluate and debug AI systems — not another chatbot UI. Run one prompt against several models at once and see the answers, latency, tokens and cost side by side, with every request reproducible and every number measured rather than guessed.
The first lab is shipped: pick a prompt and a set of models (local Ollama, Anthropic, OpenAI, or the built-in mock), run them concurrently, and watch results stream in.
| Models registry | Side-by-side results |
|---|---|
![]() |
![]() |
The second lab is shipped: paste a document, chunk it (fixed-size or sentence-aware), embed it, then run one query against BM25, vector, and hybrid (Reciprocal Rank Fusion) retrieval concurrently — side by side, with the per-method rank and score that produced each hybrid result.
- BM25, RRF and cosine search are from-scratch, not a library —
packages/ai-core/src/retrieval/. - Embeddings share one fixed 768-dimension pgvector column across providers:
Ollama's
nomic-embed-textis natively 768-dim (the zero-cost local path); OpenAI'stext-embedding-3-smallis asked fordimensions: 768on every call. - Chunking and embedding are idempotent — re-running either against the same (document, config) or (chunk, model) pair returns the cached rows instead of recomputing.
The third lab is shipped, for both retrieval and generation: build a labeled dataset, pick a scoring config, then run it against an M2 (document, chunking, retrieval) triple or an M1 (prompt version, model) pair and watch a live scorecard fill in case by case.
- Every metric is from-scratch, not a library —
packages/ai-core/src/eval/retrieval-metrics.tsandgeneration-metrics.ts. Retrieval: recall@k, precision@k, nDCG, hit rate, MRR. Generation: exact-match, contains, regex, JSON-valid, embedding-similarity (cosine, reusing the RAG Lab's vector search), and LLM-judge (a second model grades the output against a rubric). - A retrieval case is graded by substring, not chunk index.
expected.relevantTextis matched against retrieved chunk text, so the same dataset stays valid across different chunking configs instead of pinning to indexes that shift when chunking changes. - A generation case's prompt is authored inline, the same pattern as the
Experiment Builder: a template with
{{variables}}plus one model, and each dataset case supplies its own variable values — one subject, many test inputs. - A non-conforming LLM-judge reply scores 0 with the raw reply as the reason, rather than guessing a number out of free text — consistent with never fabricating a measured number.
The fourth lab is shipped: give an agent a system prompt, a model and a toolset, hand it a task, and watch it call tools in a loop — model call, tool call, tool result, repeat — until it has an answer, with the live trace, token usage and cost streaming in step by step.
- Tool calling is normalized across three genuinely different wire protocols —
packages/ai-core/src/providers/{anthropic,openai,ollama}.ts. Anthropic batchestool_resultblocks into one user turn, OpenAI JSON-stringifies call arguments, and Ollama returns no call id at all — the adapter synthesizes a stable one so the rest of the app can treat all three providers uniformly. - Three built-in tools, not a plugin system —
calculator(a hand-written recursive-descent expression parser, nevereval()on model-generated text),current_time, andsearch_docs, which reuses the RAG Lab's ownretrieveForQueryso one tool ties this lab back into M2 instead of being a toy. - Step rows are inserted live, not pre-planned. Unlike the Eval Lab's
evalCaseResults, where the case count is known upfront, an agent run's step count depends on how many tool calls the model chooses to make —agentRunStepsrows are written as the loop runs rather than pre-inserted. - Cost and tokens are aggregated across every model call in a run, the same
never-fabricate-a-number discipline as the Experiment Builder — always summed from
real
GenerationResultusage, never estimated.
The fifth lab is shipped: every model call across Experiments, Evaluation and Agents, merged into one time-sorted feed — plus a live view of what's actually loaded in your local Ollama runtime, VRAM and unload timer included.
- No new central log table.
experimentRuns, generationevalCaseResultsandagentRunStepsalready each persist one model call for their own lab;GET /tracesqueries each bounded, normalizes the rows into one shape, and merges them in-process rather than duplicating writes into a fourth table — the right call at lab scale, not a substitute for a real ingestion pipeline. - Nothing in the app called Ollama's
ps()endpoint before this. Loaded models, VRAM usage and unload expiry were sitting in the SDK unused —packages/ai-core/src/providers/ollama.tsnow wraps it behind a smallLocalRuntimeInspectableinterface, kept off the genericModelProvidersince it's Ollama-specific. - The raw provider payload is fetched lazily, not bundled into the list.
GET /tracesstays lean (summary fields only);GET /traces/:source/:idreturns the raw payload only when a row is actually expanded — most rows never are.
The sixth and final milestone is shipped: a CLI that closes the loop by making the
Evaluation Lab (M3) catch regressions automatically, not just on demand from the UI.
pnpm regression:check (or pnpm --filter @melai/cli regression-gate) seeds a fresh
database, starts the API, runs a generation eval, diffs the result against a
checked-in baseline, and exits non-zero on a regression — the same command runs
locally and in CI.
- The CLI is an HTTP client, not a database/service importer.
apps/apiexposes no packageexportsand nothing in the repo imports one app'ssrc/from another —apps/webonly ever talks to the API over HTTP.apps/clirespects that boundary too, reusingpackages/shared's Zod types for the request/response shapes the same wayapps/web/src/lib/api-client.tsdoes. - One self-contained command, no CI-yaml ceremony. The script spawns
db:seedthen the API dev server itself, waits for/health, runs the gate, and kills the whole process tree — so the new CI job (.github/workflows/ci.yml) is a single line, and a developer runs the exact same command locally. - Baselines are JSON files checked into git (
apps/cli/baselines/), not database rows — a regression shows up as a reviewable diff in a PR. The shipped suite scores the always-available, deterministicmock-echomodel, whose correct output is provably always the same string — so its baseline is pinned at a perfect1.0. This is an honest eval-shaped smoke test of the app itself (template rendering, scorers, the eval run loop), not a tracker of real model-quality drift — this repo's CI has no API keys to do that with.
All six milestones are shipped — Model Comparison, RAG, Evaluation, Agents, Local-AI Observability, and the CLI + CI regression gate that watches over all of them.
Requires Node ≥ 22 and pnpm.
pnpm install
pnpm db:seed # creates an in-process PGlite database + seed models
pnpm dev # api on :4000, web on :3000Open http://localhost:3000, go to Experiments → New experiment, write a prompt, pick Mock (echo), and hit run. The mock provider echoes the prompt back with deterministic latency/token/cost numbers, so the whole loop works with zero configuration.
Or go to RAG Lab → New document, paste some text, chunk it, embed it with Mock (embed), add BM25 + Vector + Hybrid to compare, and run a query — same zero-config story, deterministic mock embeddings included.
Or go to Evaluation Lab → New dataset, pick retrieval or generation, add a few cases, then start a run — retrieval against a RAG Lab document/chunking/retrieval triple, generation against a prompt template + Mock (echo) — and pick scorers. Same zero-config story: mock embeddings and the mock model make the whole dataset → run → scorecard loop deterministic either way.
Or go to Agents Lab → New agent, name it, pick Mock (echo) and the
calculator tool, then give it a task. The mock provider is scripted to call the
first tool it's offered once, so even with zero configuration you can watch a real
model call → tool call → tool result → model call loop play out in the live trace.
Or, after running any of the above, go to Traces to see that same call (or calls) show up in one merged, filterable feed — click a row to lazily fetch its raw payload. The "Local models" card up top will read "No models currently loaded" until you're running Ollama with something pulled.
Or, from the terminal, run pnpm regression:check — no dev server needed, it starts
and stops its own. It seeds a fresh database, runs a generation eval against Mock
(echo), and diffs the result against apps/cli/baselines/generation-smoke.json,
exiting non-zero if anything regressed.
To use real models, add credentials to .env (no re-seed needed — the models are
already there, the provider just needs a key):
ANTHROPIC_API_KEY=.../OPENAI_API_KEY=...— the provider turns green on the Models page once a key is present.ollama pull qwen2.5:7b-instruct— for the local chat model, andollama pull nomic-embed-text— for the local (free) embedding model. Both useOLLAMA_BASE_URL, defaulthttp://localhost:11434.
apps/
web/ Next.js (App Router) — builder, history, live results; RAG Lab workspace +
results; Evaluation Lab datasets, run panel, live scorecard; Agents Lab
agent builder, run panel, live step trace; Traces feed + local runtime panel
api/ Fastify — experiment engine + RAG engine + eval service + agent loop +
traces aggregation + REST + SSE
cli/ The regression-gate CLI — an HTTP client of apps/api, with its own
checked-in suites (packages/shared-typed) and baselines
packages/
ai-core/ ModelProvider + EmbeddingProvider interfaces, adapters (incl. tool
calling and Ollama running-models introspection, normalized across
Anthropic/OpenAI/Ollama), cost math, from-scratch retrieval (chunking,
BM25, RRF, cosine search), and retrieval + generation eval metrics
(recall@k, precision@k, MRR, nDCG, hit rate, exact-match, contains,
regex, JSON-valid, embedding-similarity, LLM-judge)
database/ Drizzle schema, migrations, seed; Postgres or in-process PGlite + pgvector
shared/ Zod specs (experiment, chunking, retrieval, eval, agent), prompt
templating, API DTO types (incl. the cross-lab TraceEntry)
- Every provider is behind one
ModelProviderinterface. The Anthropic, OpenAI and Ollama SDKs each report tokens and cache usage differently; the adapters normalise all of it to a singleTokenUsage, andpackages/ai-core/src/cost.tsis the only place model prices are applied. Cached input is always priced as the discounted portion, never double-counted. - The API is the source of truth for response shapes.
packages/shared/src/dto.tsdefines the wire types; the API handlers are annotated against them and the web client imports them, so a drift is a type error. - Runs are asynchronous.
POST /experiments,POST /retrieval-runs,POST /eval-runsandPOST /agent-runsall return202with pending results; their/streamroutes are Server-Sent Events streams (run.*/experiment.done,result.*/retrieval_run.done,case.*/eval_run.done, andstep.*/agent_run.done). Every results page opens the stream and re-fetches on each event — same event-bus pattern, one instance per app. - Traces is read-only, with no event stream of its own. Every call it shows
already has a live stream on its own lab's run page;
GET /tracesjust aggregates what's already been persisted, so the Traces page fetches on load and on filter change rather than subscribing to anything. - The dev database is in-process.
DB_DRIVER=pglite(the default) runs PGlite — with the pgvector extension loaded — underpackages/database/.pglite, no container. SetDB_DRIVER=postgresto useDATABASE_URLinstead (thepgvector/pgvector:pg17image viapnpm db:up).
pnpm lint && pnpm typecheck && pnpm test # unit + integration
pnpm --filter @melai/web e2e # Playwright happy path
pnpm regression:check # eval regression gate (its own server)Unit and integration tests run against PGlite and the MockProvider — no network,
no keys, no Docker. The provider adapters are contract-tested with a stubbed
fetch. The Playwright test drives the real stack end to end: build an experiment,
run it against the mock model, assert the result column reaches success. The
regression gate is a third, independent check of the same kind — it seeds and starts
its own API server (killing it afterward, whether it passed or failed) rather than
relying on one already running, so it's safe to run standalone or in CI alongside the
other two.
pnpm db:up # docker compose: pgvector/pgvector:pg17 on :5432
# set DB_DRIVER=postgres in .env
pnpm db:migrate
pnpm db:seed
pnpm devMIT


