-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
RFCenhancementNew feature or requestNew feature or requestmodule-metricsthis is part of metrics modulethis is part of metrics module
Description
π Proposal
I'm proposing to refactor the metrics module to create a clearer separation between core abstractions and specific metric implementations.
π― Motivation
Currently, the src/ragas/metrics/ directory mixes core abstractions with specific implementations, making it harder to:
- Understand which files are foundational vs. implementations
- Navigate the codebase for new contributors
- Maintain clear architectural boundaries
π Current Structure
The metrics directory contains ~40 files with two categories:
Core abstractions (files without '_' prefix):
base.py- Base metric classes and interfacesresult.py- MetricResult classdecorator.py- Metric decorator factoryvalidators.py- Validation utilitiesdiscrete.py- DiscreteMetric classllm_based.py- LLM-based metric primitivesnumeric.py- NumericMetric classranking.py- RankingMetric classutils.py- Utility functionsquoted_spans.py- Quoted span utilities
Specific implementations (files with '_' prefix):
- 30+ files like
_answer_correctness.py,_faithfulness.py, etc.
π Proposed Solution
Create a metrics.core submodule:
src/ragas/metrics/
βββ core/
β βββ __init__.py
β βββ base.py
β βββ result.py
β βββ decorator.py
β βββ validators.py
β βββ discrete.py
β βββ llm_based.py
β βββ numeric.py
β βββ ranking.py
β βββ utils.py
β βββ quoted_spans.py
βββ _answer_correctness.py
βββ _faithfulness.py
βββ ... (other implementations)
βββ __init__.py
β Benefits
- Clearer separation: Explicit distinction between abstractions and implementations
- Better organization: Core functionality grouped logically
- Improved discoverability: Developers can easily find foundational components
- Reduced cognitive load: Clear hierarchy between core and specific metrics
β οΈ Considerations
- Breaking changes: Existing imports would need updating
- Backward compatibility: We should maintain compatibility with:
# Old way (should still work) from ragas.metrics.base import Metric from ragas.metrics.result import MetricResult # New way from ragas.metrics.core import Metric, MetricResult
π Questions for Discussion
- Is this separation valuable enough to justify the refactoring effort?
- Should we use a different name than "core"? (alternatives: "base", "abstractions", "primitives")
- How should we handle the migration? Phase it over multiple releases?
- Are there other files that should be considered "core" that I've missed?
π Migration Strategy (if approved)
- Create the
metrics.coremodule with all core files - Update internal imports throughout the codebase
- Add backward compatibility imports in
metrics.__init__.py - Deprecation warnings for old import paths (remove in future major version)
- Update all documentation and examples
Looking forward to feedback from the maintainers and community!
cc: @jjmachan
dosubot, anistark and jietang00723-cloud
Metadata
Metadata
Assignees
Labels
RFCenhancementNew feature or requestNew feature or requestmodule-metricsthis is part of metrics modulethis is part of metrics module