Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(filters): replace search scope dropdowns with inline suggestions (#17350)

Nikita Kabardinf08c351a2683
diff --git a/web/src/components/table/SearchScopeSelect.tsx b/web/src/components/table/SearchScopeSelect.tsx
deleted file mode 100644
index a58808baaa..0000000000
--- a/web/src/components/table/SearchScopeSelect.tsx
+++ /dev/null
@@ -1,83 +0,0 @@
-import { ChevronDown } from "lucide-react";
-import type { TracingSearchType } from "@langfuse/shared";
-import { Button } from "@/src/components/ui/button";
-import {
- DropdownMenuController,
- DropdownMenuRadioGroup,
- DropdownMenuRadioItem,
- DropdownMenuSub,
- DropdownMenuSubTrigger,
- DropdownMenuSubContent,
-} from "@/src/components/ui/dropdown-menu";
-import {
- getSearchButtonLabel,
- getSearchMode,
- searchModeToType,
-} from "@/src/components/table/utils/searchUtils";
-
-export function SearchScopeSelect({
- searchType,
- setSearchType,
- metadataLabel,
- fullTextLabel,
- availableSearchTypes,
-}: {
- searchType: TracingSearchType[];
- setSearchType: (types: TracingSearchType[]) => void;
- metadataLabel: string;
- fullTextLabel: string;
- availableSearchTypes: { content: boolean; input: boolean; output: boolean };
-}) {
- const mode = getSearchMode(searchType, true);
- return (
- <DropdownMenuController
- align="end"
- renderMenu={() => (
- <DropdownMenuRadioGroup
- value={mode}
- onValueChange={(value) => setSearchType(searchModeToType(value))}
- >
- <DropdownMenuRadioItem value="metadata">
- {metadataLabel}
- </DropdownMenuRadioItem>
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>{fullTextLabel}</DropdownMenuSubTrigger>
- <DropdownMenuSubContent>
- <DropdownMenuRadioGroup
- value={mode}
- onValueChange={(value) =>
- setSearchType(searchModeToType(value))
- }
- >
- {availableSearchTypes.content && (
- <DropdownMenuRadioItem value="metadata_fulltext">
- Input/Output
- </DropdownMenuRadioItem>
- )}
- {availableSearchTypes.input && (
- <DropdownMenuRadioItem value="metadata_fulltext_input">
- Input
- </DropdownMenuRadioItem>
- )}
- {availableSearchTypes.output && (
- <DropdownMenuRadioItem value="metadata_fulltext_output">
- Output
- </DropdownMenuRadioItem>
- )}
- </DropdownMenuRadioGroup>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- </DropdownMenuRadioGroup>
- )}
- >
- {({ Trigger }) => (
- <Trigger asChild>
- <Button variant="outline" size="sm" aria-label="Search scope">
- {getSearchButtonLabel(searchType, metadataLabel)}
- <ChevronDown className="h-4 w-4" />
- </Button>
- </Trigger>
- )}
- </DropdownMenuController>
- );
-}
diff --git a/web/src/components/table/use-cases/observations.tsx b/web/src/components/table/use-cases/observations.tsx
index c64fa52d9a..f9834562ec 100644
--- a/web/src/components/table/use-cases/observations.tsx
+++ b/web/src/components/table/use-cases/observations.tsx
@@ -91,7 +91,6 @@ import {
} from "@/src/features/navigate-detail-pages/context";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
import { useTableViewFilterChange } from "@/src/components/table/table-view-presets/hooks/useTableViewFilterChange";
-import { SearchScopeSelect } from "@/src/components/table/SearchScopeSelect";
import { TableSearchBar, toObservedOptions } from "@/src/features/search-bar";
import { observationsFieldRegistry } from "@/src/features/filters/config/tracingSearchRegistry";
import { useRouter } from "next/router";
@@ -565,7 +564,10 @@ export default function ObservationsTable({
facetOptions,
queryFilterOptions,
);
- const searchRegistry = observationsFieldRegistry(observationsFilterConfig);
+ const searchRegistry = observationsFieldRegistry(
+ observationsFilterConfig,
+ legacyTracingIoSearchEnabled,
+ );
const observedOptions = toObservedOptions(
facetOptions,
isSidebarFilterLoading,
@@ -1348,22 +1350,8 @@ export default function ObservationsTable({
query: searchQuery,
type: searchType,
setQuery: handleSearchQueryChange,
+ setType: handleSearchTypeChange,
}}
- searchScope={
- legacyTracingIoSearchEnabled ? (
- <SearchScopeSelect
- searchType={searchType}
- setSearchType={handleSearchTypeChange}
- metadataLabel="IDs / Names"
- fullTextLabel="Full Text"
- availableSearchTypes={{
- content: true,
- input: true,
- output: true,
- }}
- />
- ) : undefined
- }
/>
<ObservationsDataTableToolbar
rowClassName="my-1"
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index e02c680c1f..228bbfb369 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -91,7 +91,6 @@ import { TablePeekViewTraceDetail } from "@/src/components/table/peek/peek-trace
import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
import { useTableViewFilterChange } from "@/src/components/table/table-view-presets/hooks/useTableViewFilterChange";
-import { SearchScopeSelect } from "@/src/components/table/SearchScopeSelect";
import { TableSearchBar, toObservedOptions } from "@/src/features/search-bar";
import { tracesFieldRegistry } from "@/src/features/filters/config/tracingSearchRegistry";
import { useFullTextSearch } from "@/src/components/table/use-cases/useFullTextSearch";
@@ -436,7 +435,6 @@ function TracesTableInternal({
filterOptions,
queryFilterOptions,
);
- const searchRegistry = tracesFieldRegistry(tracesFilterConfig);
const observedOptions = toObservedOptions(
filterOptions,
isSidebarFilterLoading,
@@ -466,6 +464,10 @@ function TracesTableInternal({
);
const legacyTracingIoSearchEnabled =
legacyTracingSearchConfig.data?.legacyTracingIoSearchEnabled ?? true;
+ const searchRegistry = tracesFieldRegistry(
+ tracesFilterConfig,
+ legacyTracingIoSearchEnabled,
+ );
const { searchQuery, searchType, setSearchQuery, setSearchType } =
useFullTextSearch({
tableAllowsFullTextSearch: legacyTracingIoSearchEnabled,
@@ -1408,22 +1410,8 @@ function TracesTableInternal({
query: searchQuery,
type: searchType,
setQuery: handleSearchQueryChange,
+ setType: handleSearchTypeChange,
}}
- searchScope={
- legacyTracingIoSearchEnabled ? (
- <SearchScopeSelect
- searchType={searchType}
- setSearchType={handleSearchTypeChange}
- metadataLabel="IDs / Names"
- fullTextLabel="Full Text"
- availableSearchTypes={{
- content: true,
- input: true,
- output: true,
- }}
- />
- ) : undefined
- }
/>
<DataTableToolbar
rowClassName="my-1"
diff --git a/web/src/features/chart-view/lib/chartFilterCompatibility.clienttest.ts b/web/src/features/chart-view/lib/chartFilterCompatibility.clienttest.ts
index 1369842431..6948abc4a4 100644
--- a/web/src/features/chart-view/lib/chartFilterCompatibility.clienttest.ts
+++ b/web/src/features/chart-view/lib/chartFilterCompatibility.clienttest.ts
@@ -119,6 +119,13 @@ describe("chartSearchFieldReason", () => {
expect(chartSearchFieldReason("startTime")).toMatch(/this field/i);
});
+ it.each(["content", "all", "in"])(
+ "marks the %s text search as unapplied",
+ (field) => {
+ expect(chartSearchFieldReason(field)).toMatch(/search/i);
+ },
+ );
+
it("returns null for unknown fields", () => {
expect(chartSearchFieldReason("nonsense")).toBeNull();
});
diff --git a/web/src/features/chart-view/lib/chartFilterCompatibility.ts b/web/src/features/chart-view/lib/chartFilterCompatibility.ts
index 8ab731f191..4f00691180 100644
--- a/web/src/features/chart-view/lib/chartFilterCompatibility.ts
+++ b/web/src/features/chart-view/lib/chartFilterCompatibility.ts
@@ -148,6 +148,8 @@ export function chartSearchFieldReason(fieldName: string): string | null {
);
// `has:`/`-has:` presence checks lower to a null-check filter, which the chart
// doesn't apply (dropped by toChartFilters) β€” so the pill is deactivated too.
+ if (ref.type === "searchScope" || (ref.type === "pseudo" && ref.id === "in"))
+ return CHART_SEARCH_QUERY_REASON;
if (ref.type === "pseudo")
return "Charts can't filter by whether a field is set at the moment β€” still applies to the table.";
return chartFilterExclusionReason(ref.field.id);
diff --git a/web/src/features/datasets/components/DatasetItemsTable.tsx b/web/src/features/datasets/components/DatasetItemsTable.tsx
index d6b969fe71..77ad7032bd 100644
--- a/web/src/features/datasets/components/DatasetItemsTable.tsx
+++ b/web/src/features/datasets/components/DatasetItemsTable.tsx
@@ -35,6 +35,8 @@ import { BatchExportTableButton } from "@/src/components/BatchExportTableButton"
import { useQueryFilterState } from "@/src/features/filters";
import { useDebounce } from "@/src/hooks/useDebounce";
import { useFullTextSearch } from "@/src/components/table/use-cases/useFullTextSearch";
+import { TableSearchBar } from "@/src/features/search-bar";
+import { DATASET_ITEMS_FIELD_REGISTRY } from "../constants/datasetItemsSearchRegistry";
import { useDatasetVersion } from "../hooks/useDatasetVersion";
import { EditDatasetItemDialog } from "./EditDatasetItemDialog";
@@ -351,13 +353,29 @@ export function DatasetItemsTable({
);
const setFilterStateWithDebounce = useDebounce(setFilterState);
- const setSearchQueryWithDebounce = useDebounce(setSearchQuery, 300);
return (
<>
+ <TableSearchBar
+ key={`${projectId}:${datasetId}:${selectedVersion?.toISOString() ?? "latest"}`}
+ projectId={projectId}
+ tableName="dataset-items"
+ registry={DATASET_ITEMS_FIELD_REGISTRY}
+ filterState={filterState}
+ setFilterState={setFilterState}
+ observed={undefined}
+ isV4={false}
+ search={{
+ query: searchQuery,
+ type: searchType,
+ setQuery: setSearchQuery,
+ setType: setSearchType,
+ }}
+ />
<DataTableToolbar
columns={columns}
tableName="dataset-items"
+ isV4={false}
filterColumnDefinition={datasetItemFilterColumns}
filterState={filterState}
setFilterState={setFilterStateWithDebounce}
@@ -368,19 +386,6 @@ export function DatasetItemsTable({
rowHeight={rowHeight}
setRowHeight={setRowHeight}
actionButtons={[menuItems, batchExportButton].filter(Boolean)}
- searchConfig={{
- metadataSearchFields: ["ID"],
- updateQuery: setSearchQueryWithDebounce,
- currentQuery: searchQuery ?? undefined,
- tableAllowsFullTextSearch: true,
- setSearchType,
- searchType,
- customDropdownLabels: {
- metadata: "IDs",
- fullText: "Full Text",
- },
- hidePerformanceWarning: true,
- }}
/>
<DataTable
tableName="datasetItems"
diff --git a/web/src/features/datasets/constants/datasetItemsSearchRegistry.clienttest.ts b/web/src/features/datasets/constants/datasetItemsSearchRegistry.clienttest.ts
new file mode 100644
index 0000000000..b55f6e70d0
--- /dev/null
+++ b/web/src/features/datasets/constants/datasetItemsSearchRegistry.clienttest.ts
@@ -0,0 +1,139 @@
+import { describe, expect, it } from "vitest";
+import type { FilterState } from "@langfuse/shared";
+import { DATASET_ITEMS_FIELD_REGISTRY } from "./datasetItemsSearchRegistry";
+import { planCommit } from "@/src/features/search-bar/lib/commit";
+import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-state-to-query";
+import {
+ applyPick,
+ planInputCompletions,
+} from "@/src/features/search-bar/lib/completions";
+import { runSearchBarInvariants } from "@/src/features/search-bar/lib/searchBarInvariants";
+
+const registry = DATASET_ITEMS_FIELD_REGISTRY;
+const metadataFilter: FilterState = [
+ {
+ column: "metadata",
+ type: "stringObject",
+ key: "region",
+ operator: "=",
+ value: "eu",
+ },
+];
+
+describe("dataset item search contract", () => {
+ it("keeps bare phrases in the ID lane and resets to it when clearing", () => {
+ expect(planCommit("item 123", undefined, registry)).toMatchObject({
+ status: "committed",
+ filters: [],
+ searchQuery: "item 123",
+ searchType: ["id"],
+ });
+ expect(planCommit("", undefined, registry)).toMatchObject({
+ status: "committed",
+ filters: [],
+ searchQuery: null,
+ searchType: ["id"],
+ });
+ });
+
+ it.each([
+ ["content", ["content"]],
+ ["input", ["input"]],
+ ["output", ["output"]],
+ ["all", ["id", "content"]],
+ ])(
+ "round-trips the %s lane alongside metadata filters",
+ (scope, searchType) => {
+ const first = planCommit(
+ `${scope}:"refund policy" metadata.region:eu`,
+ undefined,
+ registry,
+ );
+ expect(first).toMatchObject({
+ status: "committed",
+ filters: metadataFilter,
+ searchQuery: "refund policy",
+ searchType,
+ });
+ if (first.status !== "committed") throw new Error(first.status);
+
+ const projection = filterStateToQueryText(first.filters, first, registry);
+ expect(projection.skippedFilters).toEqual([]);
+ expect(planCommit(projection.text, undefined, registry)).toMatchObject({
+ status: "committed",
+ filters: metadataFilter,
+ searchQuery: first.searchQuery,
+ searchType,
+ });
+ },
+ );
+
+ it("offers payload scope rewrites that keep the full phrase", () => {
+ const input = "refund policy";
+ const plan = planInputCompletions(
+ {
+ input,
+ caret: input.length,
+ observed: {},
+ recents: [],
+ currentQueryText: input,
+ },
+ registry,
+ );
+ const options = plan?.sections.flatMap((section) => section.options) ?? [];
+ for (const [scope, searchType] of [
+ ["content", ["content"]],
+ ["input", ["input"]],
+ ["output", ["output"]],
+ ["all", ["id", "content"]],
+ ] as const) {
+ const option = options.find((option) => option.id === `scope:${scope}`);
+ expect(option).toBeDefined();
+ if (
+ !plan ||
+ !option ||
+ option.kind === "recent" ||
+ option.kind === "preset"
+ ) {
+ throw new Error("Expected a scope completion");
+ }
+ expect(
+ planCommit(applyPick(option, input, plan).next, undefined, registry),
+ ).toMatchObject({
+ status: "committed",
+ filters: [],
+ searchQuery: input,
+ searchType,
+ });
+ }
+ });
+
+ it("preserves metadata filter and quoting invariants without exposing unsupported fields", () => {
+ const legacyProjection = filterStateToQueryText(
+ metadataFilter.map((filter) => ({ ...filter, column: "Metadata" })),
+ undefined,
+ registry,
+ );
+ expect(legacyProjection.skippedFilters).toEqual([]);
+ expect(
+ planCommit(legacyProjection.text, undefined, registry),
+ ).toMatchObject({
+ status: "committed",
+ filters: metadataFilter,
+ });
+ expect(
+ runSearchBarInvariants({
+ name: "dataset items",
+ registry,
+ extraKeys: ["metadata.region", 'metadata."review team"'],
+ scoreContexts: [],
+ fieldValues: ["x", "5", "true", '"a b"'],
+ freeTextValues: ["item 123", "or", "!important", "key:value"],
+ sidebarFilters: [metadataFilter],
+ }),
+ ).toEqual([]);
+ for (const query of ["status:ACTIVE", "scores.quality:1", "traceId:abc"]) {
+ expect(planCommit(query, undefined, registry).status).toBe("invalid");
+ }
+ });
+});
diff --git a/web/src/features/datasets/constants/datasetItemsSearchRegistry.ts b/web/src/features/datasets/constants/datasetItemsSearchRegistry.ts
new file mode 100644
index 0000000000..6bda139897
--- /dev/null
+++ b/web/src/features/datasets/constants/datasetItemsSearchRegistry.ts
@@ -0,0 +1,42 @@
+import { datasetItemFilterColumns } from "@langfuse/shared";
+import { fieldRegistryFromColumns } from "@/src/features/search-bar/lib/fields";
+
+export const DATASET_ITEMS_FIELD_REGISTRY = fieldRegistryFromColumns(
+ datasetItemFilterColumns,
+ {
+ id: "datasetItems",
+ allowFreeText: true,
+ defaultSearchType: ["id"],
+ freeTextScopeLabel: "item IDs",
+ metadata: true,
+ scores: false,
+ traceScores: false,
+ searchExamples: [
+ "item ID",
+ 'content:"refund policy"',
+ "metadata.region:eu",
+ ],
+ searchScopes: {
+ content: {
+ searchType: ["content"],
+ label: "Content",
+ description: "search input, expected output, and metadata",
+ },
+ input: {
+ searchType: ["input"],
+ label: "Input",
+ description: "search input only",
+ },
+ output: {
+ searchType: ["output"],
+ label: "Expected output",
+ description: "search expected output only",
+ },
+ all: {
+ searchType: ["id", "content"],
+ label: "All fields",
+ description: "search item IDs, input, expected output, and metadata",
+ },
+ },
+ },
+);
diff --git a/web/src/features/events/components/EventsTable.tsx b/web/src/features/events/components/EventsTable.tsx
index fe7401fbaf..ee62965e89 100644
--- a/web/src/features/events/components/EventsTable.tsx
+++ b/web/src/features/events/components/EventsTable.tsx
@@ -1,6 +1,5 @@
import { eventsSearchRegistry } from "../config/eventsSearchRegistry";
-import { useEventsTableSearch } from "../hooks/useEventsTableSearch";
-import { SearchScopeSelect } from "@/src/components/table/SearchScopeSelect";
+import { useEventsSearchBar } from "@/src/features/search-bar/hooks/useEventsSearchBar";
import { DataTable } from "@/src/components/table/data-table";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import {
@@ -56,7 +55,6 @@ import { createTextTableColumn } from "@/src/components/design-system/table/colu
import { type LangfuseColumnDef } from "@/src/components/table/types";
import {
buildAiContext,
- DEFAULT_SEARCH_TYPE,
EventsSearchBarRow,
filterStateToQueryText,
observedScoreNamesFromOptions,
@@ -783,11 +781,10 @@ export default function ObservationsEventsTable({
commit: searchBarCommit,
applyFilters: searchBarApplyFilters,
resetDraft: resetSearchBarDraft,
- } = useEventsTableSearch({
+ } = useEventsSearchBar({
projectId,
tableName: eventsFilterConfig.tableName,
enabled: searchBarMode,
- useHostSearchScopes: tableStatePolicy.useHostSearchScopes,
registry: searchRegistry,
filterState: queryFilter.searchBarFilterState,
searchQuery,
@@ -820,9 +817,7 @@ export default function ObservationsEventsTable({
projectFiltersForSearchBar(state.filters),
{
searchQuery: state.searchQuery,
- searchType: tableStatePolicy.useHostSearchScopes
- ? DEFAULT_SEARCH_TYPE
- : searchType,
+ searchType,
},
searchRegistry,
).text,
@@ -836,7 +831,6 @@ export default function ObservationsEventsTable({
searchBarStore,
projectFiltersForSearchBar,
searchRegistry,
- tableStatePolicy.useHostSearchScopes,
searchType,
],
);
@@ -1798,15 +1792,6 @@ export default function ObservationsEventsTable({
new Set(
(queryFilter.explicitFilterState ?? []).map((filter) => filter.column),
).size + (searchQuery && searchQuery.trim().length > 0 ? 1 : 0);
- const searchScope = tableStatePolicy.useHostSearchScopes ? (
- <SearchScopeSelect
- searchType={searchType}
- setSearchType={handleSearchTypeChange}
- metadataLabel="IDs / Names"
- fullTextLabel="Full Text"
- availableSearchTypes={{ content: true, input: true, output: true }}
- />
- ) : null;
return (
<DataTableControlsProvider tableName={eventsFilterConfig.tableName}>
@@ -1865,9 +1850,6 @@ export default function ObservationsEventsTable({
// padding, so the bar lines up with time range / presets.
className="p-0"
/>
- {searchScope && (
- <div className="flex justify-end">{searchScope}</div>
- )}
</div>
) : (
// Externally controlled filters retain the host's search input.
@@ -1999,7 +1981,6 @@ export default function ObservationsEventsTable({
aiScoreNames={aiScoreNames}
/>
</div>
- {searchScope}
</div>
)}
{/* Toolbar spanning full width */}
diff --git a/web/src/features/events/config/eventsSearchRegistry.ts b/web/src/features/events/config/eventsSearchRegistry.ts
index 2fd379d136..8a4da76464 100644
--- a/web/src/features/events/config/eventsSearchRegistry.ts
+++ b/web/src/features/events/config/eventsSearchRegistry.ts
@@ -31,8 +31,11 @@ export function eventsSearchRegistry(
"trace_score_categories",
"trace_score_booleans",
].some((column) => omitted.has(column)),
+ defaultSearchType: useHostSearchScopes
+ ? ["id"]
+ : EVENTS_FIELD_REGISTRY.defaultSearchType,
freeTextScopeLabel: useHostSearchScopes
- ? "the selected search scope"
+ ? "IDs, user IDs and names"
: EVENTS_FIELD_REGISTRY.freeTextScopeLabel,
// A scoped registry cannot use the full events AI vocabulary.
aiFilterPrompt: omittedColumns.length === 0,
diff --git a/web/src/features/events/hooks/useEventsTableSearch.clienttest.tsx b/web/src/features/events/hooks/useEventsTableSearch.clienttest.tsx
index d839baebac..7c8bc174aa 100644
--- a/web/src/features/events/hooks/useEventsTableSearch.clienttest.tsx
+++ b/web/src/features/events/hooks/useEventsTableSearch.clienttest.tsx
@@ -2,7 +2,7 @@ import { act, renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import type { TracingSearchType } from "@langfuse/shared";
import { eventsSearchRegistry } from "../config/eventsSearchRegistry";
-import { useEventsTableSearch } from "./useEventsTableSearch";
+import { useEventsSearchBar } from "@/src/features/search-bar/hooks/useEventsSearchBar";
describe("embedded events search scopes", () => {
it.each<TracingSearchType[]>([
@@ -11,18 +11,17 @@ describe("embedded events search scopes", () => {
["id", "output"],
["content"],
])(
- "keeps the host scope %j when a phrase or another facet is edited",
+ "keeps the restored scope %j visible and intact when another facet is edited",
(...scope) => {
const setSearchType = vi.fn();
const setSearchQuery = vi.fn();
const setFilterState = vi.fn();
const { result } = renderHook(() =>
- useEventsTableSearch({
+ useEventsSearchBar({
projectId: "p",
tableName: "observations-events",
enabled: true,
- useHostSearchScopes: true,
- registry: eventsSearchRegistry(["sessionId"]),
+ registry: eventsSearchRegistry(["sessionId"], true),
filterState: [],
searchQuery: "refund",
searchType: scope,
@@ -32,9 +31,12 @@ describe("embedded events search scopes", () => {
setSearchType,
}),
);
- expect(result.current.store.getState().draft).toBe("refund ");
+ const restored = result.current.store.getState().draft.trim();
+ expect(restored).toContain("refund");
act(() =>
- result.current.store.getState().actions.setDraft("refund level:ERROR"),
+ result.current.store
+ .getState()
+ .actions.setDraft(`${restored} level:ERROR`),
);
act(() => result.current.commit("enter"));
expect(setSearchType).not.toHaveBeenCalled();
@@ -50,14 +52,36 @@ describe("embedded events search scopes", () => {
},
);
+ it("changes an embedded payload scope back to its IDs and names default", () => {
+ const setSearchType = vi.fn();
+ const setSearchQuery = vi.fn();
+ const { result } = renderHook(() =>
+ useEventsSearchBar({
+ tableName: "observations-events",
+ enabled: true,
+ registry: eventsSearchRegistry(["userId"], true),
+ filterState: [],
+ searchQuery: "refund",
+ searchType: ["content"],
+ observed: undefined,
+ setFilterState: vi.fn(),
+ setSearchQuery,
+ setSearchType,
+ }),
+ );
+ act(() => result.current.store.getState().actions.setDraft("refund"));
+ act(() => result.current.commit("enter"));
+ expect(setSearchType).toHaveBeenCalledWith(["id"]);
+ expect(setSearchQuery).toHaveBeenCalledWith("refund");
+ });
+
it("keeps the full-page grammar's original full-text default", () => {
const setSearchType = vi.fn();
const { result } = renderHook(() =>
- useEventsTableSearch({
+ useEventsSearchBar({
projectId: "p",
tableName: "observations-events",
enabled: true,
- useHostSearchScopes: false,
registry: eventsSearchRegistry([]),
filterState: [],
searchQuery: null,
diff --git a/web/src/features/events/hooks/useEventsTableSearch.ts b/web/src/features/events/hooks/useEventsTableSearch.ts
deleted file mode 100644
index e79dc53770..0000000000
--- a/web/src/features/events/hooks/useEventsTableSearch.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import type { FilterState, TracingSearchType } from "@langfuse/shared";
-import { useEventsSearchBar } from "@/src/features/search-bar/hooks/useEventsSearchBar";
-import { DEFAULT_SEARCH_TYPE } from "@/src/features/search-bar/lib/commit";
-
-const preserveHostSearchScope = () => {};
-
-export function useEventsTableSearch({
- useHostSearchScopes,
- ...options
-}: Parameters<typeof useEventsSearchBar>[0] & {
- useHostSearchScopes: boolean;
-}) {
- const searchBar = useEventsSearchBar({
- ...options,
- searchType: useHostSearchScopes ? DEFAULT_SEARCH_TYPE : options.searchType,
- analyticsSearchType: useHostSearchScopes
- ? options.searchType
- : options.analyticsSearchType,
- setSearchType: useHostSearchScopes
- ? preserveHostSearchScope
- : options.setSearchType,
- });
-
- const resetDraft = (state: {
- filters: FilterState;
- searchQuery: string | null;
- searchType: TracingSearchType[];
- }) => {
- searchBar.resetDraft({
- ...state,
- searchType: useHostSearchScopes ? DEFAULT_SEARCH_TYPE : state.searchType,
- });
- };
-
- return { ...searchBar, resetDraft };
-}
diff --git a/web/src/features/events/presetDemotionOnUserEdit.clienttest.tsx b/web/src/features/events/presetDemotionOnUserEdit.clienttest.tsx
index 4f2b192df4..5920c86722 100644
--- a/web/src/features/events/presetDemotionOnUserEdit.clienttest.tsx
+++ b/web/src/features/events/presetDemotionOnUserEdit.clienttest.tsx
@@ -13,7 +13,7 @@ import {
} from "@langfuse/shared";
import { useCallback, useRef } from "react";
import { useStore } from "zustand";
-import { useEventsTableSearch } from "./hooks/useEventsTableSearch";
+import { useEventsSearchBar } from "@/src/features/search-bar/hooks/useEventsSearchBar";
import {
type FilterConfig,
useSidebarFilterState,
@@ -235,11 +235,10 @@ function Harness({ projectId = PROJECT_ID }: { projectId?: string }) {
queryFilterRef.current.setFilterState(filters, { origin: "saved_view" }),
[],
);
- const searchBar = useEventsTableSearch({
+ const searchBar = useEventsSearchBar({
projectId,
tableName: "observations-events",
enabled: true,
- useHostSearchScopes: false,
filterState: queryFilter.searchBarFilterState,
searchQuery: null,
searchType: ["id", "content"],
diff --git a/web/src/features/filters/config/tracingSearchRegistry.clienttest.ts b/web/src/features/filters/config/tracingSearchRegistry.clienttest.ts
index a919741d99..d6d3cc8e8c 100644
--- a/web/src/features/filters/config/tracingSearchRegistry.clienttest.ts
+++ b/web/src/features/filters/config/tracingSearchRegistry.clienttest.ts
@@ -28,12 +28,7 @@ for (const registry of registries) {
});
});
- it.each([
- "input:secret",
- "output:secret",
- "traceScores.quality:>0.8",
- "bookmarked:true",
- ])(
+ it.each(["traceScores.quality:>0.8", "bookmarked:true"])(
"rejects unsupported filters without changing the query for %s",
(query) => {
expect(validateQuery(query, undefined, registry).valid).toBe(false);
@@ -41,6 +36,20 @@ for (const registry of registries) {
},
);
+ it.each(["content", "input", "output"] as const)(
+ "searches %s through the existing backend scope",
+ (scope) => {
+ expect(
+ planCommit(`${scope}:refund`, undefined, registry),
+ ).toMatchObject({
+ status: "committed",
+ searchQuery: "refund",
+ searchType: [scope],
+ filters: [],
+ });
+ },
+ );
+
it("round-trips supported names, tags, metadata, numeric ranges and score types", () => {
const nameColumn = registry.id === "traces" ? "traceName" : "name";
const tagsColumn = registry.id === "traces" ? "traceTags" : "tags";
@@ -178,3 +187,24 @@ describe("embedded tracing scope", () => {
);
});
});
+
+describe("disabled legacy payload search", () => {
+ it.each([
+ tracesFieldRegistry(getTraceFilterConfig(), false),
+ observationsFieldRegistry(getObservationsFilterConfig(), false),
+ ])("offers only supported search lanes for $id", (registry) => {
+ expect(planCommit("refund", undefined, registry)).toMatchObject({
+ status: "committed",
+ searchQuery: "refund",
+ searchType: ["id"],
+ });
+ for (const scope of ["content", "input", "output", "all"]) {
+ expect(planCommit(`${scope}:refund`, undefined, registry).status).toBe(
+ "invalid",
+ );
+ }
+ expect(planCommit("in:content refund", undefined, registry).status).toBe(
+ "invalid",
+ );
+ });
+});
diff --git a/web/src/features/filters/config/tracingSearchRegistry.ts b/web/src/features/filters/config/tracingSearchRegistry.ts
index 04f50e3fbb..1150dfae48 100644
--- a/web/src/features/filters/config/tracingSearchRegistry.ts
+++ b/web/src/features/filters/config/tracingSearchRegistry.ts
@@ -1,6 +1,7 @@
import type { FilterConfig } from "@/src/features/filters/lib/filter-config";
import {
fieldRegistryFromColumns,
+ EVENTS_FIELD_REGISTRY,
type FieldOverlay,
type FieldRegistry,
} from "@/src/features/search-bar/lib/fields";
@@ -8,6 +9,7 @@ import {
function tracingFieldRegistry(
config: FilterConfig,
id: "traces" | "observations",
+ allowsFullTextSearch: boolean,
): FieldRegistry {
const exposed = new Set(config.facets.map((facet) => facet.column));
const fields: Record<string, FieldOverlay> = {
@@ -40,7 +42,23 @@ function tracingFieldRegistry(
scores: exposed.has("scores_avg"),
traceScores: false,
allowFreeText: true,
- freeTextScopeLabel: "the selected search scope",
+ defaultSearchType: ["id"],
+ freeTextScopeLabel: "IDs, user IDs and names",
+ searchScopes: allowsFullTextSearch
+ ? {
+ ...EVENTS_FIELD_REGISTRY.searchScopes,
+ input: {
+ searchType: ["input"],
+ label: "Input",
+ description: "search only the input payload",
+ },
+ output: {
+ searchType: ["output"],
+ label: "Output",
+ description: "search only the output payload",
+ },
+ }
+ : {},
recentSearches: true,
searchExamples:
id === "traces"
@@ -50,10 +68,16 @@ function tracingFieldRegistry(
);
}
-export function tracesFieldRegistry(config: FilterConfig): FieldRegistry {
- return tracingFieldRegistry(config, "traces");
+export function tracesFieldRegistry(
+ config: FilterConfig,
+ allowsFullTextSearch = true,
+): FieldRegistry {
+ return tracingFieldRegistry(config, "traces", allowsFullTextSearch);
}
-export function observationsFieldRegistry(config: FilterConfig): FieldRegistry {
- return tracingFieldRegistry(config, "observations");
+export function observationsFieldRegistry(
+ config: FilterConfig,
+ allowsFullTextSearch = true,
+): FieldRegistry {
+ return tracingFieldRegistry(config, "observations", allowsFullTextSearch);
}
diff --git a/web/src/features/prompts/components/prompts-table.tsx b/web/src/features/prompts/components/prompts-table.tsx
index 096a3a7e57..d66ef92e8f 100644
--- a/web/src/features/prompts/components/prompts-table.tsx
+++ b/web/src/features/prompts/components/prompts-table.tsx
@@ -44,7 +44,6 @@ import {
import { useTableViewManager } from "@/src/components/table/table-view-presets/hooks/useTableViewManager";
import { useTableViewFilterChange } from "@/src/components/table/table-view-presets/hooks/useTableViewFilterChange";
import { TableSearchBar } from "@/src/features/search-bar/components/TableSearchBar";
-import { SearchScopeSelect } from "@/src/components/table/SearchScopeSelect";
import { toObservedOptions } from "@/src/features/search-bar/lib/observed-options";
import { PROMPTS_FIELD_REGISTRY } from "@/src/features/prompts/constants/promptsSearchRegistry";
@@ -508,20 +507,8 @@ export function PromptTable() {
query: searchQuery,
type: searchType,
setQuery: handleSearchQueryChange,
+ setType: handleSearchTypeChange,
}}
- searchScope={
- <SearchScopeSelect
- searchType={searchType}
- setSearchType={handleSearchTypeChange}
- metadataLabel="Names, Tags"
- fullTextLabel="Full Text"
- availableSearchTypes={{
- content: true,
- input: false,
- output: false,
- }}
- />
- }
/>
<DataTableToolbar
tableName="prompts"
diff --git a/web/src/features/prompts/constants/promptsSearchRegistry.ts b/web/src/features/prompts/constants/promptsSearchRegistry.ts
index bafd65159c..bf7d4abce4 100644
--- a/web/src/features/prompts/constants/promptsSearchRegistry.ts
+++ b/web/src/features/prompts/constants/promptsSearchRegistry.ts
@@ -12,7 +12,20 @@ export const PROMPTS_FIELD_REGISTRY = fieldRegistryFromColumns(
{
id: "prompts",
allowFreeText: true,
- freeTextScopeLabel: "prompt names, tags and content",
+ defaultSearchType: ["id"],
+ freeTextScopeLabel: "prompt names and tags",
+ searchScopes: {
+ content: {
+ searchType: ["content"],
+ label: "Prompt content",
+ description: "search only the prompt content",
+ },
+ all: {
+ searchType: ["id", "content"],
+ label: "Names, tags and content",
+ description: "search prompt names, tags and content",
+ },
+ },
recentSearches: true,
searchExamples: ["type:chat", "labels:production", "version:>1"],
fields: {
diff --git a/web/src/features/search-bar/README.md b/web/src/features/search-bar/README.md
index a587374189..39b9c264fc 100644
--- a/web/src/features/search-bar/README.md
+++ b/web/src/features/search-bar/README.md
@@ -44,51 +44,52 @@ state remain canonical; both editors update the same state.
to the real key when lowering; the reverse adapter and completions re-quote
them β€” so they round-trip)
- `has:endTime` / `-has:endTime` null checks
-- full-text search (see below): bare text, or `input:`/`output:`/`name:`/`id:`
+- text search (see below): bare text, declared `content:`/`all:` scopes, and
+ supported `input:`/`output:`/`name:`/`id:` fields
Cross-field OR, negated groups, and other shapes the flat contract cannot
represent are commit-blocking diagnostics, not silent drops. There is no
FTS `*` operator: the events tRPC filter contract has none.
-**Full-text search.** It matches as a **contiguous substring** server-side
-(`clickhouse-sql/search.ts`, `ILIKE %query%`) and is expressed field-style:
-
-- **bare text** (`refund policy`) β†’ `searchQuery`, default scope:
- `searchType=['id','content']` β€” i.e. `id` + `user_id` + `name` (the `id`
- lane) **and** `input` + `output` (the `content` lane). Typing plain text
- searches all of them. The adapter emits a `null` searchType (no scope token);
- `commit.ts`'s `DEFAULT_SEARCH_TYPE` supplies `['id','content']`.
-- **`input:"refund"` / `output:"refund"`** β†’ real `string` "contains" **column
- filters** on `e.input`/`e.output` (not `searchType`). Use them to narrow the
- search to one payload channel. They round-trip as `FilterState` like any
- other column filter, and support operators (`:=`, `*`/glob, `-` negation).
-- **`name:"checkout"` / `id:"abc"`** β†’ `string` "contains" column filters on
- `name`/`id`. Use them to narrow to that column. They are `textSearch` fields
- (bare = contains, `:=` = exact) but keep their observed-value autocomplete.
-
-Typing bare text offers the scope rewrites (`input:`/`output:`) with hover
-explanations. Scope is global per query (`searchType` is one value), so
-multi-word free text is a **phrase**, not token-AND β€” `test media` matches
-"Test Media" but not "Media β€” Test run" (open Decision A below).
-
-Historical note: the old `in:<scope>` token and the `content:` pseudo-field are
-both **gone**. `content:` searched input + output combined; that is now simply
-the default (a bare query already searches both), so the token was removed (the
-one capability it uniquely had β€” "payloads but NOT ids/names" β€” is dropped,
-pending feedback). The reverse adapter canonicalizes a legacy
-`searchType=input|output` to the `input:`/`output:` **column filter** on the
-next commit (the chosen normalization), and treats any `id`/`content` searchType
-as the default β€” rendered as bare text, no token.
-
-**Known limitation (multi-scope legacy state).** The bar's scope is a single
-value per query; the legacy toolbar's `searchType` was a _set_. `['id','content']`
-now round-trips losslessly β€” it **is** the default, rendered as bare text. The
-two remaining multi-scope states still drop their id channel on the next commit:
-`['id','input']` / `['id','output']` canonicalize to `input:"…"` / `output:"…"`
-**column filters** (per the historical note above) and drop the id-scope
-`searchType`/`searchQuery`. There's no lossless single-token projection of those
-two without a real per-column "all fields" scope β€” deferred past beta. Trigger is
-narrow (a legacy URL from the old dropdown + the bar enabled + a commit).
+**Full-text search.** Each registry declares `defaultSearchType` and
+`searchScopes`. The adapter writes the existing `searchQuery` / `searchType`
+contract; it does not introduce backend filter columns or change matching rules.
+
+- **Bare text** (`refund policy`) is one phrase in the registry's default
+ scope. Full Events uses `['id', 'content']`; metadata-first hosts use `['id']`.
+- **`content:"refund policy"`** searches only the declared content lane.
+ For Events this is input/output; for Prompts it is the prompt body; for
+ Dataset Items it includes input, expected output, and metadata.
+- **`all:"refund policy"`** uses `['id', 'content']`, including the host's
+ IDs/names lane. This preserves the additive Full Text dropdown choice.
+- **`input:` / `output:`** remain real string column filters on V4 Events,
+ supporting comparisons such as exact/glob matches and negation. On legacy
+ tracing and Dataset Items, registries instead declare them as search scopes
+ backed by the existing `searchType` lane. Prompts does not support them.
+- **`name:` / `id:`** remain ordinary column filters where the registry exposes
+ them; they do not select the metadata search lane.
+
+Scope tokens accept one positive phrase with the plain `:` operator. Multiple
+scope phrases, a scope phrase mixed with bare text, negation, comparison/glob
+operators, and grouped scope phrases are rejected: one backend search string
+cannot express those independent predicates. Ordinary facet filters can still
+combine with a scoped search, for example `content:"refund policy" env:prod`.
+The same constraint is checked in validation and lowering. V4 Events column
+filters remain independent, so `input:refund output:policy` continues to work.
+
+The reverse adapter emits bare text only for the exact default scope, then
+prefers a declared scope token. Unnamed legacy combinations use compatibility
+syntax such as `in:(id OR input) "refund policy"`. This preserves every channel
+without converting the search into a different column filter. `in:` accepts
+only search types supported by that host, applies to the global bare phrase,
+and is never offered in normal autocomplete. It cannot combine with a second
+`in:` or another scope token.
+
+Autocomplete offers only the registry's search scopes and supported V4 payload
+column rewrites, with host-specific descriptions. SQL search remains one
+`ILIKE %query%` phrase across an OR union of selected columns; V4's existing
+fast IO search also applies its token prefilter. Search operators are not
+silently translated between these backend search lanes and column filters.
Operator-looking tokens that aren't supported yet are **reserved** β€” they emit
an explicit "not supported yet" diagnostic instead of silently becoming free
@@ -408,6 +409,14 @@ the v4 sessions table passes `SESSIONS_FIELD_REGISTRY`
row. A specialized host that uses `useEventsSearchBar` and `EventsSearchBarRow`
directly must pass the same registry to both, so autocomplete and commits agree.
+Registries with a backend search lane also declare `defaultSearchType` and
+`searchScopes: Record<string, { searchType, label, description }>`. Scope
+entries describe existing backend search types, not `FilterState` columns;
+unsupported host lanes must not be declared. Preserve both declarations when
+projecting or extending a registry. Hosts pass their actual query and scope
+setters so a commit can change the scope and the phrase together. Views with
+`allowFreeText: false` keep their existing `defaultTextField` behavior.
+
**Recipe to add the bar to a view:**
1. **Derive the field registry from the view's FACETS, not its raw columns.** Use
diff --git a/web/src/features/search-bar/components/SearchComposer.tsx b/web/src/features/search-bar/components/SearchComposer.tsx
index 156ae6c2e3..ee0da1a6a5 100644
--- a/web/src/features/search-bar/components/SearchComposer.tsx
+++ b/web/src/features/search-bar/components/SearchComposer.tsx
@@ -1241,7 +1241,9 @@ export function SearchComposer({
: null;
const explainTargetId = explainTarget?.id ?? null;
const explanation =
- explainTarget === null ? null : explainSegment(explainTarget, registry);
+ explainTarget === null
+ ? null
+ : explainSegment(explainTarget, registry, draft);
const explainDeactivatedReason =
explainTarget === null
? null
@@ -1250,7 +1252,9 @@ export function SearchComposer({
// description regardless of the popover β€” including the "not applied" note,
// which the visible tooltip also carries.
const caretExplanation =
- caretSegment === null ? null : explainSegment(caretSegment, registry);
+ caretSegment === null
+ ? null
+ : explainSegment(caretSegment, registry, draft);
const caretDeactivatedReason =
caretSegment === null
? null
diff --git a/web/src/features/search-bar/components/TableSearchBar.tsx b/web/src/features/search-bar/components/TableSearchBar.tsx
index 8706607def..5eb2116a59 100644
--- a/web/src/features/search-bar/components/TableSearchBar.tsx
+++ b/web/src/features/search-bar/components/TableSearchBar.tsx
@@ -1,4 +1,3 @@
-import type { ReactNode } from "react";
import type { FilterState, TracingSearchType } from "@langfuse/shared";
import { EventsSearchBarRow } from "./EventsSearchBarRow";
import { useEventsSearchBar } from "../hooks/useEventsSearchBar";
@@ -17,7 +16,6 @@ export function TableSearchBar({
observed,
isV4,
search,
- searchScope,
onRequestColumns,
erroredColumns,
}: {
@@ -32,13 +30,12 @@ export function TableSearchBar({
query: string | null;
type?: TracingSearchType[];
setQuery: (query: string | null) => void;
+ setType?: (type: TracingSearchType[]) => void;
};
- searchScope?: ReactNode;
onRequestColumns?: (columns: readonly string[]) => void;
erroredColumns?: ReadonlySet<string>;
}) {
- // The host owns search scopes. Bare text edits its existing search lane
- // without translating a persisted scope into a different column filter.
+ // The host owns the applied query and scope; the bar edits both together.
const { store, commit, applyFilters } = useEventsSearchBar({
projectId,
tableName,
@@ -50,9 +47,9 @@ export function TableSearchBar({
observed,
searchQuery: search?.query ?? null,
setSearchQuery: search?.setQuery ?? noSearchLane,
- searchType: DEFAULT_SEARCH_TYPE,
- analyticsSearchType: search?.type ?? [],
- setSearchType: noSearchLane,
+ searchType: search?.type ?? DEFAULT_SEARCH_TYPE,
+ analyticsSearchType: search?.setType ? undefined : (search?.type ?? []),
+ setSearchType: search?.setType ?? noSearchLane,
});
return (
@@ -71,7 +68,6 @@ export function TableSearchBar({
erroredColumns={erroredColumns}
/>
</div>
- {searchScope}
</div>
);
}
diff --git a/web/src/features/search-bar/hooks/useEventsSearchBar.clienttest.tsx b/web/src/features/search-bar/hooks/useEventsSearchBar.clienttest.tsx
index db21b79c37..04114d287e 100644
--- a/web/src/features/search-bar/hooks/useEventsSearchBar.clienttest.tsx
+++ b/web/src/features/search-bar/hooks/useEventsSearchBar.clienttest.tsx
@@ -176,6 +176,28 @@ describe("useEventsSearchBar.commit", () => {
);
},
);
+ it("records payload scope intent once without sending the phrase", () => {
+ const { result } = setup({ searchQuery: null });
+ act(() =>
+ result.current.store
+ .getState()
+ .actions.setDraft('input:"private payload phrase"'),
+ );
+ act(() => result.current.commit("enter"));
+ act(() => result.current.commit("blur"));
+ expect(capture).toHaveBeenCalledTimes(1);
+ expect(capture).toHaveBeenCalledWith(
+ "filters:search_submitted",
+ expect.objectContaining({
+ searchScopes: ["input"],
+ hasFreeText: false,
+ }),
+ );
+ expect(JSON.stringify(capture.mock.calls)).not.toContain(
+ "private payload phrase",
+ );
+ });
+
it("commits outside a project without writing project recent searches", () => {
const recordRecentSearch = vi
.spyOn(recentSearches, "recordRecentSearch")
diff --git a/web/src/features/search-bar/hooks/useEventsSearchBar.ts b/web/src/features/search-bar/hooks/useEventsSearchBar.ts
index 5489192e0f..d0755c52f7 100644
--- a/web/src/features/search-bar/hooks/useEventsSearchBar.ts
+++ b/web/src/features/search-bar/hooks/useEventsSearchBar.ts
@@ -18,7 +18,6 @@ import type { FilterState, TracingSearchType } from "@langfuse/shared";
import {
classifySearchError,
- DEFAULT_SEARCH_TYPE,
planCommit,
} from "@/src/features/search-bar/lib/commit";
import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-state-to-query";
@@ -298,15 +297,15 @@ export function useEventsSearchBar({
beginCommit({
filters: committedFilters,
query: null,
- scopes: DEFAULT_SEARCH_TYPE,
+ scopes: [...registry.defaultSearchType],
});
setFilterState(committedFilters);
setSearchQuery(null);
- if (!sameScopes(DEFAULT_SEARCH_TYPE, searchTypeRef.current)) {
- setSearchType(DEFAULT_SEARCH_TYPE);
+ if (!sameScopes([...registry.defaultSearchType], searchTypeRef.current)) {
+ setSearchType([...registry.defaultSearchType]);
}
},
- [beginCommit, mergeWithSkipped],
+ [beginCommit, mergeWithSkipped, registry],
);
// The committed text at the last render β€” the dedup baseline so a blur that
@@ -374,11 +373,7 @@ export function useEventsSearchBar({
});
setFilterState(committedFilters);
setSearchQuery(result.searchQuery);
- // Only write searchType when it actually changed. planCommit coerces a
- // draft with no scope token to the default (`["id","content"]` β€” ids+names
- // +input+output); the bar's default deliberately differs from the legacy
- // toolbar's `["id"]`, so it IS written to the URL (that's how the content
- // lane persists). The guard just avoids a redundant rewrite when unchanged.
+ // Commit the scope alongside the query, without redundant URL writes.
if (!sameScopes(result.searchType, searchTypeRef.current)) {
setSearchType(result.searchType);
}
@@ -393,6 +388,18 @@ export function useEventsSearchBar({
filterCount: committedFilters.length,
hasFreeText: (result.searchQuery ?? "").trim().length > 0,
searchType: analyticsSearchType ?? result.searchType,
+ searchScopes: Array.from(
+ new Set([
+ ...((result.searchQuery ?? "").trim()
+ ? (analyticsSearchType ?? result.searchType)
+ : []),
+ ...result.filters.flatMap((filter) =>
+ filter.column === "input" || filter.column === "output"
+ ? [filter.column]
+ : [],
+ ),
+ ]),
+ ),
queryLength: committed.trim().length,
trigger,
isV4,
diff --git a/web/src/features/search-bar/index.ts b/web/src/features/search-bar/index.ts
index 5c8d7f65d9..15178e81b5 100644
--- a/web/src/features/search-bar/index.ts
+++ b/web/src/features/search-bar/index.ts
@@ -15,10 +15,7 @@ export { useEventsSearchBar } from "@/src/features/search-bar/hooks/useEventsSea
export { useSearchBarEnabled } from "@/src/features/search-bar/hooks/useSearchBarEnabled";
export { astToFilterState } from "@/src/features/search-bar/lib/adapter";
export { buildAiContext } from "@/src/features/search-bar/lib/ai-context";
-export {
- DEFAULT_SEARCH_TYPE,
- planCommit,
-} from "@/src/features/search-bar/lib/commit";
+export { planCommit } from "@/src/features/search-bar/lib/commit";
export type { QueryPresetSection } from "@/src/features/search-bar/lib/completions";
export {
EVENTS_FIELD_REGISTRY,
diff --git a/web/src/features/search-bar/lib/adapter.clienttest.ts b/web/src/features/search-bar/lib/adapter.clienttest.ts
index 8107f13d07..3b01b694c8 100644
--- a/web/src/features/search-bar/lib/adapter.clienttest.ts
+++ b/web/src/features/search-bar/lib/adapter.clienttest.ts
@@ -3,6 +3,170 @@ import { filterStateToQueryText } from "@/src/features/search-bar/lib/filter-sta
import { parse } from "@/src/features/search-bar/lib/langQ";
import { validateQuery } from "@/src/features/search-bar/lib/validate";
import type { FilterState } from "@langfuse/shared";
+import { createFieldRegistry, EVENTS_FIELD_REGISTRY } from "./fields";
+import { planCommit } from "./commit";
+import {
+ USERS_FIELD_REGISTRY,
+ LEGACY_USERS_FIELD_REGISTRY,
+} from "@/src/features/filters/config/usersSearchRegistry";
+
+const scopedRegistry = createFieldRegistry({
+ ...EVENTS_FIELD_REGISTRY,
+ defaultSearchType: ["id"],
+ fields: EVENTS_FIELD_REGISTRY.fields.filter(
+ (field) => field.id !== "input" && field.id !== "output",
+ ),
+ searchScopes: {
+ content: {
+ searchType: ["content"],
+ label: "Content",
+ description: "Input and output",
+ },
+ all: {
+ searchType: ["id", "content"],
+ label: "All fields",
+ description: "IDs, names, input and output",
+ },
+ input: {
+ searchType: ["input"],
+ label: "Input",
+ description: "Input payload",
+ },
+ output: {
+ searchType: ["output"],
+ label: "Output",
+ description: "Output payload",
+ },
+ },
+});
+
+describe("declared search scopes", () => {
+ it("does not interpret inherited object properties as search scopes", () => {
+ for (const name of ["constructor", "toString", "__proto__"]) {
+ expect(scopedRegistry.resolveField(name)).toBeNull();
+ }
+ });
+ it.each([USERS_FIELD_REGISTRY, LEGACY_USERS_FIELD_REGISTRY])(
+ "does not expose scopes on fixed-lane Users registries",
+ (registry) => {
+ expect(registry.resolveField("in")).toBeNull();
+ expect(planCommit("in:content refund", undefined, registry).status).toBe(
+ "invalid",
+ );
+ },
+ );
+ it.each([
+ ["refund policy", "refund policy", ["id"]],
+ ['content:"refund policy" env:prod', "refund policy", ["content"]],
+ ["all:refund", "refund", ["id", "content"]],
+ ["input:refund", "refund", ["input"]],
+ ['in:(id OR input) "refund policy"', "refund policy", ["id", "input"]],
+ ['IN:(id OR input) "refund policy"', "refund policy", ["id", "input"]],
+ ])("lowers %s to one backend search lane", (text, query, type) => {
+ expect(planCommit(text as string, undefined, scopedRegistry)).toMatchObject(
+ {
+ status: "committed",
+ searchQuery: query,
+ searchType: type,
+ },
+ );
+ });
+
+ it.each([
+ "content:refund output:policy",
+ "content:refund refund",
+ "content:(refund OR policy)",
+ "-content:refund",
+ "content:=refund",
+ "content:refund*",
+ "in:(id AND input) refund",
+ "in:unsupported refund",
+ "in:input content:refund",
+ "in:input in:output refund",
+ ])("rejects unsupported scope composition: %s", (text) => {
+ const parsed = parse(text, scopedRegistry);
+ const lowered = astToFilterState(parsed.ast, undefined, scopedRegistry);
+ expect(lowered.errors.length).toBeGreaterThan(0);
+ expect(validateQuery(text, undefined, scopedRegistry).valid).toBe(false);
+ expect(planCommit(text, undefined, scopedRegistry).status).toBe("invalid");
+ });
+
+ it("reports only the phrase conflict when a scoped phrase has a compatibility scope", () => {
+ const { ast } = parse("content:refund in:id", scopedRegistry);
+ expect(astToFilterState(ast, undefined, scopedRegistry).errors).toEqual([
+ "Only one search phrase is supported β€” use either bare text or one scoped search",
+ ]);
+ const { ast: missingPhrase } = parse("in:id", scopedRegistry);
+ expect(
+ astToFilterState(missingPhrase, undefined, scopedRegistry).errors,
+ ).toEqual(["Add search text after in:"]);
+ });
+
+ it.each([
+ ["id"],
+ ["content"],
+ ["input"],
+ ["output"],
+ ["id", "content"],
+ ["id", "input"],
+ ["id", "output"],
+ ["input", "output"],
+ ] as const)("round-trips the existing search scope %j", (...searchType) => {
+ const text = filterStateToQueryText(
+ [],
+ {
+ searchQuery: "refund policy",
+ searchType: [...searchType],
+ },
+ scopedRegistry,
+ ).text;
+ expect(planCommit(text, undefined, scopedRegistry)).toMatchObject({
+ status: "committed",
+ searchQuery: "refund policy",
+ searchType,
+ });
+ });
+
+ it("keeps Events input/output as independent column filters", () => {
+ expect(planCommit("input:refund output:policy")).toMatchObject({
+ status: "committed",
+ searchQuery: null,
+ filters: [
+ { column: "input", operator: "contains", value: "refund" },
+ { column: "output", operator: "contains", value: "policy" },
+ ],
+ });
+ });
+
+ it.each(['content:""', 'content:" "'])(
+ "rejects an empty scoped phrase: %s",
+ (text) => {
+ expect(validateQuery(text, undefined, scopedRegistry).valid).toBe(false);
+ expect(planCommit(text, undefined, scopedRegistry).status).toBe(
+ "invalid",
+ );
+ },
+ );
+
+ it("preserves spaces inside an explicit scoped phrase on projection", () => {
+ const committed = planCommit(
+ 'content:" refund policy "',
+ undefined,
+ scopedRegistry,
+ );
+ expect(committed.status).toBe("committed");
+ if (committed.status !== "committed") return;
+ const projected = filterStateToQueryText(
+ [],
+ committed,
+ scopedRegistry,
+ ).text;
+ expect(planCommit(projected, undefined, scopedRegistry)).toMatchObject({
+ searchQuery: " refund policy ",
+ searchType: ["content"],
+ });
+ });
+});
function lower(text: string) {
return astToFilterState(parse(text).ast);
@@ -966,14 +1130,13 @@ describe("filterStateToQueryText", () => {
).toBe("-input:refund");
});
- it("rejects content: as an unknown field (the pseudo-field was removed)", () => {
- // `content:` is no longer a field, so a value form errors as "Unknown field".
- const r = lower('content:"refund"');
- expect(r.errors).toEqual(['Unknown field "content"']);
- expect(r.searchQuery).toBeNull();
- expect(r.searchType).toBeNull();
- // Bare `content:` (no value) is left to the parser β€” the adapter stays silent
- // (empty-value FilterNode returns before resolveField), so no double.
+ it("lowers content to the payload-only search lane", () => {
+ expect(lower('content:"refund"')).toMatchObject({
+ errors: [],
+ searchQuery: "refund",
+ searchType: ["content"],
+ filters: [],
+ });
expect(lower("content:").errors).toEqual([]);
});
@@ -1004,45 +1167,39 @@ describe("filterStateToQueryText", () => {
}
});
- it("normalizes a residual input scope to an input: column filter", () => {
- // A residual input/output searchType (legacy URL or the legacy toolbar)
- // renders as the scoped token, which reparses to a real column filter β€” the
- // deliberate canonicalization (searchType β†’ column filter on next commit).
+ it("keeps a residual input search in its backend lane", () => {
const { text } = filterStateToQueryText([], {
searchQuery: "refund policy",
searchType: ["input"],
});
- const r = astToFilterState(validateQuery(text).ast);
- expect(r.errors).toEqual([]);
- expect(r.filters).toEqual([
- {
- type: "string",
- column: "input",
- operator: "contains",
- value: "refund policy",
- },
- ]);
- expect(r.searchQuery).toBeNull();
- expect(r.searchType).toBeNull();
+ expect(text).toBe('in:input "refund policy"');
+ expect(planCommit(text)).toMatchObject({
+ status: "committed",
+ filters: [],
+ searchQuery: "refund policy",
+ searchType: ["input"],
+ });
});
- it("renders the default scope (ids+names+input+output) as bare free text", () => {
- // Any subset of {id, content} is the default scope β€” no scope token, so it
- // round-trips to bare free text (and the caller re-applies the default).
- for (const searchType of [
- ["id"],
- ["id", "content"],
- ["content"],
- ] as const) {
- const { text } = filterStateToQueryText([], {
+ it("only renders the exact default scope as bare text", () => {
+ expect(
+ filterStateToQueryText([], {
searchQuery: "hello",
- searchType: [...searchType],
- });
- expect(text, `${searchType}`).toBe("hello");
- const r = astToFilterState(validateQuery(text).ast);
- expect(r.searchType).toBeNull();
- expect(r.searchQuery).toBe("hello");
- }
+ searchType: ["id", "content"],
+ }).text,
+ ).toBe("hello");
+ expect(
+ filterStateToQueryText([], {
+ searchQuery: "hello",
+ searchType: ["content"],
+ }).text,
+ ).toBe("content:hello");
+ expect(
+ filterStateToQueryText([], {
+ searchQuery: "hello",
+ searchType: ["id"],
+ }).text,
+ ).toBe("in:id hello");
});
it("preserves EXACT semantics for a single-value stringOptions any-of on id/name", () => {
diff --git a/web/src/features/search-bar/lib/adapter.ts b/web/src/features/search-bar/lib/adapter.ts
index 21dcb76b35..6de1fb4722 100644
--- a/web/src/features/search-bar/lib/adapter.ts
+++ b/web/src/features/search-bar/lib/adapter.ts
@@ -13,7 +13,8 @@
// Rules:
// - Top-level AND chain: bare text nodes become searchQuery terms (the default
// scope searches ids+names+input+output); everything else lowers into one or
-// more single filters. The bar emits no scope token, so searchType is null.
+// more single filters. Declared search scopes select the one backend phrase;
+// absent a scope token, the registry supplies the host's default.
// - A top-level OR of same-field `key:v` equalities collapses to one any-of
// filter (`level:ERROR OR level:WARNING` === `level:(ERROR OR WARNING)`).
// Any other OR/nested group is not representable.
@@ -49,10 +50,8 @@ export type AstToFilterStateResult = {
filters: FilterState;
searchQuery: string | null;
/**
- * Full-text scope. Always null today: the bar has no scope tokens β€” bare free
- * text uses the caller's default (ids+names+input+output), and `input:`/
- * `output:`/`name:`/`id:` are column filters, not scopes. Kept as the seam for
- * caller-default resolution (commit.ts) and any future scope token.
+ * Selected backend search lanes, or null for the registry's default.
+ * Real column filters remain separate from this global search phrase.
*/
searchType: TracingSearchType[] | null;
errors: string[];
@@ -141,6 +140,8 @@ type LowerContext = {
errors: string[];
scoreTypes?: ScoreTypeContext;
registry: FieldRegistry;
+ scopedSearch?: { query: string; searchType: readonly TracingSearchType[] };
+ compatibilitySearchType?: TracingSearchType[];
};
export function astToFilterState(
@@ -161,16 +162,33 @@ export function astToFilterState(
}
const defaultTextFilter = lowerDefaultTextField(ctx);
+ if (
+ ctx.scopedSearch &&
+ (ctx.searchTerms.length > 0 || ctx.compatibilitySearchType)
+ ) {
+ ctx.errors.push(
+ "Only one search phrase is supported β€” use either bare text or one scoped search",
+ );
+ }
+ if (
+ ctx.compatibilitySearchType &&
+ ctx.searchTerms.length === 0 &&
+ !ctx.scopedSearch
+ ) {
+ ctx.errors.push("Add search text after in:");
+ }
ctx.errors.push(...(registry.filterStateErrors?.(ctx.filters) ?? []));
return {
filters: ctx.filters,
searchQuery:
- defaultTextFilter || ctx.searchTerms.length === 0
+ ctx.scopedSearch?.query ??
+ (defaultTextFilter || ctx.searchTerms.length === 0
? null
- : ctx.searchTerms.join(" "),
- // The bar has no scope tokens; the caller (commit.ts) applies the default.
- searchType: null,
+ : ctx.searchTerms.join(" ")),
+ searchType: ctx.scopedSearch
+ ? [...ctx.scopedSearch.searchType]
+ : (ctx.compatibilitySearchType ?? null),
errors: ctx.errors,
};
}
@@ -279,6 +297,63 @@ function lowerFilterNode(
negated: boolean,
ctx: LowerContext,
): void {
+ const ref = ctx.registry.resolveField(node.key);
+ if (
+ ref?.type === "searchScope" ||
+ (ref?.type === "pseudo" && ref.id === "in")
+ ) {
+ if (node.values.length === 0) return;
+ const issue =
+ operatorIssue(ref, node.op, node.valueOp ?? "or") ??
+ (negated ? negationIssue(ref, node.op, node.valueOp ?? "or") : null);
+ if (issue) {
+ ctx.errors.push(issue);
+ return;
+ }
+ if (ref.type === "searchScope") {
+ if (node.values.length !== 1) {
+ ctx.errors.push(
+ `${ref.id}: accepts one search phrase, not grouped values`,
+ );
+ return;
+ }
+ if (node.values[0]!.trim().length === 0) {
+ ctx.errors.push(`Enter a search phrase after ${ref.id}:`);
+ return;
+ }
+ if (ctx.scopedSearch) {
+ ctx.errors.push("Only one scoped search phrase is supported");
+ return;
+ }
+ ctx.scopedSearch = {
+ query: node.values[0]!,
+ searchType: ref.scope.searchType,
+ };
+ } else {
+ if (ctx.compatibilitySearchType) {
+ ctx.errors.push("Only one in: scope selection is supported");
+ return;
+ }
+ const supported = new Set<string>([
+ ...ctx.registry.defaultSearchType,
+ ...Object.values(ctx.registry.searchScopes).flatMap(
+ (scope) => scope.searchType,
+ ),
+ ...["input", "output"].filter(
+ (field) => ctx.registry.resolveField(field)?.type === "field",
+ ),
+ ]);
+ const types = node.values.map((value) => value.toLowerCase());
+ if (types.some((type) => !supported.has(type))) {
+ ctx.errors.push(
+ `Unsupported search scope β€” choose ${[...supported].join(", ")}`,
+ );
+ return;
+ }
+ ctx.compatibilitySearchType = [...new Set(types)] as TracingSearchType[];
+ }
+ return;
+ }
lowerFilter(
node,
negated,
@@ -327,7 +402,7 @@ function lowerFilter(
switch (ref.type) {
case "pseudo":
- // `has` is the only pseudo-field.
+ // Global search scopes are handled by lowerFilterNode.
lowerHas(node, negated, out, errors, registry);
return;
case "metadata":
diff --git a/web/src/features/search-bar/lib/commit.ts b/web/src/features/search-bar/lib/commit.ts
index d65d16a86f..0af665d137 100644
--- a/web/src/features/search-bar/lib/commit.ts
+++ b/web/src/features/search-bar/lib/commit.ts
@@ -19,11 +19,8 @@ import {
import { serialize, type Diagnostic } from "./langQ";
import { validateQuery } from "./validate";
-// The full-text scope a bare query (no scope token) applies: ids & names
-// (`id` lane) PLUS input & output (`content` lane). Typing plain text searches
-// all of them. `input:`/`output:` narrow to one column; `name:`/`id:` narrow to
-// those. `content` here is the backend searchType lane (input βˆͺ output), not a
-// user-typed token β€” the `content:` grammar token has been removed.
+// The full Events default. Other hosts declare their own defaultSearchType
+// in the registry so bare text keeps the host's existing search behavior.
export const DEFAULT_SEARCH_TYPE: TracingSearchType[] = ["id", "content"];
export type CommitResult =
@@ -78,7 +75,7 @@ export function planCommit(
status: "committed",
filters,
searchQuery,
- searchType: searchType ?? DEFAULT_SEARCH_TYPE,
+ searchType: searchType ?? [...registry.defaultSearchType],
canonical: serialize(res.ast, registry),
};
}
diff --git a/web/src/features/search-bar/lib/completions.clienttest.ts b/web/src/features/search-bar/lib/completions.clienttest.ts
index 5999d373e1..853c257944 100644
--- a/web/src/features/search-bar/lib/completions.clienttest.ts
+++ b/web/src/features/search-bar/lib/completions.clienttest.ts
@@ -17,6 +17,8 @@ import {
toObservedOptions,
type ObservedOptions,
} from "@/src/features/search-bar/lib/observed-options";
+import { createFieldRegistry, EVENTS_FIELD_REGISTRY } from "./fields";
+import { validateQuery } from "./validate";
const OBSERVED: ObservedOptions = {
level: [
@@ -47,6 +49,52 @@ function plan(
}
describe("planInputCompletions", () => {
+ it("offers only declared scope rewrites and keeps compatibility in: out of suggestions", () => {
+ const registry = createFieldRegistry({
+ ...EVENTS_FIELD_REGISTRY,
+ fields: [],
+ defaultSearchType: ["id"],
+ freeTextScopeLabel: "prompt names and tags",
+ searchScopes: {
+ content: {
+ searchType: ["content"],
+ label: "Content",
+ description: "search prompt content",
+ },
+ },
+ });
+ const optionsFor = (input: string) =>
+ flattenOptions(
+ planInputCompletions(
+ {
+ input,
+ caret: input.length,
+ currentQueryText: input,
+ observed: {},
+ recents: [],
+ },
+ registry,
+ ),
+ );
+ const fields = optionsFor("").filter((option) => option.kind === "field");
+ expect(fields.some((option) => option.label === "content")).toBe(true);
+ expect(fields.some((option) => option.label === "in")).toBe(false);
+ const rewrites = optionsFor("refund policy").filter(
+ (option) => option.kind === "pattern" && option.id.startsWith("scope:"),
+ );
+ expect(rewrites.map((option) => option.label)).toEqual([
+ '"refund policy"',
+ 'content:"refund policy"',
+ ]);
+ for (const option of rewrites)
+ expect(validateQuery(option.label, undefined, registry).valid).toBe(true);
+ expect(
+ optionsFor('content:"refund policy"').some(
+ (option) => option.kind === "pattern" && option.id === "scope:default",
+ ),
+ ).toBe(true);
+ });
+
it("plans the empty stage with fields and recents", () => {
const p = plan("", 0, { recents: ["level:ERROR"] });
expect(p?.stage).toBe("empty");
@@ -491,8 +539,15 @@ describe("planInputCompletions", () => {
const labels = opts.map((o) => o.label);
expect(labels).toContain("input:refund");
expect(labels).toContain("output:refund");
- // content: was removed β€” the default already searches input + output.
- expect(labels).not.toContain("content:refund");
+ // Explicit content excludes IDs/names; all preserves the complete scope.
+ expect(labels).toContain("content:refund");
+ expect(labels).not.toContain("all:refund");
+ expect(
+ flattenOptions(plan("", 0)).some(
+ (option) => option.kind === "field" && option.fieldId === "all",
+ ),
+ ).toBe(false);
+ expect(validateQuery("all:refund").valid).toBe(true);
});
it("scopes the WHOLE coalesced free-text run, not just the caret word", () => {
@@ -577,7 +632,7 @@ describe("planInputCompletions", () => {
);
expect(ids).not.toContain("scope:input");
// content: was removed β€” never offered as a switch target.
- expect(ids).not.toContain("scope:content");
+ expect(ids).toContain("scope:content");
const toOutput = opts.find((o) => o.id === "scope:output");
expect(toOutput && "insert" in toOutput && toOutput.insert).toBe(
"output:abc",
@@ -739,7 +794,7 @@ describe("planInputCompletions", () => {
expect.arrayContaining(["scope:input", "scope:default"]),
);
expect(ids).not.toContain("scope:output");
- expect(ids).not.toContain("scope:content");
+ expect(ids).toContain("scope:content");
});
it("treats leading ~/^/$ as literal value chars, not suppressing prefixes", () => {
diff --git a/web/src/features/search-bar/lib/completions.ts b/web/src/features/search-bar/lib/completions.ts
index 554b4c3885..f1d8b69090 100644
--- a/web/src/features/search-bar/lib/completions.ts
+++ b/web/src/features/search-bar/lib/completions.ts
@@ -191,6 +191,15 @@ const PATTERN_OPTIONS: CompletionOption[] = [
// Ranking (prefix-before-substring) lives in ./rank so the filter sidebar's
// per-facet value search can share it β€” see that module's header.
+function suggestedSearchScopes(registry: FieldRegistry) {
+ const defaults = new Set(registry.defaultSearchType);
+ return Object.entries(registry.searchScopes).filter(
+ ([, scope]) =>
+ new Set(scope.searchType).size !== defaults.size ||
+ scope.searchType.some((type) => !defaults.has(type)),
+ );
+}
+
function fieldOptions(
registry: FieldRegistry,
includeVirtual = true,
@@ -204,6 +213,17 @@ function fieldOptions(
detail: f.description,
fieldId: f.id,
}));
+ if (includeVirtual && registry.allowFreeText) {
+ opts.push(
+ ...suggestedSearchScopes(registry).map(([id, scope]) => ({
+ id: `field:${id}`,
+ kind: "field" as const,
+ label: id,
+ detail: scope.description,
+ fieldId: id,
+ })),
+ );
+ }
if (includeVirtual && registry.metadata) {
opts.push({
id: "field:metadata.",
@@ -807,8 +827,18 @@ function valueStageSections(input: ValueStageInput): {
if (valuePrefix.length > 0) return null;
switch (ref.type) {
+ case "searchScope":
+ return typed.length > 0 && !negated
+ ? {
+ sections: section(
+ SECTION_SEARCH_IN,
+ scopeSwitchOptions(ref.id, typed, tokenSpan, registry),
+ ),
+ loading: false,
+ }
+ : null;
case "pseudo": {
- // `has` is the only pseudo-field: suggest the nullable fields it can name.
+ if (ref.id === "in") return null;
const all = registry.nullableFields().map((f) => ({
id: `value:${f.id}`,
kind: "value" as const,
@@ -1175,7 +1205,7 @@ function freeTextRun(
// The full-text scopes the bar can switch a value between. `default` is bare
// free text (ids, names, input & output); input:/output: are the scoped forms.
-type FullTextScope = "default" | "input" | "output";
+type FullTextScope = string;
// Switch options that move a full-text value between scopes, carrying the value
// and replacing the WHOLE token/run (replaceSpan). Used in both directions:
@@ -1203,6 +1233,11 @@ function scopeSwitchOptions(
): CompletionOption[] {
const v = serializeValue(value);
const allDefs: { scope: FullTextScope; insert: string; detail: string }[] = [
+ ...suggestedSearchScopes(registry).map(([scope, definition]) => ({
+ scope,
+ insert: `${scope}:${v}`,
+ detail: definition.description,
+ })),
{
scope: "input",
insert: `input:${v}`,
@@ -1222,8 +1257,11 @@ function scopeSwitchOptions(
},
];
const defs = allDefs.filter(
- (d) =>
- d.scope === "default" || registry.resolveField(d.scope)?.type === "field",
+ (d, index) =>
+ allDefs.findIndex((candidate) => candidate.scope === d.scope) === index &&
+ (d.scope === "default" ||
+ registry.resolveField(d.scope)?.type === "field" ||
+ registry.resolveField(d.scope)?.type === "searchScope"),
);
const alternatives = defs.filter((d) => d.scope !== current);
if (alternatives.length === 0) return [];
@@ -1377,7 +1415,7 @@ export function planInputCompletions(
const exactId =
exact?.type === "field"
? exact.field.id
- : exact?.type === "pseudo"
+ : exact?.type === "pseudo" || exact?.type === "searchScope"
? exact.id
: null;
return exactId === null
diff --git a/web/src/features/search-bar/lib/explain.clienttest.ts b/web/src/features/search-bar/lib/explain.clienttest.ts
index 28d986d410..dcaad985e6 100644
--- a/web/src/features/search-bar/lib/explain.clienttest.ts
+++ b/web/src/features/search-bar/lib/explain.clienttest.ts
@@ -3,17 +3,59 @@
import { deriveComposerSegments } from "@/src/features/search-bar/lib/composer-segments";
import { explainSegment } from "@/src/features/search-bar/lib/explain";
import { FIELDS } from "@/src/features/search-bar/lib/fields";
+import { SESSIONS_FIELD_REGISTRY } from "@/src/features/filters/config/sessionsSearchRegistry";
+import { SCORES_FIELD_REGISTRY } from "@/src/features/scores/constants/scoresSearchRegistry";
/** Explain the nth token of `query` as the tooltip reads it. */
function explain(query: string, index = 0): string | null {
const segment = deriveComposerSegments(query)[index];
- const explanation = segment === undefined ? null : explainSegment(segment);
+ const explanation =
+ segment === undefined ? null : explainSegment(segment, undefined, query);
return explanation === null
? null
: `${explanation.subject} ${explanation.predicate}`.trim();
}
describe("explainSegment", () => {
+ it.each([
+ ["Session ID", SESSIONS_FIELD_REGISTRY],
+ ["Score name", SCORES_FIELD_REGISTRY],
+ ] as const)("explains the default field %s", (subject, registry) => {
+ const segment = deriveComposerSegments(
+ '"refund policy"',
+ undefined,
+ registry,
+ )[0]!;
+ expect(explainSegment(segment, registry)).toEqual({
+ subject,
+ predicate: 'contains "refund policy".',
+ });
+ });
+
+ it("explains search scopes separately from column filters", () => {
+ expect(explain('content:"refund policy"')).toBe(
+ 'Content β€” search only input and output for "refund policy".',
+ );
+ expect(explain('all:"refund policy"')).toBe(
+ 'All fields β€” search IDs, names, input and output for "refund policy".',
+ );
+ expect(explain('input:"refund policy"')).toBe(
+ 'Input contains "refund policy".',
+ );
+ });
+
+ it("explains a restored search scope as a scope selection", () => {
+ expect(explain('in:(id OR input) "refund policy"')).toBe(
+ "Search scope uses id or input.",
+ );
+ expect(explain('in:(id OR input) "refund policy"', 1)).toBe(
+ 'Full-text search for "refund policy" β€” uses the scope selected by in:.',
+ );
+ expect(explain('"refund policy"')).toBe(
+ 'Full-text search for "refund policy" β€” matches ids, names, input & output.',
+ );
+ });
+
it("explains the shapes users misread", () => {
// The reported confusion: what does a leading dash mean, and what is `env`?
expect(explain("-env:langfuse-experiments")).toBe(
diff --git a/web/src/features/search-bar/lib/explain.ts b/web/src/features/search-bar/lib/explain.ts
index 746e7ff789..1a7ddd2d0b 100644
--- a/web/src/features/search-bar/lib/explain.ts
+++ b/web/src/features/search-bar/lib/explain.ts
@@ -11,8 +11,8 @@
// the word the predicate already carries ("Exactly. … is exactly …"), and the
// field is the half users actually misread (`env`, `tps`, `-`).
-import { INVERTED_COMPARISON } from "./adapter";
-import type { CompareOp } from "./ast";
+import { astToFilterState, INVERTED_COMPARISON } from "./adapter";
+import type { ASTNode, CompareOp } from "./ast";
import type { ComposerSegment, FilterSegment } from "./composer-segments";
import {
EVENTS_FIELD_REGISTRY,
@@ -20,6 +20,7 @@ import {
type FieldRef,
type FieldRegistry,
} from "./fields";
+import { parse } from "./langQ";
export type TokenExplanation = {
/** Bold lead-in: the field this token filters on. */
@@ -74,6 +75,8 @@ function subjectOf(ref: FieldRef): string {
return ref.level === "trace"
? `Trace score ${quote(ref.key)}`
: `Score ${quote(ref.key)}`;
+ case "searchScope":
+ return ref.scope.label;
case "pseudo":
return ref.id;
}
@@ -211,6 +214,13 @@ const KEYWORDS: Record<string, TokenExplanation> = {
NOT: { subject: "NOT", predicate: "β€” excludes the filter that follows." },
};
+function hasCompatibilityScope(ast: ASTNode, registry: FieldRegistry): boolean {
+ if (ast.kind === "and")
+ return ast.children.some((node) => hasCompatibilityScope(node, registry));
+ const ref = ast.kind === "filter" ? registry.resolveField(ast.key) : null;
+ return ref?.type === "pseudo" && ref.id === "in";
+}
+
/**
* Explain one token in plain language, or null when there is nothing useful to
* say (parentheses, an unknown field, an invalid token β€” those carry their own
@@ -219,12 +229,26 @@ const KEYWORDS: Record<string, TokenExplanation> = {
export function explainSegment(
seg: ComposerSegment,
registry: FieldRegistry = EVENTS_FIELD_REGISTRY,
+ queryText?: string,
): TokenExplanation | null {
switch (seg.kind) {
case "filter": {
const ref = registry.resolveField(seg.displayField);
if (ref === null) return null;
- if (ref.type === "pseudo") return explainHas(seg, registry);
+ if (ref.type === "pseudo") {
+ return ref.id === "has"
+ ? explainHas(seg, registry)
+ : {
+ subject: "Search scope",
+ predicate: `uses ${seg.values.join(" or ")}.`,
+ };
+ }
+ if (ref.type === "searchScope") {
+ return {
+ subject: ref.scope.label,
+ predicate: `β€” ${ref.scope.description} for ${quote(seg.values[0] ?? "")}.`,
+ };
+ }
if (ref.type === "field" && ref.field.kind === "boolean") {
return explainBoolean(ref.field, seg);
}
@@ -233,13 +257,46 @@ export function explainSegment(
predicate: `${predicateOf(ref, seg)}.`,
};
}
- case "freeText":
+ case "freeText": {
+ const parsed = parse(seg.raw, registry);
+ const lowered = astToFilterState(parsed.ast, undefined, registry);
+ if (!registry.allowFreeText && registry.defaultTextField !== null) {
+ const ref = registry.resolveField(registry.defaultTextField);
+ const filter = lowered.filters[0];
+ if (
+ ref?.type !== "field" ||
+ !parsed.valid ||
+ lowered.errors.length > 0 ||
+ filter?.type !== "string"
+ )
+ return null;
+ return {
+ subject: ref.field.label,
+ predicate: `${filter.operator} ${quote(filter.value)}.`,
+ };
+ }
+ const phrase = quote(lowered.searchQuery ?? seg.raw.trim());
+ if (queryText !== undefined) {
+ const query = parse(queryText, registry);
+ if (
+ query.valid &&
+ query.ast !== null &&
+ hasCompatibilityScope(query.ast, registry) &&
+ astToFilterState(query.ast, undefined, registry).errors.length === 0
+ ) {
+ return {
+ subject: "Full-text search",
+ predicate: `for ${phrase} β€” uses the scope selected by in:.`,
+ };
+ }
+ }
return {
subject: "Full-text search",
predicate: registry.freeTextScopeLabel
- ? `for ${quote(seg.raw.trim())} β€” matches ${registry.freeTextScopeLabel}.`
- : `for ${quote(seg.raw.trim())}.`,
+ ? `for ${phrase} β€” matches ${registry.freeTextScopeLabel}.`
+ : `for ${phrase}.`,
};
+ }
case "operator":
return KEYWORDS[seg.raw.toUpperCase()] ?? null;
default:
diff --git a/web/src/features/search-bar/lib/fields.ts b/web/src/features/search-bar/lib/fields.ts
index c92905f4c5..8e45ba5f8e 100644
--- a/web/src/features/search-bar/lib/fields.ts
+++ b/web/src/features/search-bar/lib/fields.ts
@@ -21,6 +21,7 @@ import {
type ColumnDefinition,
type FilterState,
type SingleValueOption,
+ type TracingSearchType,
} from "@langfuse/shared";
import type { CompareOp } from "./ast";
@@ -70,6 +71,12 @@ export type FieldDef = {
directFilter?: boolean;
};
+export type SearchScope = {
+ searchType: readonly TracingSearchType[];
+ label: string;
+ description: string;
+};
+
export type FieldRegistry = {
id:
| "events"
@@ -89,7 +96,10 @@ export type FieldRegistry = {
| "prompts"
| "monitors"
| "gatewayModels"
- | "experimentItems";
+ | "experimentItems"
+ | "datasetItems";
+ defaultSearchType: readonly TracingSearchType[];
+ searchScopes: Readonly<Record<string, SearchScope>>;
fields: readonly FieldDef[];
columns: readonly ColumnDefinition[];
allowFreeText: boolean;
@@ -172,6 +182,8 @@ export function fieldRegistryFromColumns(
/** Defaults to `scores`. */
traceScores?: boolean;
allowFreeText?: boolean;
+ defaultSearchType?: readonly TracingSearchType[];
+ searchScopes?: Readonly<Record<string, SearchScope>>;
filterStateErrors?: (filters: FilterState) => readonly string[];
defaultTextField?: string;
freeTextScopeLabel?: string;
@@ -236,6 +248,8 @@ export function fieldRegistryFromColumns(
scores,
traceScores: overlay.traceScores ?? scores,
allowFreeText: overlay.allowFreeText ?? true,
+ defaultSearchType: overlay.defaultSearchType,
+ searchScopes: overlay.searchScopes,
filterStateErrors: overlay.filterStateErrors,
defaultTextField: overlay.defaultTextField ?? null,
freeTextScopeLabel: overlay.freeTextScopeLabel ?? null,
@@ -265,6 +279,8 @@ export function extendFieldRegistryWithColumns(
scores: registry.scores,
traceScores: registry.traceScores,
allowFreeText: registry.allowFreeText,
+ defaultSearchType: registry.defaultSearchType,
+ searchScopes: registry.searchScopes,
filterStateErrors: registry.filterStateErrors,
defaultTextField: registry.defaultTextField,
freeTextScopeLabel: registry.freeTextScopeLabel,
@@ -309,6 +325,8 @@ export function withFieldOptions(
scores: registry.scores,
traceScores: registry.traceScores,
allowFreeText: registry.allowFreeText,
+ defaultSearchType: registry.defaultSearchType,
+ searchScopes: registry.searchScopes,
filterStateErrors: registry.filterStateErrors,
defaultTextField: registry.defaultTextField,
freeTextScopeLabel: registry.freeTextScopeLabel,
@@ -381,9 +399,8 @@ const METADATA_PREFIX = "metadata.";
const SCORE_PREFIXES = ["scores.", "score."];
const TRACE_SCORE_PREFIXES = ["tracescores.", "trace_scores.", "tracescore."];
-// Pseudo-fields: not columns β€” `has:<field>` lowers to a null filter. (The
-// former `content:` pseudo-field has been removed: a bare query now searches
-// input + output by default, and `input:`/`output:` narrow to one column.)
+// Presence checks lower to null filters. Compatibility `in:` and declared
+// search scopes select the backend search lane without adding column filters.
const HAS_KEY = "has";
/** Langfuse score filter columns (filter by score NAME via key-value ops). */
@@ -411,9 +428,10 @@ function isKeyedScoreColumn(column: string): boolean {
export type FieldRef =
| { type: "field"; field: FieldDef }
+ | { type: "searchScope"; id: string; scope: SearchScope }
| { type: "metadata"; key: string }
| { type: "scores"; key: string; level: "observation" | "trace" }
- | { type: "pseudo"; id: typeof HAS_KEY };
+ | { type: "pseudo"; id: typeof HAS_KEY | "in" };
/**
* Assembles a registry from field defs that already exist. `fieldRegistryFromColumns`
@@ -431,6 +449,8 @@ export function createFieldRegistry({
scores,
traceScores,
allowFreeText,
+ defaultSearchType = ["id", "content"],
+ searchScopes = {},
filterStateErrors,
defaultTextField,
freeTextScopeLabel,
@@ -447,6 +467,8 @@ export function createFieldRegistry({
scores: boolean;
traceScores: boolean;
allowFreeText: boolean;
+ defaultSearchType?: readonly TracingSearchType[];
+ searchScopes?: Readonly<Record<string, SearchScope>>;
/** View-specific backend constraints beyond individual column operators. */
filterStateErrors?: (filters: FilterState) => readonly string[];
defaultTextField: string | null;
@@ -482,6 +504,8 @@ export function createFieldRegistry({
fields,
columns,
allowFreeText,
+ defaultSearchType,
+ searchScopes,
filterStateErrors,
metadata,
scores,
@@ -517,6 +541,18 @@ export const EVENTS_FIELD_REGISTRY = createFieldRegistry({
scores: true,
traceScores: true,
allowFreeText: true,
+ searchScopes: {
+ content: {
+ searchType: ["content"],
+ label: "Content",
+ description: "search only input and output",
+ },
+ all: {
+ searchType: ["id", "content"],
+ label: "All fields",
+ description: "search IDs, names, input and output",
+ },
+ },
defaultTextField: null,
freeTextScopeLabel: "ids, names, input & output",
searchExamples: [
@@ -596,6 +632,17 @@ function resolveFromRegistry(
}
}
if (lower === HAS_KEY) return { type: "pseudo", id: lower };
+ if (
+ registry.allowFreeText &&
+ Object.keys(registry.searchScopes).length > 0 &&
+ lower === "in"
+ )
+ return { type: "pseudo", id: "in" };
+ const scope = Object.hasOwn(registry.searchScopes, lower)
+ ? registry.searchScopes[lower]
+ : undefined;
+ if (registry.allowFreeText && scope)
+ return { type: "searchScope", id: lower, scope };
const field = byName.get(lower);
return field ? { type: "field", field } : null;
}
@@ -669,10 +716,13 @@ export function operatorIssue(
}
switch (ref.type) {
+ case "searchScope":
+ return op === "="
+ ? null
+ : `${ref.id}: searches one phrase β€” ${label(op)} is not supported`;
case "pseudo":
- // `has` is the only pseudo-field.
if (op !== "=") {
- return `has: lists fields that have a value β€” it does not support ${label(op)}`;
+ return `${ref.id}: lists ${ref.id === "has" ? "fields that have a value" : "search scopes"} β€” it does not support ${label(op)}`;
}
return null;
case "metadata":
@@ -737,12 +787,18 @@ export function negationIssue(
op: CompareOp,
valueOp: "or" | "and" = "or",
): string | null {
+ if (
+ ref.type === "searchScope" ||
+ (ref.type === "pseudo" && ref.id === "in")
+ ) {
+ return `Search scopes cannot be negated β€” search text is global`;
+ }
if (valueOp === "and") {
// NOT(all of) would mean "missing at least one" β€” no such array operator.
return `negated all-of groups on "${refName(ref)}" are not representable β€” negate single values instead`;
}
if (ref.type === "pseudo") {
- return null; // `has` is the only pseudo; -has: is valid (missing value)
+ return null; // -has: is valid (missing value); in: was rejected above.
}
if (op === "^" || op === "$") {
return `negation of ${label(op)} is not representable in the Langfuse filter contract`;
@@ -785,6 +841,7 @@ function refName(ref: FieldRef): string {
? `traceScores.${quoteIfNeeded(ref.key)}`
: `scores.${quoteIfNeeded(ref.key)}`;
case "pseudo":
+ case "searchScope":
return ref.id;
}
}
diff --git a/web/src/features/search-bar/lib/filter-state-to-query.ts b/web/src/features/search-bar/lib/filter-state-to-query.ts
index deee391030..753888a7e3 100644
--- a/web/src/features/search-bar/lib/filter-state-to-query.ts
+++ b/web/src/features/search-bar/lib/filter-state-to-query.ts
@@ -259,48 +259,19 @@ export type FilterStateToQueryResult = {
export type FilterStateToQueryOptions = {
/** Global full-text query β€” rendered as bare text or a scoped field token. */
searchQuery?: string | null;
- /** Search scope β€” a residual input/output searchType renders as input:/output:;
- * the default (`["id","content"]` and any id/content subset) renders as bare
- * free text. */
+ /** Exact backend search lanes, projected through the host's registry. */
searchType?: TracingSearchType[] | null;
};
-// The default full-text scope searches ids, names, input, and output β€” the
-// `id` and `content` searchType lanes together. There is no scope token for it
-// (the `content:` token was removed), so it renders as bare free text.
-// astToFilterState returns `null` searchType for the bar (no scope tokens); the
-// sync layer maps that back to this default, hence `["id","content"]` (and any
-// subset) must also be recognized as "default" so it round-trips to bare text
-// rather than a stray scope token.
-const DEFAULT_SEARCH_TYPES: ReadonlySet<TracingSearchType> = new Set([
- "id",
- "content",
-]);
-
-function isDefaultSearchType(
- searchType: TracingSearchType[] | null | undefined,
+function sameSearchTypes(
+ a: readonly TracingSearchType[],
+ b: readonly TracingSearchType[],
): boolean {
return (
- searchType == null ||
- searchType.length === 0 ||
- searchType.every((t) => DEFAULT_SEARCH_TYPES.has(t))
+ new Set(a).size === new Set(b).size && a.every((type) => b.includes(type))
);
}
-// The bar field that expresses a non-default search scope. input/output alone
-// (e.g. from a pre-existing URL or the legacy toolbar) render as their real
-// text columns, which reparse to column filters β€” the intended convergence.
-// The default (ids+names+input+output) and id/content combos β†’ null (bare text).
-function scopedSearchField(
- searchType: TracingSearchType[] | null | undefined,
-): "input" | "output" | null {
- if (isDefaultSearchType(searchType)) return null;
- const set = new Set(searchType ?? []);
- if (set.has("input")) return "input";
- if (set.has("output")) return "output";
- return null;
-}
-
export function filterStateToQueryText(
filters: FilterState,
options: FilterStateToQueryOptions = {},
@@ -319,21 +290,18 @@ export function filterStateToQueryText(
nodes.push(node);
}
- // Full-text search. The default scope (ids+names+input+output) has no scope
- // token, so it renders as bare free text. A residual input/output searchType
- // (from a pre-existing URL or the legacy toolbar) bundles the whole query into
- // one `input:"…"`/`output:"…"` token, which reparses to its real column filter
- // β€” so such a searchType normalizes to a column filter on the next commit (the
- // deliberate canonicalization). The query is a single contiguous-substring
- // phrase (ILIKE %query%), so it renders as ONE token β€” quoted iff it has
- // whitespace via serializeValue. NOT whitespace-split: separate tokens would
- // misleadingly read as independent AND terms, disagree with the scope-rewrite
- // suggestions (which serialize the whole phrase), and strip a user's own
- // quotes on every derive.
- const searchQuery = options.searchQuery?.trim() ?? "";
- if (searchQuery.length > 0) {
- const scopeField = scopedSearchField(options.searchType);
- if (scopeField !== null) {
+ // One backend phrase can target several columns. Preserve the exact scope
+ // set: a legacy additive scope cannot become a payload-only column filter.
+ const searchQuery = options.searchQuery ?? "";
+ if (searchQuery.trim().length > 0) {
+ const searchType = options.searchType?.length
+ ? options.searchType
+ : registry.defaultSearchType;
+ const isDefault = sameSearchTypes(searchType, registry.defaultSearchType);
+ const scopeField = Object.entries(registry.searchScopes).find(([, scope]) =>
+ sameSearchTypes(searchType, scope.searchType),
+ )?.[0];
+ if (!isDefault && scopeField !== undefined) {
nodes.push({
kind: "filter",
key: scopeField,
@@ -341,6 +309,14 @@ export function filterStateToQueryText(
values: [searchQuery],
});
} else {
+ if (!isDefault) {
+ nodes.push({
+ kind: "filter",
+ key: "in",
+ op: "=",
+ values: [...searchType],
+ });
+ }
nodes.push({ kind: "text", value: searchQuery });
}
}
diff --git a/web/src/features/search-bar/lib/validate.clienttest.ts b/web/src/features/search-bar/lib/validate.clienttest.ts
index 1be58e3acb..1004a46575 100644
--- a/web/src/features/search-bar/lib/validate.clienttest.ts
+++ b/web/src/features/search-bar/lib/validate.clienttest.ts
@@ -82,6 +82,70 @@ describe("validateQuery β€” merged-diagnostic dedup", () => {
);
});
+describe("validateQuery β€” compatibility scope diagnostics", () => {
+ it("anchors an unsupported scope to its token beside other query terms", () => {
+ const query = "env:prod in:unknown refund";
+ const result = validateQuery(query);
+
+ expect(result.valid).toBe(false);
+ expect(result.diagnostics).toEqual([
+ {
+ from: query.indexOf("in:unknown"),
+ to: query.indexOf("in:unknown") + "in:unknown".length,
+ severity: "error",
+ message: expect.stringContaining("Unsupported search scope"),
+ },
+ ]);
+ });
+
+ it("anchors a missing phrase to the scope that requires it", () => {
+ const query = "env:prod in:id";
+
+ expect(validateQuery(query).diagnostics).toEqual([
+ {
+ from: query.indexOf("in:id"),
+ to: query.length,
+ severity: "error",
+ message: "Add search text after in:",
+ },
+ ]);
+ });
+
+ it("validates a scope with its phrase elsewhere in the query", () => {
+ expect(validateQuery("env:prod in:id refund")).toMatchObject({
+ valid: true,
+ diagnostics: [],
+ });
+ });
+
+ it("anchors a duplicate scope to the second scope token", () => {
+ const query = "assistant in:id in:content";
+
+ expect(validateQuery(query).diagnostics).toEqual([
+ {
+ from: query.indexOf("in:content"),
+ to: query.length,
+ severity: "error",
+ message: "Only one in: scope selection is supported",
+ },
+ ]);
+ });
+
+ it("does not add a missing-phrase error to competing scoped searches", () => {
+ const query = "env:prod content:refund in:id";
+
+ expect(validateQuery(query).diagnostics).toEqual([
+ {
+ from: 0,
+ to: query.length,
+ severity: "error",
+ message:
+ "Only one search phrase is supported β€” use either bare text or one scoped search",
+ },
+ ]);
+ });
+});
+
// LFE-11017: a partial filter token that isn't a complete expression must not
// silently apply to the query. A bare field word (`type`, no operator/value)
// used to parse as free text and lower to a full-text searchQuery, wiping the
diff --git a/web/src/features/search-bar/lib/validate.ts b/web/src/features/search-bar/lib/validate.ts
index 63067dabc8..b71e67b674 100644
--- a/web/src/features/search-bar/lib/validate.ts
+++ b/web/src/features/search-bar/lib/validate.ts
@@ -219,10 +219,34 @@ export function semanticDiagnostics(
const termRegistry = registry.filterStateErrors
? { ...registry, filterStateErrors: undefined }
: registry;
+ const { errors: wholeQueryErrors } = astToFilterState(
+ ast,
+ scoreTypes,
+ registry,
+ );
+ let firstCompatibilityScope: ASTNode | undefined;
for (const node of topLevel) {
- const { errors } = astToFilterState(node, scoreTypes, termRegistry);
+ const ref = node.kind === "filter" ? registry.resolveField(node.key) : null;
+ const isCompatibilityScope = ref?.type === "pseudo" && ref.id === "in";
+ // Include the first accepted scope so duplicate selections are diagnosed
+ // at the later token, using the same adapter rule as whole-query lowering.
+ const term: ASTNode =
+ isCompatibilityScope && firstCompatibilityScope
+ ? { kind: "and", children: [firstCompatibilityScope, node] }
+ : node;
+ const { errors, searchType } = astToFilterState(
+ term,
+ scoreTypes,
+ termRegistry,
+ );
+ if (isCompatibilityScope && searchType !== null) {
+ firstCompatibilityScope ??= node;
+ }
const span = nodeSpan(node, textLength);
for (const message of errors) {
+ // A compatibility scope uses a phrase elsewhere in the query. Keep its
+ // precise error span only when the complete query confirms the error.
+ if (isCompatibilityScope && !wholeQueryErrors.includes(message)) continue;
out.push({ from: span.from, to: span.to, severity: "error", message });
}
hasFilterWarnings(node, textLength, out, false, registry);
@@ -231,10 +255,9 @@ export function semanticDiagnostics(
// Some view contracts constrain the complete filter set (for example, one
// filter per column). Check the complete lowering as well as each term so
// draft validation and commit validation share the same backend boundary.
- if (registry.filterStateErrors) {
- const { errors } = astToFilterState(ast, scoreTypes, registry);
+ {
const span = nodeSpan(ast, textLength);
- for (const message of errors) {
+ for (const message of wholeQueryErrors) {
if (!out.some((diagnostic) => diagnostic.message === message)) {
out.push({ ...span, severity: "error", message });
}