🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix: propagate searchQuery to deleteMany call (#7274)
Steffen Schmitz3d7960f43e5c
diff --git a/packages/shared/src/features/batchAction/types.ts b/packages/shared/src/features/batchAction/types.tsindex 304069cff3..ba04c4b85e 100644--- a/packages/shared/src/features/batchAction/types.ts+++ b/packages/shared/src/features/batchAction/types.ts@@ -2,6 +2,7 @@ import z from "zod";import { singleFilter } from "../../interfaces/filters";import { orderBy } from "../../interfaces/orderBy";import { BatchTableNames } from "../../interfaces/tableNames";+import { TracingSearchType } from "../../interfaces/search";/* eslint-disable no-unused-vars */export enum BatchActionType {@@ -20,6 +21,8 @@ export type ActionId = z.infer<typeof ActionIdSchema>;export const BatchActionQuerySchema = z.object({filter: z.array(singleFilter).nullable(),orderBy,+ searchQuery: z.string().optional(),+ searchType: z.array(TracingSearchType).optional(),});export type BatchActionQuery = z.infer<typeof BatchActionQuerySchema>;diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsxindex 999992dd76..2e8547d639 100644--- a/web/src/components/table/use-cases/traces.tsx+++ b/web/src/components/table/use-cases/traces.tsx@@ -378,6 +378,8 @@ export default function TracesTable({query: {filter: filterState,orderBy: orderByState,+ searchQuery: searchQuery || undefined,+ searchType,},isBatchAction: selectAll,});diff --git a/worker/src/__tests__/batchAction.test.ts b/worker/src/__tests__/batchAction.test.tsindex d3df5f55e5..28f4088513 100644--- a/worker/src/__tests__/batchAction.test.ts+++ b/worker/src/__tests__/batchAction.test.ts@@ -182,6 +182,62 @@ describe("select all test suite", () => {expect(scores).toHaveLength(0);});+ it("should handle trace deletions with search query", async () => {+ const { projectId } = await createOrgProjectAndApiKey();++ const traces = [+ createTrace({+ project_id: projectId,+ id: uuidv4(),+ name: "search-target-trace",+ timestamp: new Date("2024-01-01").getTime(),+ }),+ createTrace({+ project_id: projectId,+ id: uuidv4(),+ name: "other-trace",+ timestamp: new Date("2024-01-01").getTime(),+ }),+ ];++ await createTracesCh(traces);++ const selectAllJob = {+ payload: {+ projectId,+ actionId: "trace-delete",+ tableName: BatchExportTableName.Traces,+ query: {+ filter: [],+ orderBy: { column: "timestamp", order: "DESC" },+ searchQuery: "search-target",+ searchType: ["id"],+ },+ cutoffCreatedAt: new Date("2024-01-02"),+ type: BatchActionType.Delete,+ },+ } as any;++ await handleBatchActionJob(selectAllJob);++ // Verify only the trace matching the search query was deleted+ const stream = await getDatabaseReadStream({+ projectId,+ tableName: BatchExportTableName.Traces,+ cutoffCreatedAt: new Date("2024-01-02"),+ filter: [],+ orderBy: { column: "timestamp", order: "DESC" },+ });++ const remainingRows: any[] = [];+ for await (const chunk of stream) {+ remainingRows.push(chunk);+ }++ expect(remainingRows).toHaveLength(1);+ expect(remainingRows[0].name).toBe("other-trace");+ });+it("should create eval jobs for historic traces", async () => {// remove all jobs from the evaluation execution queueconst queue = getQueue(QueueName.CreateEvalQueue);diff --git a/worker/src/features/batchAction/handleBatchActionJob.ts b/worker/src/features/batchAction/handleBatchActionJob.tsindex 025419c857..928b4fab39 100644--- a/worker/src/features/batchAction/handleBatchActionJob.ts+++ b/worker/src/features/batchAction/handleBatchActionJob.ts@@ -149,6 +149,8 @@ export const handleBatchActionJob = async (cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,+ searchQuery: query.searchQuery ?? undefined,+ searchType: query.searchType ?? ["id" as const],}): await getDatabaseReadStream({projectId: projectId,@@ -156,6 +158,8 @@ export const handleBatchActionJob = async (filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,tableName: tableName,+ searchQuery: query.searchQuery ?? undefined,+ searchType: query.searchType ?? ["id" as const],});// Process stream in database-sized batches@@ -205,6 +209,8 @@ export const handleBatchActionJob = async (cutoffCreatedAt: new Date(cutoffCreatedAt),filter: convertDatesInFiltersFromStrings(query.filter ?? []),orderBy: query.orderBy,+ searchQuery: query.searchQuery ?? undefined,+ searchType: query.searchType,rowLimit: env.LANGFUSE_MAX_HISTORIC_EVAL_CREATION_LIMIT,}) // when reading from clickhouse, we only want to read the necessary identifiers.: await getDatabaseReadStream({diff --git a/worker/src/features/database-read-stream/getDatabaseReadStream.ts b/worker/src/features/database-read-stream/getDatabaseReadStream.tsindex c820a73824..01351ddd81 100644--- a/worker/src/features/database-read-stream/getDatabaseReadStream.ts+++ b/worker/src/features/database-read-stream/getDatabaseReadStream.ts@@ -6,6 +6,7 @@ import {ScoreDomain,evalDatasetFormFilterCols,OrderByState,+ TracingSearchType,} from "@langfuse/shared";import { prisma } from "@langfuse/shared/src/db";import {@@ -86,10 +87,14 @@ export const getDatabaseReadStream = async ({filter,orderBy,cutoffCreatedAt,+ searchQuery,+ searchType,rowLimit = env.BATCH_EXPORT_ROW_LIMIT,}: {projectId: string;cutoffCreatedAt: Date;+ searchQuery?: string;+ searchType?: TracingSearchType[];rowLimit?: number;} & BatchExportQueryType): Promise<DatabaseReadStream<unknown>> => {// Set createdAt cutoff to prevent exporting data that was created after the job was queued@@ -291,7 +296,8 @@ export const getDatabaseReadStream = async ({filter: filter? [...filter, createdAtCutoffFilter]: [createdAtCutoffFilter],- searchType: ["id" as const],+ searchQuery,+ searchType: searchType ?? ["id" as const],orderBy,limit: pageSize,page: Math.floor(offset / pageSize),@@ -473,9 +479,19 @@ export const getTraceIdentifierStream = async (props: {cutoffCreatedAt: Date;filter: FilterCondition[];orderBy: OrderByState;+ searchQuery?: string;+ searchType?: TracingSearchType[];rowLimit?: number;}): Promise<DatabaseReadStream<Array<TraceIdentifiers>>> => {- const { projectId, cutoffCreatedAt, filter, orderBy, rowLimit } = props;+ const {+ projectId,+ cutoffCreatedAt,+ filter,+ orderBy,+ searchQuery,+ searchType,+ rowLimit,+ } = props;const createdAtCutoffFilter: FilterCondition = {column: "timestamp",@@ -495,7 +511,8 @@ export const getTraceIdentifierStream = async (props: {filter: filter? [...filter, createdAtCutoffFilter]: [createdAtCutoffFilter],- searchType: ["id" as const],+ searchQuery,+ searchType: searchType ?? ["id" as const],orderBy,limit: pageSize,page: Math.floor(offset / pageSize),