Files
substrata/scripts/db/012-ask-timing.sql
T
CatoandClaude Opus 5.5 76e7a7675e perf(ask): plan the obvious lookups before the model, one call for page questions (#98)
Measured live 2026-09-25 on the three questions George's report named: first
text 9.0-33.0 s, done 18.7-34.4 s, all served by 10 s OpenRouter links.

- lib/chat-agent/plan.ts: lookups the page and the question's words make
  obvious (listed_exposure, recent_leads, trace_dependencies, named records)
  run locally in parallel before the first model call. When the plan found the
  record AND the ask, the model gets no tools: one call. Page questions are
  capped at two model calls; the web is never pre-fetched.
- listed_exposure tool + listing on get_company: tickers with the listed /
  parent / private status in words (Hitachi Energy -> parent Hitachi 6501 JP).
- 【/path】 and similar training-format markers become markdown links.
- ai-kit 1.14.0: light reasoning on Groq gpt-oss, rolling-window cooldowns,
  per-model daily refusals (bitbaum/ai-kit#71).
- research_ask_timing (012) + /data#ask-latency: p50/p90 over the last day,
  no question text stored; journal line 'substrata ask-timing'.
- test/ask-plan.test.ts: the three measured questions take one model call; any
  page question at most two, even against a model that always wants more.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 17:40:18 -07:00

24 lines
943 B
PL/PgSQL

BEGIN;
-- How long Ask kept a reader waiting, one row per question. No question text,
-- no reader, no IP: only durations, the number of model calls, how many
-- lookups were planned before them, which link served, and how many links
-- refused on the way. /data shows p50/p90 over the last 24 hours
-- (lib/ask-timing.ts). Rows older than 30 days are pruned on insert.
CREATE TABLE IF NOT EXISTS research_ask_timing (
at timestamptz NOT NULL DEFAULT now(),
outcome text NOT NULL,
first_ms integer,
total_ms integer NOT NULL,
model_calls smallint NOT NULL DEFAULT 0,
planned smallint NOT NULL DEFAULT 0,
fallbacks smallint NOT NULL DEFAULT 0,
model text
);
CREATE INDEX IF NOT EXISTS research_ask_timing_at ON research_ask_timing (at);
COMMENT ON TABLE research_ask_timing IS 'Ask latency per question (no question text, no reader): first-text and total ms, model calls, planned lookups, serving link, fallbacks.';
COMMIT;