Skip to content

feat(tracking): capture & store observed query fan-out (Cloro searchQueries / search_model_queries) #332

Closed

Description

@gkhngyk

Summary

Capture and store the query fan-out — the sub-queries an AI answer engine actually ran to build its answer — which Cloro already returns but we currently discard at every layer. This is the observed fan-out (the real sub-queries, straight from the engine), not an LLM prediction, so it costs no extra AI/scraper spend: the data is already in the Cloro response we poll.

This is the storage/capture foundation. The product surface (a "Query Fan-out" tab on the prompts page) is tracked separately in #333.

Verified live (Cloro tests, generic prompts)

Multiple live tests (informational, shopping, review prompts across ChatGPT / Copilot / Perplexity) established the per-platform shape and reliability:

Scraper Field on raw response Shape Reliability
copilot-web searchQueries string[] ✅ Primary — consistently populated
perplexity-web search_model_queries [{ query, engine, limit }] (e.g. engine: "web") ⚠️ Present for web/informational; absent for shopping (returns shopping_cards instead)
chatgpt-web searchQueries string[] ❌ Flag surfaces the key but it comes back empty ([]) in practice, even when ChatGPT searches + cites

Findings:

  • Copilot is the primary source; Perplexity is secondary (web queries only). ChatGPT is effectively empty — enable the flag (harmless, free) but don't rely on it.
  • Fan-out arrays are small (1–2 items in tests) and not emitted for every query type — expect sparse data.
  • Perplexity items carry an engine label (only "web" observed so far); other providers give no per-item type.
  • (Out of scope, noted for later: raw responses also carry entities / citationPills (ChatGPT) and related_queries (Perplexity) that we drop too.)

Why we don't have it today

All three layers drop it:

  1. Request — buildRequestBody in server/src/lib/cloro-scraper.js sets include.searchQueries: false for the ChatGPT-family task.
  2. Parser — parseScraperResponse (same file) never reads result.searchQueries / result.search_model_queries.
  3. Storage — prompt_results has no column for it (only response, citations, shopping_cards, inline_products, …).

Proposed (capture + store only)

  1. Migration — add search_queries jsonb NOT NULL DEFAULT '[]'::jsonb to prompt_results (numbered migration via the hosted migration workflow; regenerate supabase/schema.sql).
  2. Request — set include.searchQueries: true for the ChatGPT-family task in buildRequestBody (free; often empty, but harmless).
  3. Parser — in parseScraperResponse, return a rich, normalized array (do NOT flatten to plain strings — keep the engine label so the UI can use it):
    search_queries: [{ query: string, engine?: string, source_platform: string }]
    
    • Copilot / ChatGPT: (result.searchQueries ?? []).map(q => ({ query: q, source_platform }))
    • Perplexity: (result.search_model_queries ?? []).map(q => ({ query: q.query, engine: q.engine, source_platform })).filter(x => x.query)
    • Other providers: []
  4. Persist — write search_queries in the prompt_results insert in cloro-result-handler.js (covers both the polling and webhook paths).

Non-goals (separate)

Acceptance criteria

  • prompt_results.search_queries exists (jsonb, default []); existing rows default to [].
  • New Copilot / Perplexity results persist the observed fan-out as [{ query, engine?, source_platform }]; ChatGPT persists it when present.
  • Perplexity's engine is preserved per item.
  • No new AI/scraper spend — the data comes from the existing Cloro poll/webhook response.
  • server lint / format / tests pass; supabase/schema.sql regenerated.

Notes

  • t.js / caching: N/A.
  • Enabling include.searchQueries for ChatGPT is additive; in practice it's usually empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions