Skip to content

docs: Add documentation for metrics.collections API - #2407

Merged
anistark merged 18 commits into
mainfrom
docs/metrics-collections
Nov 7, 2025
Merged

docs: Add documentation for metrics.collections API#2407
anistark merged 18 commits into
mainfrom
docs/metrics-collections

Conversation

@sanjeed5

@sanjeed5 sanjeed5 commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR updates the documentation for metrics to showcase the new ragas.metrics.collections API as the primary recommended approach, while preserving legacy API documentation for backward compatibility.

Changes

Metrics

  • AnswerAccuracy
  • AnswerCorrectness
  • AnswerRelevancy
  • AnswerSimilarity
  • BleuScore
  • ContextEntityRecall
  • ContextPrecision
  • ContextUtilization
  • Faithfulness
  • ContextRelevance
  • NoiseSensitivity
  • RougeScore
  • SemanticSimilarity
  • String metrics (ExactMatch, StringPresence, NonLLMStringSimilarity, DistanceMeasure)
  • SummaryScore

Documentation Pattern

Each metric documentation follows this structure:

  1. Primary Example: Collections-based API (modern, recommended)
  2. Concepts/How It's Calculated: Conceptual explanation (implementation-agnostic)
  3. Legacy Section: Original API for backward compatibility

Test Plan

  • Build docs locally to verify formatting
  • Test code examples to ensure they work
  • Verify all metrics from collections are documented

- Add new primary example using ragas.metrics.collections
- Show modern API with llm_factory and direct parameter passing
- Move legacy SingleTurnSample examples to Legacy section
- Relocate HHEM section to Legacy (no collections version yet)
- Add note about sync .score() method availability
- Legacy API will be deprecated in v0.4
- Complete removal planned for v1.0
- Added warning box to guide users to migrate
- Add new primary example using ragas.metrics.collections
- Show modern API with llm_factory and direct parameter passing
- Move legacy SingleTurnSample examples to Legacy section
- Add deprecation timeline (v0.4 deprecated, v1.0 removed)
- New example tested and verified to work correctly
Updated BleuScore section in traditional.md to:
- Show new collections-based API as primary example
- Add synchronous usage note
- Include configuration example for kwargs parameter
- Move legacy SingleTurnSample example to dedicated Legacy API section
- Add deprecation warning for legacy API

The new example was tested and produces the expected output.
…s API

- Add new primary example using collections-based API with llm_factory
- Include synchronous usage note for .score() method
- Move legacy SingleTurnSample example to Legacy Metrics API section
- Add deprecation timeline warning (v0.4 deprecated, v1.0 removed)
- Preserve conceptual explanation and "How It's Calculated" section
- Tested new example and verified it produces expected output
- Migrate primary example to use AnswerSimilarity from ragas.metrics.collections
- Use modern OpenAIEmbeddings instead of deprecated embedding_factory
- Add synchronous usage note for .score() method
- Move legacy SingleTurnSample example to "Legacy Metrics API" section
- Add deprecation timeline warning (v0.4 deprecation, v1.0 removal)
- Update terminology from "answer" to "response" for consistency
- Add step 4 to calculation explanation showing final score output
- Tested example successfully with no deprecation warnings
Updated answer_relevance.md to follow the new pattern:
- Added collections-based API example as primary example
- Improved structure with clearer title and description
- Added synchronous usage note
- Moved legacy SingleTurnSample example to "Legacy Metrics API" section
- Tested new example successfully
- Add examples for ContextPrecision and ContextUtilization using collections API
- Simplify documentation to show only user-facing metrics (removed wrapper details)
- Move legacy examples to deprecated section
- All examples tested and verified
- Add new collections-based API example at the top
- Add synchronous usage note
- Move legacy API examples to deprecated section
- Tested example and verified it works correctly
- Add new collections-based API example at the top
- Add synchronous usage note
- Preserve configuration section (rouge_type and mode)
- Move legacy API examples to Legacy Metrics API section with deprecation warning
- Tested example code and verified it produces expected output
- Updated example to use SemanticSimilarity from collections API
- Changed title from 'Answer Similarity' to 'Semantic Similarity' for consistency
- Added synchronous usage note
- Preserved 'How It's Calculated' section
- Moved legacy API examples to bottom with deprecation warning
- Tested example and verified it produces expected output
- Add new collections-based API example using SummaryScore from ragas.metrics.collections
- Include synchronous usage note with .score() method
- Add custom configuration example for length_penalty and coeff parameters
- Move legacy example to Legacy Metrics API section with deprecation warning
- Preserve all conceptual explanations and formulas
- Tested example code and verified it produces expected output
- Add primary example using collections-based API from ragas.metrics.collections
- Include examples for both 'relevant' and 'irrelevant' modes with outputs
- Add synchronous usage note
- Move legacy examples to Legacy Metrics API section with deprecation warning
- Preserve 'How It's Calculated' section and credits
- Tested example code and verified it works correctly
- Add collections-based API example with LLM and embeddings setup
- Move legacy evaluate() example to Legacy Metrics API section
- Add deprecation warning for legacy API
- Include synchronous usage note
- Tested example code and verified it works correctly

Note: Embeddings are required because default weights [0.75, 0.25]
include semantic similarity. See issue #2408 for making embeddings
optional when weights[1] == 0.
…Similarity) to collections API

- Updated NonLLMStringSimilarity with collections API example and configuration section
- Updated ExactMatch with collections API example
- Updated StringPresence with collections API example
- Added synchronous usage notes for all three metrics
- Moved legacy examples to Legacy Metrics API section with deprecation warnings
- All examples tested and verified to work correctly
@sanjeed5
sanjeed5 marked this pull request as ready for review November 7, 2025 12:38
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Nov 7, 2025
Reorder imports to follow Python conventions (alphabetical order, grouped by standard library, third-party, and local imports) and fix minor typo in Opik integration documentation.
@sanjeed5
sanjeed5 requested a review from anistark November 7, 2025 12:57
@anistark
anistark merged commit 5b64f89 into main Nov 7, 2025
5 checks passed
@anistark
anistark deleted the docs/metrics-collections branch November 7, 2025 14:07
anistark pushed a commit that referenced this pull request Nov 12, 2025
…2420)

## Issue Link / Problem Description
- Follow-up to PR #2407
- Completes the migration to collections-based API documentation for
metrics that were not covered in the initial PR

## Changes Made
- Updated **ContextRecall** documentation to showcase
`ragas.metrics.collections.ContextRecall` as the primary example
- Updated **FactualCorrectness** documentation to showcase
`ragas.metrics.collections.FactualCorrectness` with configuration
options (mode, atomicity, coverage)
- Updated **ResponseGroundedness** documentation in nvidia_metrics.md to
showcase `ragas.metrics.collections.ResponseGroundedness` as the primary
example
- Moved all legacy API examples to "Legacy Metrics API" sections with
deprecation warnings
- Added synchronous usage notes (`.score()` method) for all three
metrics
- Preserved all conceptual explanations and "How It's Calculated"
sections

## Testing
### How to Test
- [x] Automated tests added/updated: N/A (documentation only)
- [x] Manual testing steps:
  1. Verified `make build-docs` succeeds without errors ✓
  2. Tested all new code examples to ensure they work as documented
  3. Confirmed output values match expected results
  4. Verified consistency with PR #2407 documentation style

## References
- Related issues: Follow-up to PR #2407
- Documentation: 
  - Updated: `docs/concepts/metrics/available_metrics/context_recall.md`
- Updated:
`docs/concepts/metrics/available_metrics/factual_correctness.md`
- Updated: `docs/concepts/metrics/available_metrics/nvidia_metrics.md`
(ResponseGroundedness section)
- Pattern reference: PR #2407 (faithfulness.md, context_precision.md,
answer_correctness.md)

## Screenshots/Examples (if applicable)

All three metrics now follow the consistent pattern:
1. **Primary Example**: Collections-based API (modern, recommended)
2. **Concepts**: Implementation-agnostic explanation
3. **Synchronous Usage Note**: `.score()` method alternative
4. **Legacy Section**: Original API with deprecation timeline warnings
anistark pushed a commit that referenced this pull request Nov 17, 2025
## Summary

This PR updates the documentation for metrics to showcase the new
`ragas.metrics.collections` API as the primary recommended approach,
while preserving legacy API documentation for backward compatibility.

## Changes

### Metrics
- [x] AnswerAccuracy 
- [x] AnswerCorrectness
- [x] AnswerRelevancy
- [x] AnswerSimilarity
- [x] BleuScore
- [x] ContextEntityRecall
- [x] ContextPrecision
- [x] ContextUtilization
- [x] Faithfulness 
- [x] ContextRelevance
- [x] NoiseSensitivity
- [x] RougeScore
- [x] SemanticSimilarity
- [x] String metrics (ExactMatch, StringPresence,
NonLLMStringSimilarity, DistanceMeasure)
- [x] SummaryScore

## Documentation Pattern

Each metric documentation follows this structure:
1. **Primary Example**: Collections-based API (modern, recommended)
2. **Concepts/How It's Calculated**: Conceptual explanation
(implementation-agnostic)
3. **Legacy Section**: Original API for backward compatibility

## Test Plan

- [x] Build docs locally to verify formatting
- [x] Test code examples to ensure they work
- [x] Verify all metrics from collections are documented
anistark pushed a commit that referenced this pull request Nov 17, 2025
…2420)

## Issue Link / Problem Description
- Follow-up to PR #2407
- Completes the migration to collections-based API documentation for
metrics that were not covered in the initial PR

## Changes Made
- Updated **ContextRecall** documentation to showcase
`ragas.metrics.collections.ContextRecall` as the primary example
- Updated **FactualCorrectness** documentation to showcase
`ragas.metrics.collections.FactualCorrectness` with configuration
options (mode, atomicity, coverage)
- Updated **ResponseGroundedness** documentation in nvidia_metrics.md to
showcase `ragas.metrics.collections.ResponseGroundedness` as the primary
example
- Moved all legacy API examples to "Legacy Metrics API" sections with
deprecation warnings
- Added synchronous usage notes (`.score()` method) for all three
metrics
- Preserved all conceptual explanations and "How It's Calculated"
sections

## Testing
### How to Test
- [x] Automated tests added/updated: N/A (documentation only)
- [x] Manual testing steps:
  1. Verified `make build-docs` succeeds without errors ✓
  2. Tested all new code examples to ensure they work as documented
  3. Confirmed output values match expected results
  4. Verified consistency with PR #2407 documentation style

## References
- Related issues: Follow-up to PR #2407
- Documentation: 
  - Updated: `docs/concepts/metrics/available_metrics/context_recall.md`
- Updated:
`docs/concepts/metrics/available_metrics/factual_correctness.md`
- Updated: `docs/concepts/metrics/available_metrics/nvidia_metrics.md`
(ResponseGroundedness section)
- Pattern reference: PR #2407 (faithfulness.md, context_precision.md,
answer_correctness.md)

## Screenshots/Examples (if applicable)

All three metrics now follow the consistent pattern:
1. **Primary Example**: Collections-based API (modern, recommended)
2. **Concepts**: Implementation-agnostic explanation
3. **Synchronous Usage Note**: `.score()` method alternative
4. **Legacy Section**: Original API with deprecation timeline warnings
anistark pushed a commit that referenced this pull request Dec 14, 2025
## Issue Link / Problem Description

The modifying-prompts-metrics guide had significant factual errors that
would cause code examples to fail:
- Used non-existent class names (`FaithfulnessInput`,
`FaithfulnessPrompt`, etc.)
- Referenced wrong attribute names (`scorer.prompt` instead of
`scorer.statement_generator_prompt`)
- Documented save/load functionality that doesn't exist on the
collections `BasePrompt` class

## Changes Made

- **Fixed incorrect class names**: `FaithfulnessInput` →
`StatementGeneratorInput`, `FaithfulnessOutput` →
`StatementGeneratorOutput`, etc.
- **Fixed wrong attribute names**: `scorer.prompt` →
`scorer.statement_generator_prompt` / `scorer.nli_statement_prompt`
- **Removed non-existent save/load section**: ~175 lines documenting
functionality that doesn't exist on
`ragas.prompt.metrics.base_prompt.BasePrompt`
- **Added cross-references**: Quick start pointing to
`DiscreteMetric`/`NumericMetric` for simpler custom metrics
- **Converted to pure markdown**: Deleted `.ipynb` source, created clean
`.md` file
- **Fixed mkdocstrings link**: Changed
`[BasePrompt][ragas.prompt.metrics.base_prompt.BasePrompt]` to
`[BasePrompt][ragas.prompt.BasePrompt]` (public API)
- **Added docs rule**: Added API references guidance to
`.cursor/rules/docs-structure.mdc`

## Testing

### How to Test
- [x] Automated tests added/updated
- [x] Manual testing steps:
1. Run `uv run python tests/docs/test_modifying_prompts_metrics.py` -
all 7 tests pass
  2. Run `make serve-docs` and verify the guide renders correctly
  3. Verify all code examples in the guide work

### Test Results
```
✓ Faithfulness has statement_generator_prompt and nli_statement_prompt
✓ Generated prompt string successfully
✓ Custom FactualCorrectness prompt evaluation completed. Score: 1.0
✓ Custom Faithfulness NLI prompt evaluation completed. Score: 1.0
✓ NLI prompt string generated successfully
✓ Faithfulness evaluation completed. Score: 1.0
✓ Language adaptation completed. Score: 1.0

✓ All tests passed!
```

## References

- Related to PR #2394 (documentation structure update)
- Related to PR #2407 (metrics collections API documentation)
- Fixes errors introduced in commits `691ad9f` and `e62ff19`
cgaswin pushed a commit to cgaswin/ragas that referenced this pull request Dec 17, 2025
…bsai#2486)

## Issue Link / Problem Description

The modifying-prompts-metrics guide had significant factual errors that
would cause code examples to fail:
- Used non-existent class names (`FaithfulnessInput`,
`FaithfulnessPrompt`, etc.)
- Referenced wrong attribute names (`scorer.prompt` instead of
`scorer.statement_generator_prompt`)
- Documented save/load functionality that doesn't exist on the
collections `BasePrompt` class

## Changes Made

- **Fixed incorrect class names**: `FaithfulnessInput` →
`StatementGeneratorInput`, `FaithfulnessOutput` →
`StatementGeneratorOutput`, etc.
- **Fixed wrong attribute names**: `scorer.prompt` →
`scorer.statement_generator_prompt` / `scorer.nli_statement_prompt`
- **Removed non-existent save/load section**: ~175 lines documenting
functionality that doesn't exist on
`ragas.prompt.metrics.base_prompt.BasePrompt`
- **Added cross-references**: Quick start pointing to
`DiscreteMetric`/`NumericMetric` for simpler custom metrics
- **Converted to pure markdown**: Deleted `.ipynb` source, created clean
`.md` file
- **Fixed mkdocstrings link**: Changed
`[BasePrompt][ragas.prompt.metrics.base_prompt.BasePrompt]` to
`[BasePrompt][ragas.prompt.BasePrompt]` (public API)
- **Added docs rule**: Added API references guidance to
`.cursor/rules/docs-structure.mdc`

## Testing

### How to Test
- [x] Automated tests added/updated
- [x] Manual testing steps:
1. Run `uv run python tests/docs/test_modifying_prompts_metrics.py` -
all 7 tests pass
  2. Run `make serve-docs` and verify the guide renders correctly
  3. Verify all code examples in the guide work

### Test Results
```
✓ Faithfulness has statement_generator_prompt and nli_statement_prompt
✓ Generated prompt string successfully
✓ Custom FactualCorrectness prompt evaluation completed. Score: 1.0
✓ Custom Faithfulness NLI prompt evaluation completed. Score: 1.0
✓ NLI prompt string generated successfully
✓ Faithfulness evaluation completed. Score: 1.0
✓ Language adaptation completed. Score: 1.0

✓ All tests passed!
```

## References

- Related to PR vibrantlabsai#2394 (documentation structure update)
- Related to PR vibrantlabsai#2407 (metrics collections API documentation)
- Fixes errors introduced in commits `691ad9f` and `e62ff19`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants