Skip to content

feat: retrieval evaluation harness — P@k, R@k, MRR, nDCG@k + gbrain e… - #40

Closed
4shut0sh wants to merge 2 commits into
garrytan:masterfrom
4shut0sh:master
Closed

4shut0sh wants to merge 2 commits into
garrytan:masterfrom
4shut0sh:master

Conversation

@4shut0sh

Copy link
Copy Markdown
Contributor

…val CLI

Add a full retrieval evaluation framework so search quality can be measured, compared, and tracked instead of evaluated by vibes.

  • src/core/search/eval.ts: pure IR metrics (precisionAtK, recallAtK, mrr, ndcgAtK), EvalQrel/EvalConfig/EvalReport types, and runEval() orchestrator that executes any strategy against user-provided qrels
  • src/commands/eval.ts: gbrain eval CLI with single-run table and A/B comparison mode (--config-a / --config-b) showing Δ nDCG
  • src/core/operations.ts: eval_search operation available via MCP; agents can pass inline qrels JSON and get metrics back
  • src/core/search/hybrid.ts: add rrfK and dedupOpts to HybridSearchOpts so A/B tests can override RRF_K=60, cosine threshold, type ratio cap without touching constants
  • test/eval.test.ts: 30+ unit tests for all metric functions
  • test/e2e/mechanical.test.ts: replace non-asserting console.log precision@5 block with real expect() assertions using precisionAtK

Usage: gbrain eval --qrels ./my-queries.json
gbrain eval --qrels ./qrels.json --config-a '{"rrf_k":60}' --config-b '{"rrf_k":30}' Made-with: Cursor

@irresi

irresi commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

#36

…val CLI

Add a full retrieval evaluation framework so search quality can be
measured, compared, and tracked instead of evaluated by vibes.

- src/core/search/eval.ts: pure IR metrics (precisionAtK, recallAtK,
  mrr, ndcgAtK), EvalQrel/EvalConfig/EvalReport types, and runEval()
  orchestrator that executes any strategy against user-provided qrels
- src/commands/eval.ts: gbrain eval CLI with single-run table and
  A/B comparison mode (--config-a / --config-b) showing Δ nDCG
- src/core/operations.ts: eval_search operation available via MCP;
  agents can pass inline qrels JSON and get metrics back
- src/core/search/hybrid.ts: add rrfK and dedupOpts to HybridSearchOpts
  so A/B tests can override RRF_K=60, cosine threshold, type ratio cap
  without touching constants
- test/eval.test.ts: 30+ unit tests for all metric functions
- test/e2e/mechanical.test.ts: replace non-asserting console.log
  precision@5 block with real expect() assertions using precisionAtK

Usage: gbrain eval --qrels ./my-queries.json
  gbrain eval --qrels ./qrels.json --config-a '{"rrf_k":60}' --config-b '{"rrf_k":30}'
Made-with: Cursor
@garrytan

Copy link
Copy Markdown
Owner

@4shut0sh — this is exactly what GBrain needed. A proper retrieval eval framework with real IR metrics instead of vibing on search quality.

The API design is clean: pure metric functions with zero deps for unit testing, runEval() orchestrator for E2E, A/B comparison mode for parameter tuning. Making rrfK and dedupOpts configurable on HybridSearchOpts was the right call — it integrates perfectly with our compiled truth boost work.

We've pulled this into garrytan/search-quality-boost (PR #64) with full attribution via Co-Authored-By. It's now part of the search quality suite alongside the compiled truth ranking, cosine re-scoring, and source-aware dedup. All 38 eval unit tests pass.

Massive thank you for this. The eval harness is the kind of infrastructure that makes every future search improvement measurable instead of guesswork.

Closing in favor of #64 which includes this work.

@garrytan garrytan closed this Apr 13, 2026
jununfly referenced this pull request in jununfly/ZBrainForStudy Jun 25, 2026
Full audit document for Node 1-4: Operations layer and trust boundary migration.

Includes:
- Complete scope definition (3 child nodes, 16 implementation slices)
- Grill decisions recorded (A A A A A)
- Current state audit (4,243 lines TS to migrate)
- Security critical path identification
- TDD implementation slicing plan (#40-#55)
- Gap analysis summary
- Acceptance gates
- Risk mitigation plan

Implementation slices: 16 total, ~3,750 - 5,300 estimated lines of Rust
jununfly referenced this pull request in jununfly/ZBrainForStudy Jun 25, 2026
Complete 1:1 TypeScript → Rust port of the operations layer type system:
- ErrorCode enum with full v0.31 error codes
- OperationError struct with exact TS serialization (error/message/suggestion/docs)
- Dual error system bridge: OperationError → StructuredError conversion
- AuthInfo struct (v0.8+ OAuth with federated read support)
- CliOpts struct with quiet/progress_json/progress_interval
- Logger trait with Debug + Send + Sync bounds, NoopLogger implementation
- OperationContext struct with COMPLETE trust boundary fields:
  - remote (MCP trust flag — security critical)
  - via_subagent + subagent_id (agent policy enforcement)
  - source_id (v0.34 tenancy filter)
  - allowed_slug_prefixes (v0.23 dream cycle workspace whitelist)
  - takes_holders_allow_list (v0.28 visibility model filter)
  - brain_id (v0.19 mount support)
  - source_scope_opts() helper with v0.34.1 precedence logic
- Operation object-safe trait with name/description/local_only()

Tests: 14/14 passing
- Error serialization parity verified byte-for-byte with TS
- Trust boundary context constructors verified
- Source scope precedence logic verified
jununfly referenced this pull request in jununfly/ZBrainForStudy Jun 25, 2026
- Node 1-4-1 status: pending → in_progress
- Slice #40 completion notes added
- Commit 206adee: Operation trait and type foundation implemented
garrytan added a commit that referenced this pull request Oct 16, 2026
#43 with regression tests

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants