Repository navigation
Closed
Labels
enhancementNew feature or request
Description
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") |
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
enginelabel (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) andrelated_queries(Perplexity) that we drop too.)
Why we don't have it today
All three layers drop it:
- Request —
buildRequestBodyinserver/src/lib/cloro-scraper.jssetsinclude.searchQueries: falsefor the ChatGPT-family task. - Parser —
parseScraperResponse(same file) never readsresult.searchQueries/result.search_model_queries. - Storage —
prompt_resultshas no column for it (onlyresponse,citations,shopping_cards,inline_products, …).
Proposed (capture + store only)
- Migration — add
search_queries jsonb NOT NULL DEFAULT '[]'::jsonbtoprompt_results(numbered migration via the hosted migration workflow; regeneratesupabase/schema.sql). - Request — set
include.searchQueries: truefor the ChatGPT-family task inbuildRequestBody(free; often empty, but harmless). - 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:
[]
- Copilot / ChatGPT:
- Persist — write
search_queriesin theprompt_resultsinsert incloro-result-handler.js(covers both the polling and webhook paths).
Non-goals (separate)
- Product surface / UI → feat(prompts): Query Fan-out tab — observed engine sub-queries with times-searched + one-click track #333.
- LLM-predicted fan-out (generating sub-queries where the engine returns none). Different approach; observed data lands first.
- Category/intent tagging of the sub-queries → belongs to the UI feature (feat(prompts): Query Fan-out tab — observed engine sub-queries with times-searched + one-click track #333), derived at read time.
- The bonus
entities/related_queries/citationPillsfields.
Acceptance criteria
-
prompt_results.search_queriesexists (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
engineis preserved per item. - No new AI/scraper spend — the data comes from the existing Cloro poll/webhook response.
-
serverlint / format / tests pass;supabase/schema.sqlregenerated.
Notes
t.js/ caching: N/A.- Enabling
include.searchQueriesfor ChatGPT is additive; in practice it's usually empty.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
chore(server): structured logging Phase 2 — lib job manager/runner (#336
chore(server): structured logging Phase 2 — server.js + middleware (#337
feat(tracking): capture & store observed query fan-out (Cloro searchQ…
feat(prompts): Query Fan-out tab — observed sub-queries with times-se…