Skip to content

Per-engine queries like the Ask API; drop Google site lanes - #13

Merged
fatwang2 merged 3 commits into
mainfrom
clairic-query
Oct 21, 2026
Merged

fatwang2 merged 3 commits into
mainfrom
clairic-query

Conversation

@fatwang2

@fatwang2 fatwang2 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

What changes

The query logic now matches Search1API's Ask API as merged in search1api-monorepo PR #363 (apps/ask/src/spans.ts, extract.ts, pipeline.ts).

  • A query for each engine (src/lib/spans.ts, ported from Ask): Jev picks one coherent span of the request per engine with a single choice over every word-boundary span. The port keeps Ask's NOTES, SCOPE_NAMES, mentionsScope, wordSpans, the 255-candidate cap and engines grouped by note. selectSpans(…, only) keeps context.sources as every routed source, and the choice state and instructions are copied verbatim. A provider error, a refusal or a choice outside the candidates leaves that engine to fall back.

  • Clairic for keyword engines (src/lib/extract.ts, same fields and APPLIED text as Ask): one Workers AI call extracts hackernews, reddit and github alongside Jev's intent judgment, with a 1.5s timeout. A missing binding, timeout, error or blank field sends that engine to the Jev span choice instead.

  • Orchestration as in Ask:

    1. The intent judgment and Clairic start together.
    2. selectSpans for the non-Clairic engines runs while Clairic finishes.
    3. selectSpans runs again for any Clairic engine that came back empty.

    If an engine still has no query, it falls back to the intent judgment's pick from the keyword candidates (the entity pick for sources flagged entityQuery, none, as in Ask), and finally to the request as typed. src/lib/candidates.ts and the intent's query/entity choices are restored, identical to Ask's candidates.ts and decisions.ts.

  • Intent event: adds queries (each chosen source's query) and queryFrom (clairic | jev | intent | request). query is the first source's query, used for the "Looking for" line. The working panel names a source's own query when it differs, e.g. Reddit for “FastAPI production performance experiences”. queryExtracted is gone.

  • No Google site lanes: Hacker News, Reddit and GitHub search only their own engines, because the search service already does that inside its own engines. Removed Lane.site and includeSites/excludeSites, which no longer go in the request body. The cache key moves to v3. One lane per source, so found by N engines now only appears when different sources return the same URL.

  • Google speculation stays removed.

  • Workers AI Jev fix: typesafe/jev now answers through the binding as { state: 'Completed', result: {…} }, which left the cloudflare provider with empty answers for intent, spans and relevance (also on main). callCloudflare now reads either shape. Clef answers unwrapped, and Clairic is unaffected.

  • README, wrangler.jsonc and changelog 0011 describe the per-engine queries.

Differences from Ask

The query logic now matches Ask's: the same fields, notes, instructions and order, and the same fallback chain (Clairic or Jev span → intent pick → request as typed). What remains different:

  • Speculative Google: removed here, and Ask is removing it too.
  • queryFrom in the intent event is jev-search only. It reports request when the intent pick is the request itself.
  • Clairic wait: jev-search also stops waiting at the 1.5s timeout if the binding ignores the abort signal. Ask relies on the signal alone.
  • Intent event timing: the event is sent once every engine has its query, so the source chips appear later than on main.

Evaluation basis

search1api-monorepo apps/ask/eval/query-clairic-results.md: 102 live requests, two runs, Jev relevance on the top 8. The per-engine Jev span choice did as well as or better than Clairic on web engines, Wikipedia, YouTube and IMDb. Clairic gained on GitHub (4.9 vs 3.3 in both runs), and on Hacker News and Reddit by about 1. X did not repeat its gain, so it stays on Jev. The previous version of this PR sent one Clairic query to every engine; that has been replaced.

Testing

  • pnpm test: 21 files, 195 tests pass. New spans.test.ts and extract.test.ts are ported from Ask; candidates.test.ts is restored and identical to Ask's. Pipeline tests cover:
    • Clairic, then a Jev span, then the intent pick, then the request as typed, per engine.
    • Applied engines and scope-free candidates in every span call.
    • Keyword engines falling back to Jev when Clairic fails or there is no binding.
    • Span failure falling back to the intent query pick, and to the typed request when there is no pick.
    • One engine per source, with no include_sites.
  • pnpm typecheck and pnpm build pass.
  • Span choice on each provider (live, 133- and 255-candidate requests):
    • typesafe, vercel and openai work.
    • clef and clef-flash work (via REST).
    • cloudflare works through the real binding after the unwrap fix (local dev, JEV_PROVIDERS=cloudflare).
  • Local dev, this branch on :3030 against origin/main on :3031, same requests at the same time:
Request Engine: this branch (origin) main
On GitHub find FastAPI JWT authentication examples; on Reddit find FastAPI production performance experiences. github FastAPI JWT authentication examples (clairic) 8/8; reddit FastAPI production performance experiences (clairic) 4/8 both: FastAPI JWT authentication examples; find FastAPI production performance experiences; github engine 0/8
GitHub에서 Docker 없이 Windows에서 실행되는 OCR 프로젝트를 찾아줘 github OCR (clairic) 6/8 full sentence; github engine 0/0
who directed the movie Past Lives web directed the movie Past Lives (jev); wikipedia, imdb Past Lives (jev); wikipedia 4/8 who directed the movie Past Lives, imdb Past Lives; wikipedia 2/8
what does HN think of Zig async I/O redesign hackernews Zig async I/O redesign (clairic) 5/8 HN think Zig async I/O redesign; hackernews 4/8
reddit opinions on Arc browser alternatives reddit Arc browser alternatives (clairic) 7/8 reddit opinions Arc browser alternatives; reddit 6/8

Counts are on-topic / returned for that engine's lane.

  • Latency: understanding now takes a serial span step after the intent judgment. On the second, cache-hit round, which isolates that step, the time to the intent event was 0.70 to 0.97s on this branch against 0.27 to 0.55s on main. First results therefore arrive about 0.4 to 0.6s later in local dev; production latency is to be confirmed after deploy. Total time was often shorter because there are fewer lanes. On a cold first round, main's Google site lanes sometimes produced the first row sooner than Reddit's native engine (about 3.0s vs 4.8s).

🤖 Generated with Claude Code

Jev now answers only window and sources; Cloudflare's Clairic extracts one
query from the request's own words in parallel, and every engine receives
it. The regex candidates, the IMDb entity query and the speculative Google
call are removed. Without the AI binding, or when Clairic fails, takes over
1.2s or finds nothing, the request is sent as typed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
jev-search 4cf548d Commit Preview URL

Branch Preview URL
Oct 21 2026, 06:48 PM

Each chosen engine now gets its own span of the request, the same
selection as Search1API's Ask API (monorepo PR #363): Clairic extracts
the Hacker News, Reddit and GitHub queries alongside the intent judgment,
Jev picks a span for every other engine and for any keyword engine
Clairic leaves empty, and the request as typed is the last fallback. The
intent event carries `queries` and `queryFrom` per source.

Hacker News, Reddit and GitHub search only their own engines; the Google
site-restricted lanes and the include/exclude site parameters are gone.

Workers AI's typesafe/jev now answers through the binding wrapped in
`{ state, result }`; read either shape so the cloudflare provider works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fatwang2 fatwang2 changed the title Extract the engine query with Clairic Per-engine queries like the Ask API; drop Google site lanes Oct 21, 2026
Restore the keyword candidates and the intent judgment's query/entity
choices (identical to search1api-monorepo apps/ask candidates.ts and
decisions.ts). Each engine's query is now Clairic or a Jev span, then the
intent pick (the entity pick for sources flagged `entityQuery`, none, as in
Ask), then the request as typed; `queryFrom` gains 'intent'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fatwang2
fatwang2 merged commit 1bfe835 into main Oct 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant