Skip to content

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

feat(score-analytics): improve single-score mode UX with proper preflight and mode-specific UI (#10318)

Michael Fröhlich830f2f2c34cc
diff --git a/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsNoticeBanner.tsx b/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsNoticeBanner.tsx
index 68970ac4d1..ab1549c710 100644
--- a/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsNoticeBanner.tsx
+++ b/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsNoticeBanner.tsx
@@ -53,8 +53,9 @@ export function ScoreAnalyticsNoticeBanner() {
</div>
{estimate && (
<div className="text-sm text-muted-foreground">
- Analyzing ~{estimate.score1Count.toLocaleString()} (Score 1) and
- ~{estimate.score2Count.toLocaleString()} (Score 2) scores
+ {estimate.mode === "single"
+ ? `Analyzing ~${estimate.score1Count.toLocaleString()} scores`
+ : `Analyzing ~${estimate.score1Count.toLocaleString()} (Score 1) and ~${estimate.score2Count.toLocaleString()} (Score 2) scores`}
{estimate.willSample && " • Sampling will be applied"}
{estimate.estimatedQueryTime && (
<> • Est. time: {estimate.estimatedQueryTime}</>
@@ -78,16 +79,13 @@ export function ScoreAnalyticsNoticeBanner() {
Sampled Data
<SamplingDetailsHoverCard
samplingMetadata={data.samplingMetadata}
+ mode={data.metadata.mode}
/>
</div>
<div className="text-sm text-muted-foreground">
- Results based on a{" "}
- {(data.samplingMetadata.samplingRate * 100).toFixed(2)}% sample of
- ~
- {data.samplingMetadata.preflightEstimates?.score1Count.toLocaleString()}{" "}
- Score 1 and ~
- {data.samplingMetadata.preflightEstimates?.score2Count.toLocaleString()}{" "}
- Score 2 data.
+ {data.metadata.mode === "single"
+ ? `Results based on a ${(data.samplingMetadata.samplingRate * 100).toFixed(2)}% sample of ~${data.samplingMetadata.preflightEstimates?.score1Count.toLocaleString()} scores.`
+ : `Results based on a ${(data.samplingMetadata.samplingRate * 100).toFixed(2)}% sample of ~${data.samplingMetadata.preflightEstimates?.score1Count.toLocaleString()} Score 1 and ~${data.samplingMetadata.preflightEstimates?.score2Count.toLocaleString()} Score 2 data.`}
</div>
</div>
</div>
@@ -101,6 +99,7 @@ export function ScoreAnalyticsNoticeBanner() {
function SamplingDetailsHoverCard({
samplingMetadata,
+ mode = "two",
showLabel = false,
}: {
samplingMetadata: {
@@ -115,6 +114,7 @@ function SamplingDetailsHoverCard({
reason: string;
};
};
+ mode?: "single" | "two";
showLabel?: boolean;
}) {
return (
@@ -137,29 +137,45 @@ function SamplingDetailsHoverCard({
<HoverCardContent className="w-80" align="start">
<div className="space-y-3">
<div>
- <h4 className="mb-2 text-sm font-semibold">Estimated Scores</h4>
+ <h4 className="mb-2 text-sm font-semibold">
+ {mode === "single" ? "Estimated Score Count" : "Estimated Scores"}
+ </h4>
<dl className="space-y-1 text-sm">
- <div className="flex justify-between">
- <dt className="text-muted-foreground">Score 1:</dt>
- <dd className="font-medium">
- ~
- {samplingMetadata.preflightEstimates?.score1Count.toLocaleString()}
- </dd>
- </div>
- <div className="flex justify-between">
- <dt className="text-muted-foreground">Score 2:</dt>
- <dd className="font-medium">
- ~
- {samplingMetadata.preflightEstimates?.score2Count.toLocaleString()}
- </dd>
- </div>
- <div className="flex justify-between">
- <dt className="text-muted-foreground">Estimated Matches:</dt>
- <dd className="font-medium">
- ~
- {samplingMetadata.preflightEstimates?.estimatedMatchedCount.toLocaleString()}
- </dd>
- </div>
+ {mode === "single" ? (
+ <div className="flex justify-between">
+ <dt className="text-muted-foreground">Total Scores:</dt>
+ <dd className="font-medium">
+ ~
+ {samplingMetadata.preflightEstimates?.score1Count.toLocaleString()}
+ </dd>
+ </div>
+ ) : (
+ <>
+ <div className="flex justify-between">
+ <dt className="text-muted-foreground">Score 1:</dt>
+ <dd className="font-medium">
+ ~
+ {samplingMetadata.preflightEstimates?.score1Count.toLocaleString()}
+ </dd>
+ </div>
+ <div className="flex justify-between">
+ <dt className="text-muted-foreground">Score 2:</dt>
+ <dd className="font-medium">
+ ~
+ {samplingMetadata.preflightEstimates?.score2Count.toLocaleString()}
+ </dd>
+ </div>
+ <div className="flex justify-between">
+ <dt className="text-muted-foreground">
+ Estimated Matches:
+ </dt>
+ <dd className="font-medium">
+ ~
+ {samplingMetadata.preflightEstimates?.estimatedMatchedCount.toLocaleString()}
+ </dd>
+ </div>
+ </>
+ )}
</dl>
</div>
diff --git a/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsProvider.tsx b/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsProvider.tsx
index ab0de2194f..9c965eb530 100644
--- a/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsProvider.tsx
+++ b/web/src/features/scores/components/score-analytics/components/ScoreAnalyticsProvider.tsx
@@ -63,6 +63,7 @@ export interface EstimateData {
willSample: boolean;
willSkipFinal: boolean;
estimatedQueryTime: string;
+ mode: "single" | "two";
}
export interface ScoreAnalyticsContextValue
@@ -108,17 +109,24 @@ export function ScoreAnalyticsProvider({
children,
}: ScoreAnalyticsProviderProps) {
// Step 1: Run estimate query first
- const canEstimate =
- params.score1 !== undefined && params.score2 !== undefined;
+ // Enable for both single-score and two-score modes to provide loading indicators
+ // and sampling transparency
+ const canEstimate = params.score1 !== undefined;
+
+ // Determine mode: "single" when only score1 selected, "two" when score2 explicitly provided
+ const mode: "single" | "two" = params.score2 === undefined ? "single" : "two";
const estimateQuery = api.scores.estimateScoreComparisonSize.useQuery(
{
projectId: params.projectId,
score1: params.score1 ?? { name: "", dataType: "", source: "" },
- score2: params.score2 ?? { name: "", dataType: "", source: "" },
+ // For single-score mode, pass score1 as score2 (backend will detect identical scores)
+ score2: params.score2 ??
+ params.score1 ?? { name: "", dataType: "", source: "" },
fromTimestamp: params.fromTimestamp,
toTimestamp: params.toTimestamp,
objectType: params.objectType ?? "all",
+ mode, // Pass explicit mode to backend
},
{
enabled: canEstimate,
@@ -127,8 +135,8 @@ export function ScoreAnalyticsProvider({
},
);
- // Step 2: Only run main query after estimate succeeds (two-score mode)
- // For single-score mode, run immediately without estimate
+ // Step 2: Only run main query after estimate succeeds
+ // This applies to both single-score and two-score modes now
const queryResult = useScoreAnalyticsQuery(params, {
enabled: !canEstimate || estimateQuery.isSuccess,
});
diff --git a/web/src/features/scores/components/score-analytics/components/cards/StatisticsCard.tsx b/web/src/features/scores/components/score-analytics/components/cards/StatisticsCard.tsx
index b7995cd3b5..dcd816cad7 100644
--- a/web/src/features/scores/components/score-analytics/components/cards/StatisticsCard.tsx
+++ b/web/src/features/scores/components/score-analytics/components/cards/StatisticsCard.tsx
@@ -113,6 +113,7 @@ export function StatisticsCard() {
{data.samplingMetadata.isSampled && (
<SamplingDetailsHoverCard
samplingMetadata={data.samplingMetadata}
+ mode={data.metadata.mode}
showLabel
/>
)}
diff --git a/web/src/features/scores/components/score-analytics/hooks/useScoreAnalyticsQuery.ts b/web/src/features/scores/components/score-analytics/hooks/useScoreAnalyticsQuery.ts
index 059bee2ed5..190c6aefc6 100644
--- a/web/src/features/scores/components/score-analytics/hooks/useScoreAnalyticsQuery.ts
+++ b/web/src/features/scores/components/score-analytics/hooks/useScoreAnalyticsQuery.ts
@@ -209,6 +209,9 @@ export function useScoreAnalyticsQuery(
nBins = 10,
} = params;
+ // Determine mode: "single" when only score1 selected, "two" when score2 explicitly provided
+ const mode: "single" | "two" = score2 === undefined ? "single" : "two";
+
// Fetch API data
const {
data: apiData,
@@ -219,6 +222,7 @@ export function useScoreAnalyticsQuery(
projectId,
score1,
score2: score2 ?? score1, // Use same score if only one selected
+ mode, // Pass explicit mode to backend
fromTimestamp,
toTimestamp,
interval,
@@ -234,21 +238,11 @@ export function useScoreAnalyticsQuery(
const transformedData = useMemo<ScoreAnalyticsData | null>(() => {
if (!apiData) return null;
- const dataType = score1.dataType;
+ // Use metadata from backend (authoritative source for mode, isSameScore, dataType)
+ const { mode, isSameScore } = apiData.metadata;
+ const dataType = apiData.metadata.dataType as DataType;
const isNumeric = dataType === "NUMERIC";
- // Determine mode based on whether score2 was originally provided in params
- // (not the fallback value sent to the API at line 190)
- const mode: "single" | "two" = score2 !== undefined ? "two" : "single";
-
- // Determine if we have two scores and if they're the same
- const isSameScore = Boolean(
- score1 &&
- score2 &&
- score1.name === score2.name &&
- score1.source === score2.source,
- );
-
// ========================================================================
// 1. Extract categories (categorical/boolean only)
// ========================================================================
@@ -635,6 +629,7 @@ export function useScoreAnalyticsQuery(
},
},
heatmap,
+ // Use metadata from API response (backend echoes mode and provides authoritative isSameScore)
metadata: {
mode,
isSameScore,
diff --git a/web/src/server/api/routers/scores.ts b/web/src/server/api/routers/scores.ts
index 5daf02a044..4907b3fe21 100644
--- a/web/src/server/api/routers/scores.ts
+++ b/web/src/server/api/routers/scores.ts
@@ -931,6 +931,7 @@ export const scoresRouter = createTRPCRouter({
objectType: z
.enum(["all", "trace", "session", "observation", "dataset_run"])
.default("all"),
+ mode: z.enum(["single", "two"]).optional(), // Frontend passes "single" when only score1 selected
}),
)
.query(async ({ input }) => {
@@ -997,6 +998,7 @@ export const scoresRouter = createTRPCRouter({
willSample,
willSkipFinal,
estimatedQueryTime,
+ mode: input.mode ?? "two", // Echo back the mode from frontend
};
}),
@@ -1018,6 +1020,7 @@ export const scoresRouter = createTRPCRouter({
dataType: z.string(),
source: z.string(),
}),
+ mode: z.enum(["single", "two"]).optional(), // Frontend passes "single" when only score1 selected
fromTimestamp: z.date(),
toTimestamp: z.date(),
interval: z
@@ -2324,6 +2327,12 @@ export const scoresRouter = createTRPCRouter({
: "Large dataset - skipping FINAL for performance",
},
},
+ // Metadata about query mode and score comparison
+ metadata: {
+ mode: input.mode ?? "two", // Echo back the mode from frontend
+ isSameScore: isIdenticalScores,
+ dataType: score1.dataType,
+ },
};
}),
});