Skip to content

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

feat: full text search (#6343)

Max Deichmanne3fa322ecfd4
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index 95dd1e60ca..34347ce389 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -54,6 +54,7 @@ export * from "./server/utils/metadata_conversion";
export * from "./errors/index";
export * from "./utils/environment";
+export * from "./interfaces/search";
// domain
export * from "./domain";
diff --git a/packages/shared/src/interfaces/search.ts b/packages/shared/src/interfaces/search.ts
new file mode 100644
index 0000000000..bb7ad65592
--- /dev/null
+++ b/packages/shared/src/interfaces/search.ts
@@ -0,0 +1,6 @@
+import { z } from "zod";
+
+export const TracingSearchType = z.enum(["id", "content"]);
+// id: for searching smaller columns like IDs, types, and other metadata
+// content: for searching input/output text of functions traced via OpenTelemetry
+export type TracingSearchType = z.infer<typeof TracingSearchType>;
diff --git a/packages/shared/src/server/queries/clickhouse-sql/search.ts b/packages/shared/src/server/queries/clickhouse-sql/search.ts
index 885f77e4e2..4726dd690b 100644
--- a/packages/shared/src/server/queries/clickhouse-sql/search.ts
+++ b/packages/shared/src/server/queries/clickhouse-sql/search.ts
@@ -1,16 +1,22 @@
+import { TracingSearchType } from "../../../interfaces/search";
+
const regexIndefiniteCharacters = "%";
-export const clickhouseSearchCondition = (query?: string) => {
+export const clickhouseSearchCondition = (
+ query?: string,
+ searchType?: TracingSearchType[],
+) => {
+ const conditions = [
+ !searchType || searchType.includes("id")
+ ? `id ILIKE {searchString: String} OR user_id ILIKE {searchString: String} OR name ILIKE {searchString: String}`
+ : null,
+ searchType && searchType.includes("content")
+ ? `input ILIKE {searchString: String} OR output ILIKE {searchString: String}`
+ : null,
+ ].filter(Boolean);
+
return {
- query: query
- ? `
- AND (
- id ILIKE {searchString: String} OR
- user_id ILIKE {searchString: String} OR
- name ILIKE {searchString: String}
- )
- `
- : "",
+ query: query ? `AND (${conditions.join(" OR ")})` : "",
params: query
? {
searchString: `${regexIndefiniteCharacters}${query}${regexIndefiniteCharacters}`,
diff --git a/packages/shared/src/server/repositories/observations.ts b/packages/shared/src/server/repositories/observations.ts
index 52a9703482..4f021b0a89 100644
--- a/packages/shared/src/server/repositories/observations.ts
+++ b/packages/shared/src/server/repositories/observations.ts
@@ -22,7 +22,6 @@ import {
observationsTableTraceUiColumnDefinitions,
observationsTableUiColumnDefinitions,
} from "../../tableDefinitions";
-import { TableCount } from "./types";
import { OrderByState } from "../../interfaces/orderBy";
import { getTracesByIds } from "./traces";
import { convertDateToClickhouseDateTime } from "../clickhouse/client";
@@ -33,6 +32,7 @@ import {
TRACE_TO_OBSERVATIONS_INTERVAL,
} from "./constants";
import { env } from "../../env";
+import { TracingSearchType } from "../../interfaces/search";
import { ClickHouseClientConfigOptions } from "@clickhouse/client";
/**
@@ -413,6 +413,7 @@ export type ObservationTableQuery = {
filter: FilterState;
orderBy?: OrderByState;
searchQuery?: string;
+ searchType?: TracingSearchType[];
limit?: number;
offset?: number;
selectIOAndMetadata?: boolean;
@@ -427,13 +428,20 @@ export type ObservationsTableQueryResult = ObservationRecordReadType & {
trace_user_id?: string;
};
-export const getObservationsTableCount = async (opts: ObservationTableQuery) =>
- getObservationsTableInternal<TableCount>({
+export const getObservationsTableCount = async (
+ opts: ObservationTableQuery,
+) => {
+ const count = await getObservationsTableInternal<{
+ count: string;
+ }>({
...opts,
select: "count",
tags: { kind: "count" },
});
+ return Number(count[0].count);
+};
+
export const getObservationsTableWithModelData = async (
opts: ObservationTableQuery,
): Promise<FullObservations> => {
@@ -627,7 +635,7 @@ const getObservationsTableInternal = async <T>(
const appliedScoresFilter = scoresFilter.apply();
const appliedObservationsFilter = observationsFilter.apply();
- const search = clickhouseSearchCondition(opts.searchQuery);
+ const search = clickhouseSearchCondition(opts.searchQuery, opts.searchType);
const scoresCte = `WITH scores_agg AS (
SELECT
diff --git a/packages/shared/src/server/services/traces-ui-table-service.ts b/packages/shared/src/server/services/traces-ui-table-service.ts
index ab3f421efa..535a42f83f 100644
--- a/packages/shared/src/server/services/traces-ui-table-service.ts
+++ b/packages/shared/src/server/services/traces-ui-table-service.ts
@@ -22,6 +22,7 @@ import {
queryClickhouse,
reduceUsageOrCostDetails,
} from "../repositories";
+import { TracingSearchType } from "../../interfaces/search";
import { ObservationLevelType, TraceDomain } from "../../domain";
import { ClickHouseClientConfigOptions } from "@clickhouse/client";
@@ -160,6 +161,7 @@ export type FetchTracesTableProps = {
projectId: string;
filter: FilterState;
searchQuery?: string;
+ searchType?: TracingSearchType[];
orderBy?: OrderByState;
limit?: number;
page?: number;
@@ -171,6 +173,7 @@ export const getTracesTableCount = async (props: {
projectId: string;
filter: FilterState;
searchQuery?: string;
+ searchType: TracingSearchType[];
orderBy?: OrderByState;
limit?: number;
page?: number;
@@ -211,6 +214,7 @@ export const getTracesTable = async (p: {
projectId: string;
filter: FilterState;
searchQuery?: string;
+ searchType?: TracingSearchType[];
orderBy?: OrderByState;
limit?: number;
page?: number;
@@ -220,6 +224,7 @@ export const getTracesTable = async (p: {
projectId,
filter,
searchQuery,
+ searchType,
orderBy,
limit,
page,
@@ -231,6 +236,7 @@ export const getTracesTable = async (p: {
projectId,
filter,
searchQuery,
+ searchType,
orderBy,
limit,
page,
@@ -249,6 +255,7 @@ const getTracesTableGeneric = async <T>(props: FetchTracesTableProps) => {
limit,
page,
searchQuery,
+ searchType,
clickhouseConfigs,
} = props;
@@ -358,7 +365,7 @@ const getTracesTableGeneric = async <T>(props: FetchTracesTableProps) => {
const scoresFilterRes = scoresFilter.apply();
const observationFilterRes = observationsFilter.apply();
- const search = clickhouseSearchCondition(searchQuery);
+ const search = clickhouseSearchCondition(searchQuery, searchType);
const defaultOrder = orderBy?.order && orderBy?.column === "timestamp";
const orderByCols = [
diff --git a/web/src/components/table/data-table-toolbar.tsx b/web/src/components/table/data-table-toolbar.tsx
index 2368d88cb1..d66c4b9fb0 100644
--- a/web/src/components/table/data-table-toolbar.tsx
+++ b/web/src/components/table/data-table-toolbar.tsx
@@ -1,10 +1,5 @@
import { Button } from "@/src/components/ui/button";
-import React, {
- type Dispatch,
- type SetStateAction,
- useEffect,
- useState,
-} from "react";
+import React, { type Dispatch, type SetStateAction, useState } from "react";
import { Input } from "@/src/components/ui/input";
import { DataTableColumnVisibilityFilter } from "@/src/components/table/data-table-column-visibility-filter";
import { PopoverFilterBuilder } from "@/src/features/filters/components/filter-builder";
@@ -14,6 +9,7 @@ import {
type OrderByState,
type TableViewPresetDomain,
type TableViewPresetTableName,
+ type TracingSearchType,
} from "@langfuse/shared";
import {
type RowSelectionState,
@@ -35,6 +31,7 @@ import {
import { DataTableSelectAllBanner } from "@/src/components/table/data-table-multi-select-actions/data-table-select-all-banner";
import { MultiSelect } from "@/src/features/filters/components/multi-select";
import { cn } from "@/src/utils/tailwind";
+import DocPopup from "@/src/components/layouts/doc-popup";
import { TableViewPresetsDrawer } from "@/src/components/table/table-view-presets/components/data-table-view-presets-drawer";
export interface MultiSelect {
@@ -48,9 +45,12 @@ export interface MultiSelect {
}
interface SearchConfig {
- placeholder: string;
- updateQuery(event: string): void;
+ metadataSearchFields: string[];
+ updateQuery: (event: string) => void;
currentQuery?: string;
+ tableAllowsFullTextSearch?: boolean;
+ setSearchType: ((newSearchType: TracingSearchType[]) => void) | undefined;
+ searchType: TracingSearchType[] | undefined;
}
interface TableViewControllers {
@@ -122,45 +122,84 @@ export function DataTableToolbar<TData, TValue>({
const [searchString, setSearchString] = useState(
searchConfig?.currentQuery ?? "",
);
- const capture = usePostHogClientCapture();
- // Update searchString when searchConfig.currentQuery changes to account for saved view selection
- // Only update once on initial value of searchConfig.currentQuery, to allow for initial value to be set
- useEffect(() => {
- if (searchConfig?.currentQuery !== searchString) {
- setSearchString(searchConfig?.currentQuery ?? "");
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [searchConfig?.currentQuery]);
+ const capture = usePostHogClientCapture();
return (
<div className={cn("grid h-fit w-full gap-0 px-2", className)}>
<div className="my-2 flex flex-wrap items-center gap-2 @container">
{searchConfig && (
- <div className="flex max-w-md items-center rounded-md border">
- <Button
- variant="ghost"
- size="icon"
- onClick={() => {
- capture("table:search_submit");
- searchConfig.updateQuery(searchString);
- }}
- >
- <Search className="h-4 w-4" />
- </Button>
- <Input
- autoFocus
- placeholder={searchConfig.placeholder}
- value={searchString}
- onChange={(event) => setSearchString(event.currentTarget.value)}
- onKeyDown={(event) => {
- if (event.key === "Enter") {
+ <div className="flex w-full max-w-xl items-center justify-between rounded-md border">
+ <div className="flex flex-1 items-center">
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => {
capture("table:search_submit");
searchConfig.updateQuery(searchString);
+ }}
+ >
+ <Search className="h-4 w-4" />
+ </Button>
+ <Input
+ autoFocus
+ placeholder={
+ searchConfig.tableAllowsFullTextSearch
+ ? "Search..."
+ : `Search (${searchConfig.metadataSearchFields.length > 0 ? searchConfig.metadataSearchFields.join(", ") : ""})`
}
- }}
- className="min-w-0 max-w-fit border-none px-0"
- />
+ value={searchString}
+ onChange={(event) => setSearchString(event.currentTarget.value)}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") {
+ capture("table:search_submit");
+ searchConfig.updateQuery(searchString);
+ }
+ }}
+ className="w-full border-none px-0"
+ />
+ </div>
+ {searchConfig.tableAllowsFullTextSearch &&
+ searchConfig.setSearchType && (
+ <div className="border-l px-2">
+ <Button
+ variant="tertiary"
+ size="sm"
+ className="flex items-center gap-1"
+ onClick={() => {
+ const newSearchType =
+ (searchConfig.searchType ?? []).indexOf("content") >= 0
+ ? ["id" as const]
+ : ["id" as const, "content" as const];
+ searchConfig?.setSearchType?.(newSearchType);
+ }}
+ >
+ <>
+ {(searchConfig.searchType ?? []).indexOf("content") >= 0
+ ? "Metadata + Full Text"
+ : "Metadata"}
+ <DocPopup
+ description={
+ <>
+ <p className="text-xs font-normal text-primary">
+ <strong>Metadata search:</strong>{" "}
+ {searchConfig.metadataSearchFields.join(", ")}
+ </p>
+ <p className="text-xs font-normal text-primary">
+ <strong>Full text search:</strong> Input, Output
+ </p>
+ <br />
+ <p className="text-xs font-normal text-primary">
+ For improved performance, filter the table before
+ searching.
+ </p>
+ </>
+ }
+ />
+ </>
+ </Button>
+ </div>
+ )}
</div>
)}
{selectedOption && setDateRangeAndOption && (
diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsx
index 53d4ca3c5f..4ec7d42d99 100644
--- a/web/src/components/table/use-cases/observations.tsx
+++ b/web/src/components/table/use-cases/observations.tsx
@@ -3,13 +3,7 @@ import { DataTable } from "@/src/components/table/data-table";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import { useEffect, useMemo } from "react";
import { TokenUsageBadge } from "@/src/components/token-usage-badge";
-import {
- NumberParam,
- StringParam,
- useQueryParam,
- useQueryParams,
- withDefault,
-} from "use-query-params";
+import { NumberParam, useQueryParams, withDefault } from "use-query-params";
import { useQueryFilterState } from "@/src/features/filters/hooks/useFilterState";
import { formatIntervalSeconds } from "@/src/utils/dates";
import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
@@ -59,6 +53,7 @@ import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context
import { useObservationPeekNavigation } from "@/src/components/table/peek/hooks/useObservationPeekNavigation";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
import { useRouter } from "next/router";
+import { useFullTextSearch } from "@/src/components/table/use-cases/useFullTextSearch";
export type ObservationsTableRow = {
// Shown by default
@@ -120,12 +115,11 @@ export default function ObservationsTable({
const router = useRouter();
const { viewId } = router.query;
- const [searchQuery, setSearchQuery] = useQueryParam(
- "search",
- withDefault(StringParam, null),
- );
const { setDetailPageList } = useDetailPageLists();
+ const { searchQuery, searchType, setSearchQuery, setSearchType } =
+ useFullTextSearch();
+
const [paginationState, setPaginationState] = useQueryParams({
pageIndex: withDefault(NumberParam, 0),
pageSize: withDefault(NumberParam, 50),
@@ -239,6 +233,7 @@ export default function ObservationsTable({
projectId,
filter: filterState,
searchQuery,
+ searchType,
page: 0,
limit: 0,
orderBy: null,
@@ -929,9 +924,11 @@ export default function ObservationsTable({
filterState={inputFilterState}
setFilterState={useDebounce(setInputFilterState)}
searchConfig={{
- placeholder: "Search (by id, name, trace name, model)",
+ metadataSearchFields: ["ID", "Name", "Trace Name", "Model"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
+ searchType,
+ setSearchType,
}}
viewConfig={{
tableName: TableViewPresetTableName.Observations,
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index c3ae587f5a..452a5f47a5 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -12,13 +12,7 @@ import { formatIntervalSeconds } from "@/src/utils/dates";
import { type RouterOutput } from "@/src/utils/types";
import { type Row, type RowSelectionState } from "@tanstack/react-table";
import { useEffect, useMemo, useState } from "react";
-import {
- NumberParam,
- StringParam,
- useQueryParam,
- useQueryParams,
- withDefault,
-} from "use-query-params";
+import { NumberParam, useQueryParams, withDefault } from "use-query-params";
import type Decimal from "decimal.js";
import { numberFormatter, usdFormatter } from "@/src/utils/numbers";
import { DeleteTraceButton } from "@/src/components/deleteButton";
@@ -83,6 +77,7 @@ import { PeekViewTraceDetail } from "@/src/components/table/peek/peek-trace-deta
import { useTracePeekNavigation } from "@/src/components/table/peek/hooks/useTracePeekNavigation";
import { useTracePeekState } from "@/src/components/table/peek/hooks/useTracePeekState";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
+import { useFullTextSearch } from "@/src/components/table/use-cases/useFullTextSearch";
export type TracesTableRow = {
// Shown by default
@@ -141,12 +136,10 @@ export default function TracesTable({
const utils = api.useUtils();
const [selectedRows, setSelectedRows] = useState<RowSelectionState>({});
const { setDetailPageList } = useDetailPageLists();
- const [searchQuery, setSearchQuery] = useQueryParam(
- "search",
- withDefault(StringParam, null),
- );
+
const { selectedOption, dateRange, setDateRangeAndOption } =
useTableDateRange(projectId);
+
const [userFilterState, setUserFilterState] = useQueryFilterState(
[],
"traces",
@@ -213,28 +206,36 @@ export default function TracesTable({
});
const { selectAll, setSelectAll } = useSelectAll(projectId, "traces");
+ const { searchQuery, searchType, setSearchQuery, setSearchType } =
+ useFullTextSearch();
+
const tracesAllCountFilter = {
projectId,
filter: filterState,
- searchQuery,
- // "empty" values as they do not matter for total count
+ searchQuery: searchQuery,
+ searchType: searchType,
page: 0,
limit: 0,
orderBy: null,
};
+ const totalCountQuery = api.traces.countAll.useQuery(tracesAllCountFilter, {
+ enabled: environmentFilterOptions.data !== undefined,
+ });
+
const tracesAllQueryFilter = {
...tracesAllCountFilter,
+ searchQuery: searchQuery,
+ searchType: searchType,
page: paginationState.pageIndex,
limit: paginationState.pageSize,
orderBy: orderByState,
};
+
const traces = api.traces.all.useQuery(tracesAllQueryFilter, {
enabled: environmentFilterOptions.data !== undefined,
});
- const totalCountQuery = api.traces.countAll.useQuery(tracesAllCountFilter, {
- enabled: environmentFilterOptions.data !== undefined,
- });
+
const traceMetrics = api.traces.metrics.useQuery(
{
projectId,
@@ -550,7 +551,6 @@ export default function TracesTable({
return null;
}
-
return (
<BreakdownTooltip details={row.original.tokenDetails ?? []}>
<div className="flex items-center gap-1">
@@ -1031,9 +1031,12 @@ export default function TracesTable({
}}
filterColumnDefinition={transformedFilterOptions}
searchConfig={{
- placeholder: "Search (by id, name, trace name, user id)",
+ metadataSearchFields: ["ID", "Name", "Trace Name", "User ID"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
+ tableAllowsFullTextSearch: true,
+ setSearchType,
+ searchType,
}}
filterState={userFilterState}
setFilterState={useDebounce(setUserFilterState)}
diff --git a/web/src/components/table/use-cases/useFullTextSearch.tsx b/web/src/components/table/use-cases/useFullTextSearch.tsx
new file mode 100644
index 0000000000..c4e2248743
--- /dev/null
+++ b/web/src/components/table/use-cases/useFullTextSearch.tsx
@@ -0,0 +1,35 @@
+import type { TracingSearchType } from "@langfuse/shared";
+import {
+ useQueryParam,
+ withDefault,
+ StringParam,
+ ArrayParam,
+} from "use-query-params";
+
+export const useFullTextSearch = () => {
+ const [searchQuery, setSearchQuery] = useQueryParam(
+ "search",
+ withDefault(StringParam, null),
+ );
+
+ // Search type can be either "id" or "metadata". Keep it untyped here and
+ // cast later to the stricter `TracingSearchType[]` to avoid type mismatch
+ // with the generic `ArrayParam` from `use-query-params`.
+ const [searchType, handleSearchTypeChange] = useQueryParam(
+ "searchType",
+ withDefault(ArrayParam, ["id"]),
+ );
+
+ const setSearchType = (newSearchType: TracingSearchType[]) => {
+ handleSearchTypeChange(newSearchType);
+ };
+
+ const typedSearchType = (searchType ?? ["id"]) as TracingSearchType[];
+
+ return {
+ searchQuery,
+ searchType: typedSearchType,
+ setSearchQuery,
+ setSearchType,
+ };
+};
diff --git a/web/src/ee/features/evals/hooks/useEvalTargetCount.ts b/web/src/ee/features/evals/hooks/useEvalTargetCount.ts
index eeedd9f510..83a722220b 100644
--- a/web/src/ee/features/evals/hooks/useEvalTargetCount.ts
+++ b/web/src/ee/features/evals/hooks/useEvalTargetCount.ts
@@ -33,6 +33,7 @@ export function useEvalTargetCount({
const tracesAllCountFilter = {
...baseAllCountFilter,
searchQuery: null,
+ searchType: ["id" as const],
orderBy: null,
};
diff --git a/web/src/features/datasets/components/DatasetsTable.tsx b/web/src/features/datasets/components/DatasetsTable.tsx
index 032a8fd4cf..0ffe3a06c0 100644
--- a/web/src/features/datasets/components/DatasetsTable.tsx
+++ b/web/src/features/datasets/components/DatasetsTable.tsx
@@ -263,9 +263,12 @@ export function DatasetsTable(props: { projectId: string }) {
rowHeight={rowHeight}
setRowHeight={setRowHeight}
searchConfig={{
- placeholder: "Search by name",
+ metadataSearchFields: ["Name"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
+ tableAllowsFullTextSearch: false,
+ setSearchType: undefined,
+ searchType: undefined,
}}
viewConfig={{
tableName: TableViewPresetTableName.Datasets,
diff --git a/web/src/pages/project/[projectId]/users.tsx b/web/src/pages/project/[projectId]/users.tsx
index a69951b5cf..f4136ca215 100644
--- a/web/src/pages/project/[projectId]/users.tsx
+++ b/web/src/pages/project/[projectId]/users.tsx
@@ -342,9 +342,12 @@ const UsersTable = () => {
selectedOption={selectedOption}
setDateRangeAndOption={setDateRangeAndOption}
searchConfig={{
- placeholder: "Search by user id",
+ metadataSearchFields: ["User ID"],
updateQuery: setSearchQuery,
currentQuery: searchQuery ?? undefined,
+ tableAllowsFullTextSearch: false,
+ setSearchType: undefined,
+ searchType: undefined,
}}
environmentFilter={{
values: selectedEnvironments,
diff --git a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
index 50d84c9b32..5c9d527814 100644
--- a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
+++ b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
@@ -19,6 +19,7 @@ export async function getAllGenerations({
filter: input.filter,
orderBy: input.orderBy,
searchQuery: input.searchQuery ?? undefined,
+ searchType: input.searchType,
selectIOAndMetadata: selectIOAndMetadata,
offset: input.page * input.limit,
limit: input.limit,
diff --git a/web/src/server/api/routers/generations/getAllQueries.ts b/web/src/server/api/routers/generations/getAllQueries.ts
index deb9f70594..33ce9329dc 100644
--- a/web/src/server/api/routers/generations/getAllQueries.ts
+++ b/web/src/server/api/routers/generations/getAllQueries.ts
@@ -31,7 +31,7 @@ export const getAllQueries = {
offset: 0,
});
return {
- totalCount: countQuery.shift()?.count,
+ totalCount: countQuery,
};
}),
};
diff --git a/web/src/server/api/routers/generations/utils/GenerationTableOptions.ts b/web/src/server/api/routers/generations/utils/GenerationTableOptions.ts
index 104fc21f1a..01b523e56c 100644
--- a/web/src/server/api/routers/generations/utils/GenerationTableOptions.ts
+++ b/web/src/server/api/routers/generations/utils/GenerationTableOptions.ts
@@ -1,10 +1,11 @@
import { z } from "zod";
-import { singleFilter } from "@langfuse/shared";
+import { singleFilter, TracingSearchType } from "@langfuse/shared";
import { orderBy } from "@langfuse/shared";
export const GenerationTableOptions = z.object({
projectId: z.string(), // Required for protectedProjectProcedure
filter: z.array(singleFilter),
searchQuery: z.string().nullable(),
+ searchType: z.array(TracingSearchType),
orderBy: orderBy,
});
diff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.ts
index 5cb8b19e79..42a4136444 100644
--- a/web/src/server/api/routers/traces.ts
+++ b/web/src/server/api/routers/traces.ts
@@ -18,6 +18,7 @@ import {
timeFilter,
tracesTableUiColumnDefinitions,
type Observation,
+ TracingSearchType,
} from "@langfuse/shared";
import {
traceException,
@@ -46,6 +47,7 @@ import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEnti
const TraceFilterOptions = z.object({
projectId: z.string(), // Required for protectedProjectProcedure
searchQuery: z.string().nullable(),
+ searchType: z.array(TracingSearchType),
filter: z.array(singleFilter).nullable(),
orderBy: orderBy,
...paginationZod,
@@ -82,6 +84,7 @@ export const traceRouter = createTRPCRouter({
projectId: ctx.session.projectId,
filter: input.filter ?? [],
searchQuery: input.searchQuery ?? undefined,
+ searchType: input.searchType ?? ["id"],
orderBy: input.orderBy,
limit: input.limit,
page: input.page,
@@ -91,14 +94,18 @@ export const traceRouter = createTRPCRouter({
countAll: protectedProjectProcedure
.input(TraceFilterOptions)
.query(async ({ input, ctx }) => {
- const totalCount = await getTracesTableCount({
+ const count = await getTracesTableCount({
projectId: ctx.session.projectId,
filter: input.filter ?? [],
+ searchType: input.searchType,
searchQuery: input.searchQuery ?? undefined,
limit: 1,
page: 0,
});
- return { totalCount };
+
+ return {
+ totalCount: count,
+ };
}),
metrics: protectedProjectProcedure
.input(
diff --git a/worker/src/features/database-read-stream/getDatabaseReadStream.ts b/worker/src/features/database-read-stream/getDatabaseReadStream.ts
index 1633750191..7499e3f48c 100644
--- a/worker/src/features/database-read-stream/getDatabaseReadStream.ts
+++ b/worker/src/features/database-read-stream/getDatabaseReadStream.ts
@@ -287,6 +287,7 @@ export const getDatabaseReadStream = async ({
filter: filter
? [...filter, createdAtCutoffFilter]
: [createdAtCutoffFilter],
+ searchType: ["id" as const],
orderBy,
limit: pageSize,
page: Math.floor(offset / pageSize),