Skip to content

Commit

Permalink
feat: added initial metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Nov 7, 2024
0 parents commit 5e37743
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Upload Python Package to PyPI when a Release is Created

on:
release:
types: [created]

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/rag-metrics
permissions:
id-token: write
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --all-extras --dev

- name: Build Package
run: uv build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
Empty file added README.md
Empty file.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "rag-metrics"
version = "0.1.0"
description = "Metrics for RAG systems"
readme = "README.md"
authors = [
{ name = "Ivan Leo", email = "[email protected]" }
]
requires-python = ">=3.11"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
4 changes: 4 additions & 0 deletions rag_metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from rag_metrics.metrics import calculate_mrr, calculate_recall


__all__ = ["calculate_mrr", "calculate_recall"]
12 changes: 12 additions & 0 deletions rag_metrics/metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def calculate_mrr(predictions: list[str], gt: list[str]):
mrr = 0
for label in gt:
if label in predictions:
# Find the relevant item that has the smallest index
mrr = max(mrr, 1 / (predictions.index(label) + 1))
return mrr


def calculate_recall(predictions: list[str], gt: list[str]):
# Calculate the proportion of relevant items that were retrieved
return len([label for label in gt if label in predictions]) / len(gt)

0 comments on commit 5e37743

Please sign in to comment.