Repository navigation
feat(content): generate one opportunity per prompt cluster - #930
Merged
Merged
Conversation
Opportunities were generated per prompt, so the same need asked several ways piled up near-identical suggestions (#857). They are now generated per prompt cluster (#925), with a score that explains itself. - One generator for the nightly run and the Generate button, which carried two copies of the same logic. The button refreshes clusters first. - Each run takes the three highest-scoring clusters that have answers and no opportunity yet, and writes one opportunity per cluster. A cluster that already has one, in any status, is not suggested again. - A cluster that needs the same content as an opportunity in another topic is merged into it (related_cluster_ids) instead of getting a near-copy. - Cluster metrics come from the Insights rollups over the last 30 days: the same figures from raw answers take about 50 s on the largest brand. The competitor gap is the strongest competitor's visibility minus the brand's; the old sum grew with the number of answers. - Score components are stored with the opportunity. Demand moves to a log scale, since summed cluster volumes put most clusters at the old cap. - The brief lists the cluster's prompts as the questions to answer and its fan-out queries as related searches. - The detail page shows the basket (prompts, included and excluded searches with reasons) and the score breakdown. - Migration 00102 adds cluster_id and related_cluster_ids to content_opportunities and the brand_prompt_opportunity_metrics function. prompt_id stays, set to the cluster's highest-volume prompt, so filters, webhooks and MCP keep working.
7 tasks done
gkhngyk
added a commit
that referenced
this pull request
Oct 5, 2026
Cluster opportunities (#930) were listed among thousands of untouched per-prompt ones, and the prompt filter only matched an opportunity's own prompt_id (#857). - Migration 00103 archives the per-prompt backlog: status 'new', no cluster, no brief. Nothing is deleted; Restore on the detail page sets one back to 'new'. The list, its summary and the MCP list hide archived rows unless the Archived status is chosen. - The prompt filter matches the opportunities of the prompt's cluster, own or merged, and still matches older ones by prompt_id. Its option counts are computed the same way. - A topic filter matches opportunities whose own or merged clusters are in the topic, with options from GET /brand/:id/topics. - content_opportunity_aggregates takes the topic filter, matches prompts through clusters and returns the brand's signal count: the prompts and fan-out queries its clusters were built from. The first KPI card shows it as "from N signals analyzed". - A run picks at most one cluster per topic, so its few suggestions spread across the brand's topics.
This was referenced Oct 7, 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
Second of three PRs for #857. Content opportunities are now generated per prompt cluster (#925) instead of per prompt. The score now shows what it is made of.
Generation
generateContentOpportunities, and the button refreshes clusters first.related_cluster_ids;Score
source_data.scoreComponents.brand_prompt_opportunity_metrics. Computing the same figures from raw answers took about 50 s on the largest brand and timed out; the rollups take about 0.6 s.Brief
Detail page
GET /api/content/:id/basket.Compatibility
cluster_idandrelated_cluster_idstocontent_opportunities, plus the metrics function. It is already applied to the hosted database.prompt_idis still set, to the cluster's highest-volume prompt, so the prompt filter, webhooks and MCP keep working. PR 3 moves the filters to clusters and maps the old per-prompt backlog.Tried on production data
On a 35-prompt brand with 14 clusters, one run produced 3 opportunities in about 8 s.
Related issue
Part of #857
Type of change
feat— New featurerefactor— The Generate button and the nightly run share one generatortest— Adding or updating testsHow to test
opportunity-limits.test.jscovers the cluster metrics, the score components and the log scale, and which clusters are covered and picked.Checklist
yarn lint,yarn typecheck,yarn format:check,yarn test(400) andyarn buildpass (run fromweb/)yarn lint,yarn format:checkandyarn test(944) pass (run fromserver/)supabase/schema.sqlrebuilt withbuild-schema.sh🤖 Generated with Claude Code