Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(taxonomic-filter): run event match as an experiment and say why it has no suggestion (#117758)

Paul D'Ambradb7618529723
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 5427da06d4cb..7cfd85faa277 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3616,6 +3616,14 @@ snapshots:
hash: v1.k794b7964.c9c8b86f1f196faf8bb7ff2fa3a8b662b5da749e9d740979253eefd3caef6d83.Vi2aZn3Sv-3nBjiCPo9tkuX4Dj5bZSq-4KMFkSMAKps
filters-taxonomic-filter--empty-events-with-stale-toggle--light:
hash: v1.k794b7964.06c743209b67d84e2d6403f78e9a8dbb412f4d552936335f6380b841ab20ea05.RJKRGsdtc3psVWSHimWW-MDLaXIyUbQj2dU33xEIYC0
+ filters-taxonomic-filter--empty-events-with-unsent-event-hint--dark:
+ hash: v1.k794b7964.36dcc5f7829de403957bb284997042af8755fb33347ec245644328201b96a6be.WR_e3wcaujsOyjKVUAzJKopna3G4E9WWFjGLZzRXbgY
+ filters-taxonomic-filter--empty-events-with-unsent-event-hint--light:
+ hash: v1.k794b7964.3726716eae08f672c2d989ad565e947f5a2c2a9b3339cac58672cf2ff506579a.rzmd0zlST6aJiPXxMNXFZe4lwLeS07kxpVspx9so32A
+ filters-taxonomic-filter--empty-events-with-value-hint--dark:
+ hash: v1.k794b7964.56b8792ce05a2bd6639b561f1330df09e67cf01fa9307301aa91560ff69442dd.mnfSSv24JeDgvtTRf6YX_-olqjQUQIzvd7GVi6CFMNU
+ filters-taxonomic-filter--empty-events-with-value-hint--light:
+ hash: v1.k794b7964.97ddd61650806011675ac41c4ca31e0409b894993096eaa1e645e5748502be1a.NtvmxNSJzpPc-osNFNOzk85H2kVtbmQKDUClTvwYPfA
filters-taxonomic-filter--events-free--dark:
hash: v1.k794b7964.66ffbc1a41e65685646edaa051c0112d431e5f99dcca205d6a62f2bd3ce60f4c.9sxt-JbSQIxs9w_imI-y34flHbdgcsTC57Md7yFCVzM
filters-taxonomic-filter--events-free--light:
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index d23bca73e497..3ddc1e8970db 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -5418,9 +5418,42 @@ export interface EventMatchApi {
probability: number
}
+/**
+ * * `wrong_length` - The search is too short or too long to ask about
+ * * `only_values` - Nothing but values is left for the model to read
+ * * `unavailable` - The model could not answer at all
+ * * `partial` - Some model requests failed, so an event it never asked about might have matched
+ * * `nothing_likely` - The model found no core event likely
+ * * `not_ingested` - The project never sent the likely events
+ * * `matched` - At least one likely event has data
+ */
+export type EventMatchOutcomeEnumApi = (typeof EventMatchOutcomeEnumApi)[keyof typeof EventMatchOutcomeEnumApi]
+
+export const EventMatchOutcomeEnumApi = {
+ WrongLength: 'wrong_length',
+ OnlyValues: 'only_values',
+ Unavailable: 'unavailable',
+ Partial: 'partial',
+ NothingLikely: 'nothing_likely',
+ NotIngested: 'not_ingested',
+ Matched: 'matched',
+} as const
+
export interface EventMatchResponseApi {
/** PostHog core events the search most likely means, strongest first. Empty when nothing is likely. */
matches: EventMatchApi[]
+ /** The step that decided the answer, so an empty answer says why it is empty.
+ *
+ * * `wrong_length` - The search is too short or too long to ask about
+ * * `only_values` - Nothing but values is left for the model to read
+ * * `unavailable` - The model could not answer at all
+ * * `partial` - Some model requests failed, so an event it never asked about might have matched
+ * * `nothing_likely` - The model found no core event likely
+ * * `not_ingested` - The project never sent the likely events
+ * * `matched` - At least one likely event has data */
+ outcome: EventMatchOutcomeEnumApi
+ /** Likely core events this project never sent, strongest first. Only filled when outcome is not_ingested. */
+ unsent: EventMatchApi[]
}
/**
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
index f9e13e9b112b..dde9347d611b 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
@@ -5,12 +5,40 @@ import { LemonButton } from '@posthog/lemon-ui'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { infiniteListLogic } from './infiniteListLogic'
-import { taxonomicEventMatchLogic } from './taxonomicEventMatchLogic'
+import { EventMatchHint, taxonomicEventMatchLogic } from './taxonomicEventMatchLogic'
+
+function listOfNames(names: string[]): string {
+ if (names.length <= 1) {
+ return names.join('')
+ }
+ return `${names.slice(0, -1).join(', ')} or ${names[names.length - 1]}`
+}
+
+function EventMatchHintMessage({ hint }: { hint: EventMatchHint }): JSX.Element {
+ if (hint.kind === 'unsent') {
+ return (
+ <div className="flex flex-col items-center gap-y-1" data-attr="taxonomic-event-match-unsent">
+ <span className="text-secondary text-center max-w-80">
+ This looks like <strong>{listOfNames(hint.events.map((event) => event.display_name))}</strong>,
+ which this project hasn't sent yet.
+ </span>
+ </div>
+ )
+ }
+
+ return (
+ <div className="flex flex-col items-center gap-y-1" data-attr="taxonomic-event-match-value">
+ <span className="text-secondary text-center max-w-80">
+ This looks like a value, not an event name. Pick the property that holds it, then filter on the value.
+ </span>
+ </div>
+ )
+}
export function TaxonomicEventMatchSuggestions(): JSX.Element | null {
const { props } = useMountedLogic(infiniteListLogic)
const logic = taxonomicEventMatchLogic(props)
- const { suggestedEvents, isMatching } = useValues(logic)
+ const { suggestedEvents, isMatching, hint } = useValues(logic)
const { selectEventMatch } = useActions(logic)
if (isMatching) {
@@ -23,7 +51,7 @@ export function TaxonomicEventMatchSuggestions(): JSX.Element | null {
}
if (suggestedEvents.length === 0) {
- return null
+ return hint ? <EventMatchHintMessage hint={hint} /> : null
}
return (
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
index dbaee792172b..acc03ca08fa7 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
@@ -883,11 +883,24 @@ const eventMatchAutocaptureMock = mswDecorator({
{ name: '$autocapture', display_name: 'Autocapture', probability: 0.95 },
{ name: '$rageclick', display_name: 'Rageclick', probability: 0.74 },
],
+ outcome: 'matched',
+ unsent: [],
},
],
},
})
+const eventMatchAnswerMock = (answer: Record<string, unknown>): ReturnType<typeof mswDecorator> =>
+ mswDecorator({
+ get: {
+ '/api/projects/:team_id/event_definitions': [],
+ '/api/projects/:team_id/property_definitions': { results: [], count: 0 },
+ },
+ post: {
+ '/api/projects/:team_id/taxonomic_search_intent/match_events/': () => [200, answer],
+ },
+ })
+
/** A search that matches no event name gets core events the decision model thinks it describes. */
export const EmptyEventsWithEventMatch: Story = {
render: EventMatchStoryRender,
@@ -897,7 +910,7 @@ export const EmptyEventsWithEventMatch: Story = {
},
decorators: [eventMatchAutocaptureMock],
parameters: {
- featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: 'test' },
testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-suggestion"]' },
},
}
@@ -911,11 +924,45 @@ export const EmptyAllTabWithEventMatch: Story = {
},
decorators: [eventMatchAutocaptureMock],
parameters: {
- featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: 'test' },
testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-suggestion"]' },
},
}
+/** The model's likely event was never sent by this project, so the empty state names it instead of suggesting it. */
+export const EmptyEventsWithUnsentEventHint: Story = {
+ render: (args) => <EventMatchStoryRender {...args} resetMatches />,
+ args: {
+ taxonomicFilterLogicKey: 'events-event-match-unsent',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ },
+ decorators: [
+ eventMatchAnswerMock({
+ matches: [],
+ outcome: 'not_ingested',
+ unsent: [{ name: '$screen', display_name: 'Screen', probability: 0.85 }],
+ }),
+ ],
+ parameters: {
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: 'test' },
+ testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-unsent"]' },
+ },
+}
+
+/** A search made only of values gets a pointer to properties instead of an event suggestion. */
+export const EmptyEventsWithValueHint: Story = {
+ render: (args) => <EventMatchStoryRender {...args} resetMatches />,
+ args: {
+ taxonomicFilterLogicKey: 'events-event-match-value',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.EventProperties],
+ },
+ decorators: [eventMatchAnswerMock({ matches: [], outcome: 'only_values', unsent: [] })],
+ parameters: {
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: 'test' },
+ testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-value"]' },
+ },
+}
+
/** While the decision model is still answering, the empty state says so. */
export const EmptyEventsWithEventMatchLoading: Story = {
render: (args) => <EventMatchStoryRender {...args} resetMatches />,
@@ -931,13 +978,13 @@ export const EmptyEventsWithEventMatchLoading: Story = {
post: {
'/api/projects/:team_id/taxonomic_search_intent/match_events/': async () => {
await delay('infinite')
- return [200, { matches: [] }]
+ return [200, { matches: [], outcome: 'nothing_likely', unsent: [] }]
},
},
}),
],
parameters: {
- featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: 'test' },
// The spinner is the point of this story, so the runner must not wait for it to disappear.
testOptions: {
waitForSelector: '[data-attr="taxonomic-event-match-loading"]',
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
index 3a87e7204839..daeeb780624c 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
@@ -31,6 +31,8 @@ const ALL_TAB_PROPS: TaxonomicFilterLogicProps = {
taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions],
}
+const ELIGIBLE_EVENT = 'taxonomic filter event match eligible'
+
const AUTOCAPTURE = { name: '$autocapture', display_name: 'Autocapture', probability: 0.95 }
describe('taxonomicEventMatchLogic', () => {
@@ -39,12 +41,16 @@ describe('taxonomicEventMatchLogic', () => {
let matchRequests: Record<string, any>[]
let status: number
let matches: Record<string, any>[]
+ let outcome: string
+ let unsent: Record<string, any>[]
let answerGate: Promise<void> | null
beforeEach(() => {
matchRequests = []
status = 200
matches = [AUTOCAPTURE]
+ outcome = 'matched'
+ unsent = []
answerGate = null
resetEventMatchMemoryForTests()
useMocks({
@@ -57,7 +63,7 @@ describe('taxonomicEventMatchLogic', () => {
if (answerGate) {
await answerGate
}
- return status === 200 ? [200, { matches }] : [status, {}]
+ return status === 200 ? [200, { matches, outcome, unsent }] : [status, {}]
},
},
})
@@ -77,9 +83,9 @@ describe('taxonomicEventMatchLogic', () => {
await expectLogic(logic).toFinishAllListeners()
}
- const enroll = (enabled: boolean): void => {
+ const enroll = (variant: 'test' | 'control' | false): void => {
featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH], {
- [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: enabled,
+ [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: variant,
})
}
@@ -104,10 +110,11 @@ describe('taxonomicEventMatchLogic', () => {
it.each([
['for a person outside the flag', (): typeof logic => (enroll(false), logic)],
+ ['for a person in the control arm', (): typeof logic => (enroll('control'), logic)],
[
'from a tab that never shows suggestions',
(): typeof logic => {
- enroll(true)
+ enroll('test')
const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
allTabFilterLogic.actions.setActiveTab(TaxonomicFilterGroupType.Actions)
allTabFilterLogic.actions.setSearchQuery('browser capture')
@@ -138,7 +145,7 @@ describe('taxonomicEventMatchLogic', () => {
1,
],
])('drops the ask when another tab opens %s', async (_, waitBeforeSwitch, expectedRequests) => {
- enroll(true)
+ enroll('test')
const captureSpy = jest.spyOn(posthog, 'capture')
const answer = holdAnswer()
const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
@@ -153,10 +160,12 @@ describe('taxonomicEventMatchLogic', () => {
expect(allTabLogic.values.isMatching).toBe(false)
expect(allTabLogic.values.suggestedEvents).toEqual([])
expect(captureSpy).not.toHaveBeenCalledWith('taxonomic filter event match suggested', expect.anything())
+ // Exposure counts only once the pause ended on a visible list.
+ expect(captureSpy.mock.calls.filter(([event]) => event === ELIGIBLE_EVENT)).toHaveLength(expectedRequests)
})
it('shows a loading state from the All tab until the answer arrives, and records the tab', async () => {
- enroll(true)
+ enroll('test')
const captureSpy = jest.spyOn(posthog, 'capture')
const answer = holdAnswer()
const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
@@ -181,7 +190,7 @@ describe('taxonomicEventMatchLogic', () => {
})
it('suggests the matched events for the current search only, and selects one on click', async () => {
- enroll(true)
+ enroll('test')
const captureSpy = jest.spyOn(posthog, 'capture')
await search('browser capture')
@@ -208,7 +217,7 @@ describe('taxonomicEventMatchLogic', () => {
})
it('shows the remembered answer again when the empty state remounts for the same search', async () => {
- enroll(true)
+ enroll('test')
const captureSpy = jest.spyOn(posthog, 'capture')
await search('browser capture')
expect(matchRequests).toHaveLength(1)
@@ -236,7 +245,7 @@ describe('taxonomicEventMatchLogic', () => {
excludingFilterLogic.mount()
const excludingLogic = taxonomicEventMatchLogic(excludingProps)
excludingLogic.mount()
- enroll(true)
+ enroll('test')
const captureSpy = jest.spyOn(posthog, 'capture')
excludingFilterLogic.actions.setSearchQuery('browser capture')
@@ -257,7 +266,7 @@ describe('taxonomicEventMatchLogic', () => {
excludingFilterLogic.mount()
const excludingLogic = taxonomicEventMatchLogic(excludingProps)
excludingLogic.mount()
- enroll(true)
+ enroll('test')
matches = [
AUTOCAPTURE,
{ name: '$rageclick', display_name: 'Rageclick', probability: 0.9 },
@@ -277,14 +286,19 @@ describe('taxonomicEventMatchLogic', () => {
})
it('stops asking for the project after a 404', async () => {
- enroll(true)
+ enroll('test')
status = 404
+ const captureSpy = jest.spyOn(posthog, 'capture')
+
await search('browser capture')
await search('page view')
expect(matchRequests).toHaveLength(1)
expect(logic.values.suggestedEvents).toEqual([])
+ expect(logic.values.isMatching).toBe(false)
+ // A 404 must not make the test arm look less exposed than control.
+ expect(captureSpy.mock.calls.filter(([event]) => event === ELIGIBLE_EVENT)).toHaveLength(2)
})
it.each([
@@ -293,7 +307,7 @@ describe('taxonomicEventMatchLogic', () => {
[503, false],
[500, true],
])('reports a %s failure to error tracking: %s', async (failureStatus, reported) => {
- enroll(true)
+ enroll('test')
status = failureStatus
const captureExceptionSpy = jest.spyOn(posthog, 'captureException').mockImplementation(() => undefined as any)
@@ -306,4 +320,115 @@ describe('taxonomicEventMatchLogic', () => {
: []
)
})
+
+ it.each([['control'], ['test']] as const)(
+ 'reports the %s arm as eligible once per search, after the pause',
+ async (variant) => {
+ enroll(variant)
+ const captureSpy = jest.spyOn(posthog, 'capture')
+
+ // A prefix typed before the pause ends must not count as a search.
+ filterLogic.actions.setSearchQuery('browser')
+ await search('browser capture')
+ logic.unmount()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ const eligible = captureSpy.mock.calls.filter(([event]) => event === ELIGIBLE_EVENT)
+ expect(eligible).toEqual([
+ ['taxonomic filter event match eligible', { surface: 'legacy-pill', tab: 'events', variant }],
+ ])
+ expect(matchRequests).toHaveLength(variant === 'test' ? 1 : 0)
+ }
+ )
+
+ it('names the likely events the project never sent instead of suggesting them', async () => {
+ enroll('test')
+ matches = []
+ outcome = 'not_ingested'
+ unsent = [{ name: '$screen', display_name: 'Screen', probability: 0.85 }]
+ const captureSpy = jest.spyOn(posthog, 'capture')
+
+ await search('mobile screen')
+
+ expect(logic.values.suggestedEvents).toEqual([])
+ expect(logic.values.hint).toEqual({ kind: 'unsent', events: unsent })
+ expect(captureSpy).toHaveBeenCalledWith('taxonomic filter event match hint shown', {
+ surface: 'legacy-pill',
+ tab: 'events',
+ hint: 'unsent',
+ unsentEvents: ['$screen'],
+ })
+ })
+
+ it('does not name an unsent event the picker excludes', async () => {
+ const excludingProps: TaxonomicFilterLogicProps = {
+ ...PROPS,
+ taxonomicFilterLogicKey: 'event-match-excluding-unsent-test',
+ excludedProperties: { [TaxonomicFilterGroupType.Events]: ['$screen'] },
+ }
+ const excludingFilterLogic = taxonomicFilterLogic(excludingProps)
+ excludingFilterLogic.mount()
+ const excludingLogic = taxonomicEventMatchLogic(excludingProps)
+ excludingLogic.mount()
+ enroll('test')
+ matches = []
+ outcome = 'not_ingested'
+ unsent = [{ name: '$screen', display_name: 'Screen', probability: 0.85 }]
+
+ excludingFilterLogic.actions.setSearchQuery('mobile screen')
+ await expectLogic(excludingLogic).toFinishAllListeners()
+
+ expect(excludingLogic.values.hint).toBeNull()
+ })
+
+ it.each([
+ { picker: 'events only', taxonomicGroupTypes: [TaxonomicFilterGroupType.Events], hint: null },
+ {
+ picker: 'events and event properties',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.EventProperties],
+ hint: { kind: 'value' },
+ },
+ {
+ picker: 'events and person properties',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.PersonProperties],
+ hint: { kind: 'value' },
+ },
+ {
+ picker: 'events and session properties',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.SessionProperties],
+ hint: { kind: 'value' },
+ },
+ ])(
+ 'points a value search at properties only where one can be picked: $picker',
+ async ({ taxonomicGroupTypes, hint }) => {
+ enroll('test')
+ matches = []
+ outcome = 'only_values'
+ const pickerProps: TaxonomicFilterLogicProps = {
+ taxonomicFilterLogicKey: `event-match-value-hint-${taxonomicGroupTypes.join('-')}`,
+ taxonomicGroupTypes,
+ }
+ const pickerFilterLogic = taxonomicFilterLogic(pickerProps)
+ pickerFilterLogic.mount()
+ const pickerLogic = taxonomicEventMatchLogic(pickerProps)
+ pickerLogic.mount()
+ pickerFilterLogic.actions.setActiveTab(TaxonomicFilterGroupType.Events)
+
+ pickerFilterLogic.actions.setSearchQuery('[email protected]')
+ await expectLogic(pickerLogic).toFinishAllListeners()
+
+ expect(pickerLogic.values.hint).toEqual(hint)
+ }
+ )
+
+ it('shows no hint when the model simply found nothing likely', async () => {
+ enroll('test')
+ matches = []
+ outcome = 'nothing_likely'
+
+ await search('browser capture')
+
+ expect(logic.values.hint).toBeNull()
+ })
})
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
index 844715630d60..cfa67e6a7458 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
@@ -6,7 +6,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { projectLogic } from 'scenes/projectLogic'
import { taxonomicSearchIntentMatchEventsCreate } from '~/generated/core/api'
-import type { EventMatchApi } from '~/generated/core/api.schemas'
+import type { EventMatchApi, EventMatchOutcomeEnumApi } from '~/generated/core/api.schemas'
import type { FeatureFlagsSet } from '../../logic/featureFlagLogic'
import { SelectItemMeta, taxonomicFilterLogic } from './taxonomicFilterLogic'
@@ -30,24 +30,75 @@ const EVENT_MATCH_DEBOUNCE_MS = 350
const UNREPORTED_FAILURE_STATUSES = [429, 503]
// The picker keeps every tab's list mounted and hides the inactive ones, so only the open tab may ask the model.
const TABS_WITH_SUGGESTIONS = [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.SuggestedFilters]
+// The flag is an experiment. Only the test arm asks the model; both arms report that they reached the dead end.
+const EXPERIMENT_VARIANTS = ['control', 'test']
+const TEST_VARIANT = 'test'
-export interface EventMatches {
+export interface EventMatchAnswer {
+ matches: EventMatchApi[]
+ outcome: EventMatchOutcomeEnumApi
+ unsent: EventMatchApi[]
+}
+
+export interface EventMatches extends EventMatchAnswer {
projectId: number
query: string
- matches: EventMatchApi[]
}
+/** What the empty state can say when the model has no event to suggest. */
+export type EventMatchHint = { kind: 'unsent'; events: EventMatchApi[] } | { kind: 'value' }
+
// A 404 means the person is not in the flag for this project, so the rest of the page load does not ask again.
const unavailableProjectIds = new Set<number>()
// Switching between the All and Events tabs remounts the empty state and this logic with it, so each answer is
// kept for the page load and shown again without another model call. The backend caches the same key.
-const answeredMatches = new Map<string, EventMatchApi[]>()
+const answeredMatches = new Map<string, EventMatchAnswer>()
+// Exposure for the experiment: one report per search per page load, so retyping or remounting does not count twice.
+const reportedEligible = new Set<string>()
const matchKey = (projectId: number, query: string): string => `${projectId}:${query}`
+// A value belongs to a property, so the value hint only helps in a picker where the person can pick one.
+const PROPERTY_GROUP_TYPES = [
+ TaxonomicFilterGroupType.EventProperties,
+ TaxonomicFilterGroupType.PersonProperties,
+ TaxonomicFilterGroupType.SessionProperties,
+]
+
+function offersProperties(taxonomicGroupTypes: TaxonomicFilterGroupType[]): boolean {
+ return PROPERTY_GROUP_TYPES.some((groupType) => taxonomicGroupTypes.includes(groupType))
+}
+
export function resetEventMatchMemoryForTests(): void {
unavailableProjectIds.clear()
answeredMatches.clear()
+ reportedEligible.clear()
+}
+
+function reportEligible(projectId: number, query: string, tab: TaxonomicFilterGroupType, variant: string): void {
+ const key = matchKey(projectId, query)
+ if (reportedEligible.has(key)) {
+ return
+ }
+ reportedEligible.add(key)
+ // pinned: analytics event name and properties, the experiment's exposure reads them
+ posthog.capture('taxonomic filter event match eligible', {
+ surface: legacyTaxonomicSurface(),
+ tab,
+ variant,
+ })
+}
+
+function reportHint(hint: EventMatchHint | null, tab: TaxonomicFilterGroupType): void {
+ if (!hint) {
+ return
+ }
+ posthog.capture('taxonomic filter event match hint shown', {
+ surface: legacyTaxonomicSurface(),
+ tab,
+ hint: hint.kind,
+ unsentEvents: hint.kind === 'unsent' ? hint.events.map((event) => event.name) : undefined,
+ })
}
function reportSuggested(shown: EventMatchApi[], tab: TaxonomicFilterGroupType): void {
@@ -71,7 +122,9 @@ export interface taxonomicEventMatchLogicValues {
searchQuery: string // taxonomicFilterLogic
taxonomicGroupTypes: TaxonomicFilterGroupType[] // taxonomicFilterLogic
taxonomicGroups: TaxonomicFilterGroup[] // taxonomicFilterLogic
+ currentAnswer: EventMatches | null
eventMatches: EventMatches | null
+ hint: EventMatchHint | null
isMatching: boolean
pendingQuery: string | null
suggestedEvents: EventMatchApi[]
@@ -112,11 +165,20 @@ export interface taxonomicEventMatchLogicActions {
export interface taxonomicEventMatchLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
- suggestedEvents: (
+ currentAnswer: (
eventMatches: EventMatches | null,
searchQuery: string,
- taxonomicGroups: TaxonomicFilterGroup[],
currentProjectId: number | null
+ ) => EventMatches | null
+ hint: (
+ currentAnswer: EventMatches | null,
+ suggestedEvents: EventMatchApi[],
+ taxonomicGroups: TaxonomicFilterGroup[],
+ taxonomicGroupTypes: TaxonomicFilterGroupType[]
+ ) => EventMatchHint | null
+ suggestedEvents: (
+ currentAnswer: EventMatches | null,
+ taxonomicGroups: TaxonomicFilterGroup[]
) => EventMatchApi[]
isMatching: (pendingQuery: string | null, searchQuery: string) => boolean
tabShowsSuggestions: (activeTab: TaxonomicFilterGroupType) => boolean
@@ -130,9 +192,18 @@ export type taxonomicEventMatchLogicType = MakeLogicType<
taxonomicEventMatchLogicMeta
>
+// A picker that excludes an event from its list must not offer or name it either.
+function withoutExcluded(events: EventMatchApi[], taxonomicGroups: TaxonomicFilterGroup[]): EventMatchApi[] {
+ const excluded =
+ taxonomicGroups.find((group) => group.type === TaxonomicFilterGroupType.Events)?.excludedProperties ?? []
+ return events.filter((event) => !excluded.includes(event.name)).slice(0, MAX_SUGGESTIONS)
+}
+
/**
* Asks the decision model which PostHog core events a search that matched no event name describes, for the
- * `taxonomic-filter-event-match` flag. Mounted by the empty state of the events list and of the "All" list.
+ * `taxonomic-filter-event-match` experiment. Mounted by the empty state of the events list and of the "All" list.
+ * The test arm suggests the matched events, or says why there are none: the likely event was never sent, or the
+ * search is only values. The control arm asks nothing and only reports that it reached the dead end.
* Legacy surface only.
*/
export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
@@ -172,25 +243,44 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
],
}),
selectors({
- suggestedEvents: [
- (s) => [s.eventMatches, s.searchQuery, s.taxonomicGroups, s.currentProjectId],
+ currentAnswer: [
+ (s) => [s.eventMatches, s.searchQuery, s.currentProjectId],
(
eventMatches: EventMatches | null,
searchQuery: string,
- taxonomicGroups: TaxonomicFilterGroup[],
currentProjectId: number | null
- ): EventMatchApi[] => {
+ ): EventMatches | null =>
// An answer for an older search or another project stays hidden, so a suggestion never names the wrong one.
- if (eventMatches?.query !== searchQuery.trim() || eventMatches.projectId !== currentProjectId) {
- return []
+ eventMatches?.query === searchQuery.trim() && eventMatches.projectId === currentProjectId
+ ? eventMatches
+ : null,
+ ],
+ hint: [
+ (s) => [s.currentAnswer, s.suggestedEvents, s.taxonomicGroups, s.taxonomicGroupTypes],
+ (
+ currentAnswer: EventMatches | null,
+ suggestedEvents: EventMatchApi[],
+ taxonomicGroups: TaxonomicFilterGroup[],
+ taxonomicGroupTypes: TaxonomicFilterGroupType[]
+ ): EventMatchHint | null => {
+ if (!currentAnswer || suggestedEvents.length > 0) {
+ return null
+ }
+ if (currentAnswer.outcome === 'only_values') {
+ return offersProperties(taxonomicGroupTypes) ? { kind: 'value' } : null
+ }
+ if (currentAnswer.outcome === 'not_ingested') {
+ const events = withoutExcluded(currentAnswer.unsent, taxonomicGroups)
+ return events.length > 0 ? { kind: 'unsent', events } : null
}
- // A picker that excludes an event from its list must not offer it as a suggestion either.
- const excluded =
- taxonomicGroups.find((group) => group.type === TaxonomicFilterGroupType.Events)
- ?.excludedProperties ?? []
- return eventMatches.matches.filter((match) => !excluded.includes(match.name)).slice(0, MAX_SUGGESTIONS)
+ return null
},
],
+ suggestedEvents: [
+ (s) => [s.currentAnswer, s.taxonomicGroups],
+ (currentAnswer: EventMatches | null, taxonomicGroups: TaxonomicFilterGroup[]): EventMatchApi[] =>
+ currentAnswer ? withoutExcluded(currentAnswer.matches, taxonomicGroups) : [],
+ ],
isMatching: [
(s) => [s.pendingQuery, s.searchQuery],
(pendingQuery: string | null, searchQuery: string): boolean =>
@@ -208,34 +298,46 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
findEventMatches: async ({ searchQuery }, breakpoint) => {
const query = searchQuery.trim()
const projectId = values.currentProjectId
+ const variant = values.featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]
if (
query.length < MIN_QUERY_LENGTH ||
query.length > MAX_QUERY_LENGTH ||
projectId === null ||
- unavailableProjectIds.has(projectId) ||
- !values.featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH] ||
+ !EXPERIMENT_VARIANTS.includes(String(variant)) ||
!values.tabShowsSuggestions ||
!values.taxonomicGroupTypes.includes(TaxonomicFilterGroupType.Events)
) {
return
}
- const remembered = answeredMatches.get(matchKey(projectId, query))
+ // A 404 blocks only the model call. Both arms still count as exposed, so the arms stay comparable.
+ const asksTheModel = variant === TEST_VARIANT && !unavailableProjectIds.has(projectId)
+ const remembered = asksTheModel ? answeredMatches.get(matchKey(projectId, query)) : undefined
if (remembered) {
- actions.setEventMatches({ projectId, query, matches: remembered })
+ reportEligible(projectId, query, values.activeTab, String(variant))
+ actions.setEventMatches({ projectId, query, ...remembered })
reportSuggested(values.suggestedEvents, values.activeTab)
+ reportHint(values.hint, values.activeTab)
return
}
- actions.startEventMatch(query)
+ if (asksTheModel) {
+ actions.startEventMatch(query)
+ }
await breakpoint(EVENT_MATCH_DEBOUNCE_MS)
// A tab opened during the pause hides this list, so the ask is dropped before it costs a model call.
if (!values.tabShowsSuggestions) {
actions.setEventMatches(null)
return
}
+ // Both arms count as exposed once a settled search reaches the dead end the model would answer.
+ reportEligible(projectId, query, values.activeTab, String(variant))
+ if (!asksTheModel) {
+ return
+ }
- let matches: EventMatchApi[]
+ let answer: EventMatchAnswer
try {
- matches = (await taxonomicSearchIntentMatchEventsCreate(String(projectId), { query })).matches
+ const response = await taxonomicSearchIntentMatchEventsCreate(String(projectId), { query })
+ answer = { matches: response.matches, outcome: response.outcome, unsent: response.unsent ?? [] }
} catch (error: any) {
if (error?.status === 404) {
unavailableProjectIds.add(projectId)
@@ -256,9 +358,10 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
actions.setEventMatches(null)
return
}
- answeredMatches.set(matchKey(projectId, query), matches)
- actions.setEventMatches({ projectId, query, matches })
+ answeredMatches.set(matchKey(projectId, query), answer)
+ actions.setEventMatches({ projectId, query, ...answer })
reportSuggested(values.suggestedEvents, values.activeTab)
+ reportHint(values.hint, values.activeTab)
},
selectEventMatch: ({ match }) => {
const eventsGroup = values.taxonomicGroups.find((group) => group.type === TaxonomicFilterGroupType.Events)
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 2e183a43fb96..3fa3a7830eb0 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -574,7 +574,7 @@ export const FEATURE_FLAGS = {
TASK_TOOL: 'phai-task-tool', // owner: @kappa90 #team-posthog-ai
TASKS: 'tasks', // owner: #team-ai-observability
TASKS_STREAM_VIA_PROXY: 'tasks-stream-via-proxy', // owner: #team-ai-observability
- TAXONOMIC_FILTER_EVENT_MATCH: 'taxonomic-filter-event-match', // owner: @pauldambra, asks the decision model which core events an events search with no results describes, then suggests them in the empty state
+ TAXONOMIC_FILTER_EVENT_MATCH: 'taxonomic-filter-event-match', // owner: @pauldambra multivariate=control,test, experiment: test asks the decision model which core events an events search with no results describes, then suggests them or says why there are none; control asks nothing
TAXONOMIC_FILTER_MENU_REBUILD: 'taxonomic-filter-menu-rebuild', // owner: @adamleith, opt-in to the rebuilt TaxonomicFilter — headless filter panel + new popover menu (column / preview-pane)
TAXONOMIC_FILTER_SEARCH_INTENT: 'taxonomic-filter-search-intent', // owner: @pauldambra multivariate=control,banner,promote, classifies a picker search with the decision model. control changes nothing, banner suggests the right tab, promote moves the predicted group to the top of the All tab
TEXT_CARD_WORD_ART: 'text-card-word-art', // owner: @jonmcwest, gates the word art insert button in dashboard text cards
diff --git a/posthog/api/taxonomic_search_intent.py b/posthog/api/taxonomic_search_intent.py
index b9ce4782ecf9..94851217cdf8 100644
--- a/posthog/api/taxonomic_search_intent.py
+++ b/posthog/api/taxonomic_search_intent.py
@@ -22,6 +22,7 @@ from posthog.llm.system_one import SystemOneNotConfigured, SystemOneRequestFaile
from posthog.models import User
from posthog.taxonomic_search_intent.classify import classify_search_intent, search_intent_enabled
from posthog.taxonomic_search_intent.contracts import (
+ EventMatch,
EventMatchOutcome,
EventMatchRequest,
SearchIntentRequest,
@@ -114,6 +115,18 @@ class EventMatchResponseSerializer(serializers.Serializer):
child=EventMatchSerializer(),
help_text="PostHog core events the search most likely means, strongest first. Empty when nothing is likely.",
)
+ outcome = serializers.ChoiceField(
+ choices=EventMatchOutcome.choices,
+ help_text="The step that decided the answer, so an empty answer says why it is empty.",
+ )
+ unsent = serializers.ListField(
+ child=EventMatchSerializer(),
+ help_text="Likely core events this project never sent, strongest first. Only filled when outcome is not_ingested.",
+ )
+
+
+def _serialize_match(match: EventMatch) -> dict[str, Any]:
+ return {"name": match.name, "display_name": match.label, "probability": match.probability}
class SearchIntentUnavailable(APIException):
@@ -223,10 +236,9 @@ class SearchIntentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
return Response(
EventMatchResponseSerializer(
{
- "matches": [
- {"name": match.name, "display_name": match.label, "probability": match.probability}
- for match in answer.matches
- ]
+ "matches": [_serialize_match(match) for match in answer.matches],
+ "outcome": answer.outcome.value,
+ "unsent": [_serialize_match(match) for match in answer.unsent],
}
).data
)
diff --git a/posthog/api/test/test_taxonomic_search_intent.py b/posthog/api/test/test_taxonomic_search_intent.py
index 6684ded1da93..154f22019749 100644
--- a/posthog/api/test/test_taxonomic_search_intent.py
+++ b/posthog/api/test/test_taxonomic_search_intent.py
@@ -134,10 +134,49 @@ class TestSearchIntentEndpoint(APIBaseTest):
assert flag.call_args.args[0] == "taxonomic-filter-event-match"
if expected_status == status.HTTP_200_OK:
assert response.json() == {
- "matches": [{"name": "$autocapture", "display_name": "Autocapture", "probability": 0.95}]
+ "matches": [{"name": "$autocapture", "display_name": "Autocapture", "probability": 0.95}],
+ "outcome": "matched",
+ "unsent": [],
}
assert matcher.call_args.args[0].project_id == self.team.project_id
if expected_outcome:
assert report.call_args.args[1:] == ("taxonomic filter event match answered", {"outcome": expected_outcome})
else:
report.assert_not_called()
+
+ @parameterized.expand(
+ [
+ (
+ "not_ingested",
+ EventMatchAnswer(
+ matches=[],
+ outcome=EventMatchOutcome.NOT_INGESTED,
+ unsent=[EventMatch(name="$screen", label="Screen", probability=0.85)],
+ ),
+ {
+ "matches": [],
+ "outcome": "not_ingested",
+ "unsent": [{"name": "$screen", "display_name": "Screen", "probability": 0.85}],
+ },
+ ),
+ (
+ "only_values",
+ EventMatchAnswer(matches=[], outcome=EventMatchOutcome.ONLY_VALUES),
+ {"matches": [], "outcome": "only_values", "unsent": []},
+ ),
+ ]
+ )
+ def test_tells_the_picker_why_an_answer_is_empty(self, _name, answer, expected) -> None:
+ with (
+ patch(FLAG_CHECK, return_value=True),
+ patch("posthog.api.taxonomic_search_intent.match_core_events", return_value=answer),
+ patch("posthog.api.taxonomic_search_intent.report_user_action"),
+ ):
+ response = self.client.post(
+ f"/api/projects/{self.team.id}/taxonomic_search_intent/match_events/",
+ {"query": "browser capture"},
+ format="json",
+ )
+
+ assert response.status_code == status.HTTP_200_OK
+ assert response.json() == expected
diff --git a/posthog/taxonomic_search_intent/contracts.py b/posthog/taxonomic_search_intent/contracts.py
index 69d501b73b34..3fa9ba3ae13e 100644
--- a/posthog/taxonomic_search_intent/contracts.py
+++ b/posthog/taxonomic_search_intent/contracts.py
@@ -1,3 +1,5 @@
+from dataclasses import field
+
from django.db import models
from posthog.dataclasses import frozen
@@ -69,3 +71,6 @@ class EventMatchAnswer:
matches: list[EventMatch]
outcome: EventMatchOutcome
+ # Likely core events the project never sent, strongest first. Filled only for NOT_INGESTED, so the picker can say
+ # what the search probably means instead of showing nothing.
+ unsent: list[EventMatch] = field(default_factory=list)
diff --git a/posthog/taxonomic_search_intent/event_match.py b/posthog/taxonomic_search_intent/event_match.py
index e92b8483538f..ac1ea91114f7 100644
--- a/posthog/taxonomic_search_intent/event_match.py
+++ b/posthog/taxonomic_search_intent/event_match.py
@@ -235,6 +235,6 @@ def match_core_events(request: EventMatchRequest, *, use_cache: bool = True) ->
matches = [match for match in likely if match.name in ingested]
if matches:
return EventMatchAnswer(matches=matches, outcome=EventMatchOutcome.MATCHED)
- return EventMatchAnswer(
- matches=[], outcome=EventMatchOutcome.NOT_INGESTED if complete else EventMatchOutcome.PARTIAL
- )
+ if not complete:
+ return EventMatchAnswer(matches=[], outcome=EventMatchOutcome.PARTIAL)
+ return EventMatchAnswer(matches=[], outcome=EventMatchOutcome.NOT_INGESTED, unsent=likely)
diff --git a/posthog/taxonomic_search_intent/test_event_match.py b/posthog/taxonomic_search_intent/test_event_match.py
index d54a539b3417..a265f108b463 100644
--- a/posthog/taxonomic_search_intent/test_event_match.py
+++ b/posthog/taxonomic_search_intent/test_event_match.py
@@ -99,6 +99,18 @@ class TestMatchCoreEvents(BaseTest):
assert answer.outcome == outcome
if outcome != EventMatchOutcome.MATCHED:
assert answer.matches == []
+ if outcome != EventMatchOutcome.NOT_INGESTED:
+ assert answer.unsent == []
+
+ def test_names_the_likely_events_the_project_never_sent(self) -> None:
+ with patch(BUILD_CLIENT, return_value=_model_that_believes({"Screen": 0.85})):
+ answer = match_core_events(self._search("browser capture"))
+
+ assert answer == EventMatchAnswer(
+ matches=[],
+ outcome=EventMatchOutcome.NOT_INGESTED,
+ unsent=[EventMatch(name="$screen", label="Screen", probability=0.85)],
+ )
def test_the_model_reads_placeholders_instead_of_values(self) -> None:
client = _model_that_believes({})
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 4813dd500c86..86ba4ecc9b16 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -43555,6 +43555,28 @@ export namespace Schemas {
probability: number;
}
+ /**
+ * * `wrong_length` - The search is too short or too long to ask about
+ * * `only_values` - Nothing but values is left for the model to read
+ * * `unavailable` - The model could not answer at all
+ * * `partial` - Some model requests failed, so an event it never asked about might have matched
+ * * `nothing_likely` - The model found no core event likely
+ * * `not_ingested` - The project never sent the likely events
+ * * `matched` - At least one likely event has data
+ */
+ export type EventMatchOutcomeEnum = typeof EventMatchOutcomeEnum[keyof typeof EventMatchOutcomeEnum];
+
+
+ export const EventMatchOutcomeEnum = {
+ WrongLength: 'wrong_length',
+ OnlyValues: 'only_values',
+ Unavailable: 'unavailable',
+ Partial: 'partial',
+ NothingLikely: 'nothing_likely',
+ NotIngested: 'not_ingested',
+ Matched: 'matched',
+ } as const;
+
export interface EventMatchRequest {
/**
* What the person typed into the events list search box, which matched no event name.
@@ -43566,6 +43588,18 @@ export namespace Schemas {
export interface EventMatchResponse {
/** PostHog core events the search most likely means, strongest first. Empty when nothing is likely. */
matches: EventMatch[];
+ /** The step that decided the answer, so an empty answer says why it is empty.
+ *
+ * * `wrong_length` - The search is too short or too long to ask about
+ * * `only_values` - Nothing but values is left for the model to read
+ * * `unavailable` - The model could not answer at all
+ * * `partial` - Some model requests failed, so an event it never asked about might have matched
+ * * `nothing_likely` - The model found no core event likely
+ * * `not_ingested` - The project never sent the likely events
+ * * `matched` - At least one likely event has data */
+ outcome: EventMatchOutcomeEnum;
+ /** Likely core events this project never sent, strongest first. Only filled when outcome is not_ingested. */
+ unsent: EventMatch[];
}
export type EventMatchScope = typeof EventMatchScope[keyof typeof EventMatchScope];