Skip to content

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

fix(worker): add deduplication to experiments backfill queries (#11226)

Steffen Schmitz082f18937fbc
diff --git a/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts b/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
index 2646ddefe3..76af41be50 100644
--- a/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
+++ b/worker/src/backgroundMigrations/backfillExperimentsHistoric.ts
@@ -250,6 +250,8 @@ export default class BackfillExperimentsHistoric
FROM observations o
WHERE o.project_id IN {projectIds: Array(String)}
AND o.trace_id IN {traceIds: Array(String)}
+ ORDER BY o.event_ts DESC
+ LIMIT 1 BY o.project_id, o.trace_id, o.id
`;
return queryClickhouse<SpanRecord>({
@@ -313,6 +315,8 @@ export default class BackfillExperimentsHistoric
FROM traces t
WHERE t.project_id IN {projectIds: Array(String)}
AND t.id IN {traceIds: Array(String)}
+ ORDER BY t.event_ts DESC
+ LIMIT 1 BY t.project_id, t.id
`;
return queryClickhouse<SpanRecord>({