Repository navigation
feat(server): record brand mention position on tracking results - #569
Merged
Merged
Conversation
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)inresponse-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.00038: two nullable columns onprompt_results—mention_positionandmentioned_entity_count.NULLentity count doubles as the "not computed yet" marker;0means computed-and-empty.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.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
yarn testfromserver/— includes the newcomputeMentionPositioncases (first/middle/absent, domain-as-mention, URL-only names ignored, earliest-occurrence rule).prompt_resultsrows carrymention_position/mentioned_entity_count.node src/scripts/backfill-mention-position.js --dry-runprints the would-be scope without writing.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)