Skip to content

feat(server): record brand mention position on tracking results - #569

Merged
gkhngyk merged 2 commits into
mainfrom
feature/mention-position-signal
Jul 31, 2026
Merged

gkhngyk merged 2 commits into
mainfrom
feature/mention-position-signal

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a deterministic mention-order signal to every tracking result: where the brand lands among the brand + tracked competitors named in an answer.

  • computeMentionPosition(text, brand, competitors) in response-parser.js — earliest word-boundary occurrence of each entity's name/domain in the URL-stripped answer text (same matching rules as the existing mention counting; no LLM involved). Returns the brand's 1-based rank (1 = named first, null = not mentioned) and how many tracked entities the answer names.
  • Migration 00038: two nullable columns on prompt_results — mention_position and mentioned_entity_count. NULL entity count doubles as the "not computed yet" marker; 0 means computed-and-empty.
  • Both insert paths persist the fields (Cloro webhook handler + worker's polling/API-model path).
  • src/scripts/backfill-mention-position.js: idempotent, paced backfill from the stored answer texts (--days N, --brand <id>, --dry-run), scoped to brands of active/trialing organizations.
  • 7 new unit tests for the position computation.

Not surfaced in any UI yet — the signal accumulates first so future position-aware metrics can be calibrated against real distributions before anything user-facing changes.

Related issue

—

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. yarn test from server/ — includes the new computeMentionPosition cases (first/middle/absent, domain-as-mention, URL-only names ignored, earliest-occurrence rule).
  2. After the migration is applied, run a tracking job — new prompt_results rows carry mention_position / mentioned_entity_count.
  3. node src/scripts/backfill-mention-position.js --dry-run prints the would-be scope without writing.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

@gkhngyk
gkhngyk merged commit 22c8cd3 into main Jul 31, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feature/mention-position-signal branch July 31, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant