Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): use tuple key for confusion matrix lookup to avoid delimiter collisions (#17196)

marliessophieaa4466182985
diff --git a/web/src/__tests__/heatmap-utils.clienttest.ts b/web/src/__tests__/heatmap-utils.clienttest.ts
index 000faee874..0a02523f16 100644
--- a/web/src/__tests__/heatmap-utils.clienttest.ts
+++ b/web/src/__tests__/heatmap-utils.clienttest.ts
@@ -161,6 +161,28 @@ describe("heatmap-utils", () => {
expect(result.cells[1].metadata?.percentage).toBe(75);
});
+ it("should not collide cells when categories contain the key delimiter", () => {
+ const input = {
+ data: [
+ { row_category: "a-b", col_category: "c", count: 10 },
+ { row_category: "a", col_category: "b-c", count: 99 },
+ ],
+ };
+
+ const result = generateConfusionMatrixData(input);
+
+ const cellAB_C = result.cells.find(
+ (c) =>
+ c.metadata?.rowCategory === "a-b" && c.metadata?.colCategory === "c",
+ );
+ const cellA_BC = result.cells.find(
+ (c) =>
+ c.metadata?.rowCategory === "a" && c.metadata?.colCategory === "b-c",
+ );
+ expect(cellAB_C?.value).toBe(10);
+ expect(cellA_BC?.value).toBe(99);
+ });
+
it("should handle empty confusion matrix data", () => {
const input = {
data: [],
diff --git a/web/src/features/score-analytics/lib/heatmap-utils.ts b/web/src/features/score-analytics/lib/heatmap-utils.ts
index 06666f5c41..6555b746d1 100644
--- a/web/src/features/score-analytics/lib/heatmap-utils.ts
+++ b/web/src/features/score-analytics/lib/heatmap-utils.ts
@@ -171,14 +171,14 @@ export function generateConfusionMatrixData({
// Create lookup map
const dataMap = new Map<string, number>();
data.forEach((d) => {
- dataMap.set(`${d.row_category}-${d.col_category}`, d.count);
+ dataMap.set(JSON.stringify([d.row_category, d.col_category]), d.count);
});
// Generate cells
const cells: HeatmapCell[] = [];
rowCategories.forEach((rowCat, rowIdx) => {
colCategories.forEach((colCat, colIdx) => {
- const count = dataMap.get(`${rowCat}-${colCat}`) || 0;
+ const count = dataMap.get(JSON.stringify([rowCat, colCat])) || 0;
const percentage = total > 0 ? (count / total) * 100 : 0;
const isDiagonal = rowCat === colCat;