Skip to content

feat(core): AI visibility score compute layer — weights module and component RPCs - #573

Merged
gkhngyk merged 1 commit into
mainfrom
feature/ai-visibility-score-core
Jul 31, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/ai-visibility-score-core

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Foundation layer for position-aware visibility scoring (builds on #569/#572). No UI changes yet.

Score definition, one place per runtime:

  • web/src/lib/visibility-score.ts + mirrored server/src/config/visibility-score.js: canonical weights {mention: 0.6, citation: 0.25, position: 0.15} and computeAiVisibilityScore(components) → 0-100, one decimal, null for empty scopes. Every future surface calls this — recalibrating weights is a one-line change, never a migration.
  • 6 unit tests (blend math, null position, empty scope, natural 100 cap, rounding, weights-sum-to-1).

Component RPCs (migration 00040, already applied to the hosted database):

  • New ai_visibility_aggregates — brand + per-competitor {answers, mention_answers, citation_answers, position_factor} in one call, shared denominator, live competitors only (00035 semantics), same 8-param filter surface as competitor_aggregates.
  • prompt_visibility_summaries gains the three components per prompt (DROP + CREATE as in 00034/00037; all existing columns kept, so current consumers are untouched).
  • visibility_rate_trend gains per-day components for the brand and each competitor; existing keys unchanged, so the live trend chart keeps working as-is.

RPCs return raw components only — all blending happens in the JS modules, keeping the formula in exactly one place.

Verified against live data: RPC-computed components reproduce hand-rolled SQL aggregation exactly for a full brand + competitor set over a 7-day window.

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 web/ — includes the new visibility-score cases.
  2. select ai_visibility_aggregates('<brand>', null, null, null, now() - interval '7 days', null, null, null); returns brand + competitor components.
  3. Existing surfaces (All Prompts column, trend chart) behave identically — only additive fields.

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 b2232cf into main Jul 31, 2026
5 checks passed
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