Repository navigation
feat(core): AI visibility score compute layer — weights module and component RPCs - #573
Merged
Merged
Conversation
7 of 12 tasks
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
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+ mirroredserver/src/config/visibility-score.js: canonical weights{mention: 0.6, citation: 0.25, position: 0.15}andcomputeAiVisibilityScore(components)→ 0-100, one decimal,nullfor empty scopes. Every future surface calls this — recalibrating weights is a one-line change, never a migration.Component RPCs (migration
00040, already applied to the hosted database):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 ascompetitor_aggregates.prompt_visibility_summariesgains the three components per prompt (DROP + CREATE as in 00034/00037; all existing columns kept, so current consumers are untouched).visibility_rate_trendgains 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 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 testfromweb/— includes the newvisibility-scorecases.select ai_visibility_aggregates('<brand>', null, null, null, now() - interval '7 days', null, null, null);returns brand + competitor components.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)