Repository navigation
Conversation
AgentGoalAccuracyWithoutReference inherited the base default `output_type = None`, unlike its sibling AgentGoalAccuracyWithReference, so `metric.train(path, instruction_config=InstructionConfig(llm=...))` raised "Output type for metric 'agent_goal_accuracy' is not defined" before any optimization could run. Both classes judge the same Literal["0", "1"] verdict, so BINARY is the intended value.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Link / Problem Description
AgentGoalAccuracyWithoutReferencenever declaresoutput_type, so it keeps the base-class defaultoutput_type: t.Optional[MetricOutputType] = None(src/ragas/metrics/base.py:167).BaseMetric._optimize_instructionreads that field to pick the loss function and raises before the optimizer is even constructed (src/ragas/metrics/base.py:211-213), so the publicmetric.train(path, instruction_config=InstructionConfig(llm=...))always aborts with:Instruction/prompt optimization is unreachable for this metric regardless of dataset size or LLM.
Its sibling
AgentGoalAccuracyWithReference, defined in the same module and scoring the sameLiteral["0", "1"]verdict (CompareOutcomeOutput), does declareoutput_type: t.Optional[MetricOutputType] = MetricOutputType.BINARYatsrc/ragas/metrics/_goal_accuracy.py:114. Commit9bd1402(PR #1722), which introducedoutput_typeso the loss for optimization could be derived, added that line toAgentGoalAccuracyWithReferenceonly and skipped the near-identical class sitting directly below it in the same file. The value is enforced independently downstream as well:src/ragas/optimizers/genetic.py:549raisesValueError("No output type provided for the metric.").Changes Made
src/ragas/metrics/_goal_accuracy.py: addoutput_type: t.Optional[MetricOutputType] = MetricOutputType.BINARYto theAgentGoalAccuracyWithoutReferencedataclass body, directly after_required_columns, mirroring line 114 of the sibling class.MetricOutputTypeis already imported in the module. This is the only production change.tests/unit/test_goal_accuracy.py(new): regression test covering both the declared value and thetrain()path that consumes it.Testing
How to Test
On an unpatched tree (source reverted to
main, new test kept):with
src/ragas/metrics/base.py:212: ValueError: Output type for metric 'agent_goal_accuracy' is not defined. Please set the output type in the metric or in the instruction config.On the patched tree:
The second test drives
AgentGoalAccuracyWithoutReference(llm=...).train(path, instruction_config=InstructionConfig(llm=...))with an optimizer stub that records the loss it is handed, and asserts it is aBinaryMetricLoss— i.e. the same run that previously raised now reaches the optimizer.Full unit suite (
pytest tests/unit --ignore=tests/unit/integrations):2 failed, 743 passed, 62 skipped, 8 errors. The identical failure/error set occurs on unmodifiedmain(missing optionalsacrebleu/haystackdependencies andtest_experiment.pygit fixtures); the unpatched run differs only by the two new test failures. No regressions introduced.Lint and type checks:
ruff format --checkandruff checkpass on both changed files (the repo-wideruff format --checkreports 88 pre-existing reformats in files this PR does not touch);pyright -p pyproject.tomlreports 0 errors forsrc/ragas/metrics/_goal_accuracy.py.References
9bd1402("feat: add output type to metrics") — addedoutput_typeto the sibling class onlysrc/ragas/optimizers/genetic.py:549Screenshots/Examples (if applicable)
N/A — one-line field declaration.