Skip to content

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

perf: limit filteroptions api (#1973)

Max Deichmann74da65f9b28d
diff --git a/web/src/server/api/routers/generations/filterOptionsQuery.ts b/web/src/server/api/routers/generations/filterOptionsQuery.ts
index 16171514c1..760997b0ed 100644
--- a/web/src/server/api/routers/generations/filterOptionsQuery.ts
+++ b/web/src/server/api/routers/generations/filterOptionsQuery.ts
@@ -18,6 +18,10 @@ export const filterOptionsQuery = protectedProjectProcedure
projectId: input.projectId,
},
},
+ take: 1000,
+ orderBy: {
+ name: "desc",
+ },
by: ["name"],
});
@@ -25,11 +29,19 @@ export const filterOptionsQuery = protectedProjectProcedure
by: ["model"],
where: queryFilter,
_count: { _all: true },
+ take: 1000,
+ orderBy: {
+ model: "desc",
+ },
});
const name = await ctx.prisma.observation.groupBy({
by: ["name"],
where: queryFilter,
_count: { _all: true },
+ take: 1000,
+ orderBy: {
+ name: "desc",
+ },
});
const promptNames = await ctx.prisma.$queryRaw<
Array<{
@@ -47,6 +59,7 @@ export const filterOptionsQuery = protectedProjectProcedure
AND o.prompt_id IS NOT NULL
AND p.project_id = ${input.projectId}
GROUP BY 1
+ LIMIT 1000
`);
const traceName = await ctx.prisma.$queryRaw<
Array<{
@@ -63,6 +76,7 @@ export const filterOptionsQuery = protectedProjectProcedure
AND o.project_id = ${input.projectId}
AND t.project_id = ${input.projectId}
GROUP BY 1
+ LIMIT 1000
`);
// typecheck filter options, needs to include all columns with options
diff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.ts
index d64a43ce9b..a34fad092d 100644
--- a/web/src/server/api/routers/traces.ts
+++ b/web/src/server/api/routers/traces.ts
@@ -182,6 +182,12 @@ export const traceRouter = createTRPCRouter({
projectId: input.projectId,
},
},
+ take: 1000,
+ orderBy: {
+ _count: {
+ id: "desc",
+ },
+ },
by: ["name"],
});
const names = await ctx.prisma.trace.groupBy({
@@ -207,7 +213,8 @@ export const traceRouter = createTRPCRouter({
SELECT COUNT(*)::integer AS "count", tags.tag as value
FROM traces, UNNEST(traces.tags) AS tags(tag)
WHERE traces.project_id = ${input.projectId}
- GROUP BY tags.tag;
+ GROUP BY tags.tag
+ LIMIT 1000
`;
const res: TraceOptions = {
scores_avg: scores.map((score) => score.name),