Skip to content

feat(knowledge): retrieval precision metric (agents' KB #3)#228

Merged
mkreyman merged 1 commit into
masterfrom
knowledge-retrieval-metrics
Jul 1, 2026
Merged

feat(knowledge): retrieval precision metric (agents' KB #3)#228
mkreyman merged 1 commit into
masterfrom
knowledge-retrieval-metrics

Conversation

@mkreyman

@mkreyman mkreyman commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Closes the loop on whether retrieval is actually improving.

The signal: of the articles a search surfaced on a day, how many did the agent then open (search → get/context, same api_key, within a follow-through window)? That share is precision — a mechanical proxy computed purely from article_access_events (no LLM, no labels), which should trend up as dedup (#1), navigation (#5), and conflict resolution (#4) clean the corpus and sharpen the top results.

Pieces

  • RetrievalMetrics.compute/3 — the search→open correlation (correlated EXISTS + interval window); compute / snapshot / list_snapshots.
  • retrieval_metric_snapshots table (RLS) — daily time series, upsert per tenant/day/window.
  • RetrievalMetricsWorker — daily all_tenants fan-out, snapshots the previous full day. Cron 30 4 * * *.
  • GET /knowledge/analytics/retrieval-metrics (orchestrator+); MCP v2.29.0 knowledge_retrieval_metrics.

Honest caveat (documented in the module)

It measures search → open, not search → useful — a snippet-only use counts as a miss, so the absolute number undercounts. The bias is consistent, so the trend is the meaningful thing.

Tests (+11): precision math (window / api_key / context / empty), snapshot idempotency + tenant isolation, worker fan-out (skips suspended) + per-day, controller series + role gate. Full gate green: format, credo, dialyzer, 3075 tests.

Closes the loop on whether retrieval is improving. Signal: of the articles a search
SURFACED on a day, how many did the agent then OPEN (search -> get/context by the same
api_key within a follow-through window)? That share is precision — mechanical, computed
purely from article_access_events (no LLM), trends UP as dedup (#1), navigation (#5) and
conflict resolution (#4) clean the corpus.

- RetrievalMetrics.compute/3 (search->open correlated EXISTS + interval window), snapshot,
  list_snapshots. retrieval_metric_snapshots table (RLS), daily time series, upsert.
- RetrievalMetricsWorker: daily all_tenants fan-out, previous full day. Cron 30 4 * * *.
- GET /knowledge/analytics/retrieval-metrics (orchestrator+); MCP v2.29.0
  knowledge_retrieval_metrics.

Honest caveat (documented): measures search->OPEN not search->useful; consistent bias,
so the TREND is what matters. Tests (+11). Full gate green (3075 tests, dialyzer, credo).
@mkreyman mkreyman merged commit f424684 into master Jul 1, 2026
9 checks passed
@mkreyman mkreyman deleted the knowledge-retrieval-metrics branch July 1, 2026 01:38
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.

1 participant