Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metrics): fixed NDCG calculation and added comprehensive test cases #17126

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

iamarunbrahma
Copy link
Contributor

Description

This PR fixes a bug in the NDCG (Normalized Discounted Cumulative Gain) metric calculation where the IDCG was incorrectly calculated using retrieved_ids instead of expected_ids. The fix ensures IDCG represents the best possible ranking of relevant documents.

Key changes:

  • Fixed IDCG calculation to use min(len(retrieved_ids), len(expected_ids))
  • Added proper handling for empty expected_ids case
  • Added comprehensive test cases covering various scenarios including:
    • Perfect ranking
    • Partial matches
    • No relevant docs
    • More relevant docs than retrieved
    • Single relevant doc
    • Different modes (linear/exponential)
    • Empty expected_ids

Fixes #17070

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • I added new unit tests to cover this change
    • Added comprehensive test cases in test_metrics.py covering various NDCG scenarios
    • Tests include edge cases like empty expected_ids and different ranking modes

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 2, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 3, 2024
@logan-markewich logan-markewich merged commit ccfe6d7 into run-llama:main Dec 3, 2024
11 checks passed
alexeyrodriguez added a commit to alexeyrodriguez/llama_index that referenced this pull request Dec 10, 2024
alexeyrodriguez added a commit to alexeyrodriguez/llama_index that referenced this pull request Dec 10, 2024
…test cases (run-llama#17126)"

This reverts commit ccfe6d7.

Signed-off-by: Alexey Rodriguez Yakushev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Calculation of ideal DCG in NDCG is incorrect
2 participants