Skip to content

Commit

Permalink
Ensure EmbeddingSimilarity scores do not exceed 1 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielericlee authored Sep 10, 2024
1 parent 6b10885 commit 12f4397
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions js/ragas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test("Ragas end-to-end test", async () => {

if (score === 1) {
expect(actualScore.score).toBeCloseTo(score, 4);
expect(actualScore.score).toBeLessThanOrEqual(1);
}
}
}, 600000);
2 changes: 1 addition & 1 deletion js/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ export const EmbeddingSimilarity: ScorerWithPartial<
}, "EmbeddingSimilarity");

function scaleScore(score: number, expectedMin: number): number {
return Math.max((score - expectedMin) / (1 - expectedMin), 0);
return Math.min(Math.max((score - expectedMin) / (1 - expectedMin), 0), 1);
}

0 comments on commit 12f4397

Please sign in to comment.