Skip to content

GSC integration phase 3a: feed prompt suggestions with real Search Console demand #648

Closed

Description

@gkhngyk

Motivation

gsc_query_stats (#644) now holds each mapped brand's real Google demand. Today's prompt suggestions are generated from brand context alone — educated guesses. This issue feeds the suggestion engine with proven demand: queries people actually type that the brand does not yet track in AI answers.

Brands without the GSC integration are untouched: the current generation path keeps working exactly as-is — GSC is an optional enrichment, never a prerequisite.

Scope

1. Candidate mining (deterministic SQL)

Aggregate the last 28 days per query (sum impressions/clicks, avg position) for the brand, keep queries above a minimum impressions threshold.

2. Coverage-gap filter (deterministic)

Drop candidates already covered by a tracked prompt using normalized token overlap — no LLM in the filter. What survives is "searched on Google, untracked in AI".

3. Candidate composition — three slices with rationale badges

  • Head demand: top queries by impressions.
  • Click-based classification: high clicks → Protect existing traffic (AI answers will cannibalize these first); high impressions + low CTR → Capture unmet demand.
  • Long-tail quick wins: 4+ word queries above a lower threshold — specific, low-competition intents where becoming the cited answer is cheapest.

4. Competition enrichment via DataForSEO (v1, cost-capped)

Run the surviving candidates through the existing getSearchVolumes pipeline to attach competition_index → Low competition badge. Hard cost controls:

  • At most 20 candidates enriched per generation, in one batched request.
  • Per-query result cached 30 days — repeat refreshes cost zero new calls.
  • Env kill-switch to disable enrichment without losing the feature (badges just drop).

5. Prompt conversion & storage

Feed the final candidates into the existing suggestion generation as explicit context; the LLM's only job is converting a raw query into a trackable prompt phrasing (never inventing content). Extend prompt_suggestions with source ('llm' | 'gsc') and source_data (impressions, clicks, badge, original query) via a numbered migration.

6. UI

Suggestions card renders GSC-sourced entries with a "From Search Console" badge, monthly impressions, and the rationale badge (Protect existing traffic / Capture unmet demand / Low competition). Accept/dismiss flows unchanged.

7. Retention

Prune gsc_query_stats rows older than 90 days as part of the daily sync.

Out of scope

  • Search-vs-AI comparison surfaces (phase 3b).
  • Any change to suggestion behavior for brands without a connected + mapped GSC property.

Acceptance

  • A mapped brand's suggestion refresh includes GSC-sourced suggestions with correct badges and impression counts; raw queries are converted to natural prompt phrasings.
  • Queries already covered by tracked prompts are not suggested.
  • Enrichment never exceeds the per-generation cap and reuses the 30-day cache on repeat runs.
  • Brands without GSC (no connection, no mapping, or no Composio env) get exactly today's suggestions — no new API calls, no behavior change.
  • gsc_query_stats stays bounded by the 90-day retention.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions