create-metric-plugin
Skill149 starsChanged 8 months agoApache-2.0View on GitHub
Guide developers through creating a custom evaluation metric plugin for AutoRAG-Research. Covers both retrieval metrics (recall, precision, etc.) and generation metrics (BLEU, ROUGE, etc.). Walks through scaffolding, implementing metric functions with @metric decorators, writing configs, testing, and installing. Use when building a new evaluation metric.
- Installs packages
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- autorag-querySkill
- create-generation-pluginSkill
- create-ingestor-pluginSkill
- create-retrieval-pluginSkill
- refactorSkill
- resolve-conversationSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Read the generated metric.py, pyproject.toml, YAML config, and test file to understand the structure.
- Very specific: line 33
Use the @metric decorator (per-input) or @metric_loop decorator (batch) from autorag_research.evaluation.metrics.util.
- Very specific: line 72
Verify: ls configs/metrics/retrieval/my_metric.yaml (or metrics/generation/)
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Create Metric Plugin
Workflow
1. Scaffold
# For retrieval metric:
autorag-research plugin create my_metric --type=metric_retrieval
# For generation metric:
autorag-research plugin create my_metric --type=metric_generationRead the generated metric.py, pyproject.toml, YAML config, and test file to understand the structure.
2. Implement the metric function
Use the @metric decorator (per-input) or @metric_loop decorator (batch) from autorag_research.evaluation.metrics.util. Both validate that required fields are non-None before calling.
@metric(fields_to_check=[...])— function receives a singleMetricInput, returnsfloat@metric_loop(fields_to_check=[...])— function receiveslist[MetricInput], returnslist[float]
See autorag_research/schema.py for the full MetricInput dataclass definition.
3. Understanding retrieval_gt (AND/OR group structure)
For retrieval metrics, metric_input.retrieval_gt uses a nested list structure with AND/OR semantics:
retrieval_gt: list[list[str]]
Example: [["A", "B"], ["C"]]
→ Means: (A OR B) AND C
→ Each inner list is an OR group (any item satisfies the group)
→ Outer list is AND (ALL groups must be satisfied for complete retrieval)This is critical for multi-hop queries where multiple evidence pieces are needed. Your metric must handle this structure correctly — don't just flatten it into a single set unless your metric semantics allow it.
Examples:
[["doc1"]]— single required document[["doc1", "doc2"], ["doc3"]]— need (doc1 OR doc2) AND doc3[["doc1"], ["doc2"], ["doc3"]]— need doc1 AND doc2 AND doc3
See retrieval_ndcg in autorag_research/evaluation/metrics/retrieval.py for a real implementation that handles AND/OR groups with graded relevance.
4. Wire up config and install
The generated config class just needs get_metric_func() to return your metric function. If your metric takes extra kwargs, override get_metric_kwargs().
cd my_metric_plugin
pip install -e . # or: uv pip install -e .
cd .. && autorag-research plugin syncVerify: ls configs/metrics/retrieval/my_metric.yaml (or metrics/generation/)
Key Files
| Purpose | Path |
| Base config classes | autorag_research/config.py → BaseRetrievalMetricConfig, BaseGenerationMetricConfig |
| MetricInput schema | autorag_research/schema.py |
| Metric decorators | autorag_research/evaluation/metrics/util.py → @metric, @metric_loop |
| Plugin entry point discovery | autorag_research/plugin_registry.py |
Examples
Study these existing implementations for patterns:
autorag_research/evaluation/metrics/retrieval.py— Recall, Precision, F1, NDCG, MRR, MAP (all handle AND/OR groups)autorag_research/evaluation/metrics/generation.py— BLEU, ROUGE, BERTScore, SemScore- YAML configs:
configs/metrics/retrieval/f1.yaml,configs/metrics/generation/rouge.yaml
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

