Repository navigation
Description
What Drew ordered (2026-11-06 22:48 CST, verbatim substance)
Build the cross-database search surface as a Cloudflare Worker that pulls all databases for search; for each search query it stores a Durable Object, automatically inserts the query as an embedding, and caches the result — for now, indefinitely (no TTL/expiry).
This is the successor surface for the Atlas shard consumer wiring in #5755 (slice 1 merged in #6661; rehomed as fleet serve search in #6674). It supersedes the 2026-11-05 "Ask-the-ledger" direction (Cloudflare AI Search / AutoRAG over R2 snapshots + a query/miss ledger DB): Drew replaced the managed-AI-Search design with this explicit Worker + Durable Object + embedding cache design. The AI Search proposal is not being built; this issue is the record of what replaced it.
Architecture (v1)
Components
- Cloudflare Worker (
pkgs/atlas-search/worker/) — the only public edge. Inbound gate: a shared bearer secret checked in the Worker (constant-time compare); not public-open. (Cloudflare Access in front of the Worker hostname is a follow-up hardening note below.) - Durable Object class
QueryCache— one DO per distinct query. DO name =sha256(normalized_query || config_fingerprint)where the fingerprint pins{ceiling: "personal", model_rev, vec_table, trunc: 0, k}so a cache entry can never be served across different effective ceilings or embedding spaces (the same rule the search service applies to job dedupe). - The fleet search service (
fleet serve search/atlas-search serve, laptop loopback :18760) remains the fan-out engine: it discovers the shard set from the Turso Platform API (onlyatlas-core-*databases), reads each candidate'satlas_manifestself-description (tier, topic, part, expected chunks), enforces per-client tier ceilings, embeds the query with the one shared resident embedder, runs the parallel cosine scan + merge/rerank. The Worker keeps no shard list of its own — new databases join the fan-out by existing in the Turso org with theatlas-core-prefix and a manifest; the Worker inherits the set through the service. - Reachability: the service is exposed to the Worker through the existing
amd-6-pm-stackCloudflare Tunnel asatlas-search.security.cab→localhost:18760, fronted by a Cloudflare Access application whose only policy is a service token the Worker presents (CF-Access-Client-Id/CF-Access-Client-Secret). The tunnel hostname without the service token is rejected by Access before it reaches the laptop.
Miss path (first time a query is seen)
- Worker normalizes the query, computes the DO key, asks the DO for its entry → miss.
- Worker calls the service's new
POST /v1/embed(added by this work to bothserver.rscopies, parity-guarded): the service's shared embedder returns the production query vector. The Worker stores{query, normalized_query, embedding, model, model_rev, dims, created_at}in the DO first — the DO is born holding the query's embedding, per Drew's spec, even if the search below then fails. - Worker calls
POST /v1/search(sync one-shot) with the dedicatedcf-workerservice client (see boundary below) → merged, reranked results. - Worker stores
{result, searched_at, fanout_ms, embed_ms}in the DO and returns the result withcache: "miss"and the timings.
Hit path
- The DO returns the stored result verbatim; the fleet service is never contacted. Response carries
cache: "hit", the originalsearched_at, and ahit_countthe DO increments. This is the proof surface: a hit must be byte-identical to the miss response's result and must not move any counter on the service side.
Retention
- Indefinite. No TTL, no eviction in v1 — Drew's "for now". DO storage is the ledger of every query ever asked through this surface. A future eviction policy (size/LRU) is a deliberate follow-up (filed separately), not a v1 behavior.
Embedding source — decision and why
The fleet embedder (the service's resident ONNX session): model Snowflake/snowflake-arctic-embed-m-v2.0 pinned at rev 95c2741480856aa9666782eb4afe11959938017f, query prompt "query: ", production vector table vec_snowflake_m_v2_768_f32 — 768 dimensions, full width (trunc = 0).
Workers AI is rejected: its 384-dim @cf/baai/bge-small-en-v1.5 lives in a different embedding space (and a different width). Cosine similarity across embedding spaces is meaningless; a Worker-side embedding that cannot be compared against the corpus vectors would silently corrupt every ranking. Any edge embedding must reproduce the corpus's exact space, and the only artifact that does that today is the pinned Snowflake session in the fleet service.
Correction to older notes: several records describe the corpus as "384-dim Snowflake". Production is 768-dim (vec_snowflake_m_v2_768_f32 in the live service config; 384 was a Matryoshka truncation option from the Python era, never the production width).
Secret-tier boundary
- The Worker authenticates to the search service as a dedicated client,
cf-worker, withceiling_cap: "personal"— the service mechanically caps it to the Public + Internal tiers. The Secret tier is unreachable through this client no matter what the Worker asks for. - The Worker holds no Turso credentials and never receives secret-tier shard data, so nothing secret can enter a Durable Object — neither chunk content nor embeddings of secret chunks.
- The
drew-cliclient (secret-bearingcap) stays laptop-local and is not used by anything in this build. Secret-tier search remains a laptop-side-only operation, exactly as today.
What v1 deliberately leaves out
- Filters / FTS interplay — the fan-out runs the service's default hybrid search; classification/date filters and the FTS answer remain atlas shard consumer: classification/date filters and FTS answer for shard fan-out (follow-up of #5755 slice 1) #6665.
- Hydration (
--expand) — results are the service's standard envelope; expansion remains atlas shard consumer: --expand hydration from tier content stores (follow-up of #5755 slice 1) #6664. - Serve-mode snapshot-id integration — remains atlas shard consumer: serve-mode (fleet serve search role) and #5668 snapshot-id integration (follow-up of #5755 slice 1) #6666.
- Eviction policy for the indefinite cache — follow-up issue (Drew: "for now").
- Access in front of the Worker hostname itself — v1 gate is the in-Worker bearer check; recorded as a hardening follow-up.
- The live proof in this issue advances atlas shard consumer: live verification — parity, latency, token minting (follow-up of #5755 slice 1) #6662 only for the
personalceiling path through the Worker; atlas shard consumer: live verification — parity, latency, token minting (follow-up of #5755 slice 1) #6662 stays open for its remaining parity scope.
Open questions (recorded, proceeded on defaults)
- Worker hostname: default
atlas-searchon the account'sworkers.devsubdomain; a custom domain can be bound later without changing the design. - Whether the DO should also store the FTS match expression / branch pools for debugging: default no — result + embedding + provenance only.
Proof required (acceptance)
- Deployed Worker + DO; a real query run twice: first response
cache: "miss"with fan-out executed (service-side evidence), DO created holding a 768-dim embedding; second responsecache: "hit", byte-identical result, served from the DO with no service contact; timings for both; DO state read back through the Worker's gated inspect endpoint.
Activity
developing-today commentedon Nov 7, 2026
CODE-2089
Merge pull request #6800 from developing-today/feat/6788-atlas-search…
developing-today commentedon Nov 7, 2026
Shipped — v1 live and proven (2026-11-06 night)
PR: #6800, merged as
f3cdeca52af2bf1d961d9447ecf278240545df66(merge verified by readback; the user-token bucket was rate-limited, so the merge went through the GitHub App route).What shipped
pkgs/atlas-search/worker/, deployed:https://atlas-search.developing-today.workers.dev(versionb8682c0b-2215-4ade-950f-86ec3bba4047). Routes:GET /health(open),POST /v1/searchandGET /v1/cache/inspect(gate-token bearer, constant-time compare).QueryCache, SQLite-backed): key = sha256(normalized query ‖ ceiling ‖ model rev ‖ vector table ‖ k). Miss path runs entirely inside the DO: the query is embedded and the embedding persisted before the fan-out runs (state machine absent → embedded → complete; a failed search retries the search only), then the result is cached indefinitely. Hits never contact the service.POST /v1/embedadded to bothserver.rscopies under the fleet step 5: search domain joins fleet — gated on #5350 step 6 cutover #5433 parity guard (parity script green). Embed jobs are memory-only — they never enter the jobs ledger.atlas-core-*→atlas_manifest), embeddings, and merge/rerank all stay infleet serve search. The Worker holds no Turso credentials and no shard list — new databases join by existing with the prefix + manifest.cf-workerclient (ceiling_cap: personal⇒ Public+Internal tiers only), and refuses to cache any response whose reportedeffective_ceilingisn'tpersonal. Secret-tier data cannot enter a DO.atlas-search.security.cab→localhost:18760on the existing amd-6-pm-stack tunnel, DNS CNAME created, Cloudflare Access app with a service-token-only policy (public hits get 403 — verified). Secrets vaulted by name in BWS + 1Password Dev:atlas.search-cf-worker-token,atlas.search-worker-gate-token,cloudflare.access-atlas-search-client-id,cloudflare.access-atlas-search-client-secret.Tests (oracles named)
embed_wire_roundtrip), atlas-search 27 (incl. embed route serving the shared embedder's vector), fleet-search--features serve33 lib + 11 contract (incl. embed route). fmt clean.Live proof (2026-11-07T05:20Z, query "how does the fleet queue claim a task", k=3)
05:20:34.839Z.cache: "hit", result byte-identical (verified programmatically), same key.cache: "hit"— normalization works in production.GET /v1/cache/inspect:has_embedding: true, embedding_dims: 768, embedding_valid: true, has_result: true, result_bytes: 16985, hit_count: 2, modelSnowflake/snowflake-arctic-embed-m-v2.0./v1/embedwithout bearer → 401.Deployment caveat (honest state)
The service binary currently serving the laptop's
atlas-search.serviceis the release build of the PR branch, wired via a reversible systemd drop-in (~/.config/systemd/user/atlas-search.service.d/6788-embed-endpoint.conf, withATLAS_ORT_LIBpointed at the nix-closure ONNX Runtime). The code is on main now, so the durable deploy is the normal nix package rebuild — after that lands, the drop-in should be removed. Until then, if the unit is restarted from the stock nix binary,/v1/embeddisappears: cache hits keep working, misses return 502 and cache nothing. Thecf-workerclient was added to~/.local/state/atlas-search/service.json(backup atservice.json.bak-6788).Deliberately out of v1
Open questions recorded in the issue body stand (snapshot distribution, restricted-network shape) — neither blocks v1.