Skip to content

feat(server): record competitor mention positions on tracking results - #572

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

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

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the mention-order signal (#569) to competitors: computeMentionPosition now ranks every mentioned entity — the brand and each tracked competitor — by earliest word-boundary occurrence in the URL-stripped answer text, and parseResponse embeds each competitor's 1-based rank into its competitor_mentions entry as mention_position (null when that competitor isn't mentioned). Ranks are computed among all mentioned entities, so the brand's own rank is unchanged from #569.

  • No schema change — the field lives inside the existing competitor_mentions jsonb.
  • No insert-path changes — both paths already persist parseResponse's competitorMentions verbatim.
  • Backfill script reworked: walks all rows (offset paging over a stable ordering), annotates competitor entries from the stored answer texts, and skips rows already carrying both the columns and the per-entry keys — fully idempotent, bounded concurrency.
  • 3 new unit tests (competitor ranks among all entities, ranks without a brand mention, parseResponse embedding).

Still not surfaced in any UI — the signal accumulates alongside #569's.

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 competitor-rank cases.
  2. After a tracking run, competitor_mentions entries on new prompt_results rows carry mention_position.
  3. node src/scripts/backfill-mention-position.js --dry-run shows scope without writing; a real run annotates historical rows and a re-run skips them.

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 c130c97 into main Jul 31, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feature/competitor-mention-position branch July 31, 2026 21:22
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