Skip to content

DQ1: the doc search on Workers and Supabase - #2

Merged
pullely merged 1 commit into
mainfrom
orun/DQ-2-the-doc-search-on-workers-and-supabase
Oct 28, 2026
Merged

pullely merged 1 commit into
mainfrom
orun/DQ-2-the-doc-search-on-workers-and-supabase

Conversation

@pullely

@pullely pullely commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

The template in apps/web on Next.js 16.3.8, the page on the Pages Router with upstream's UI pins and the search an App Router route handler (an edge-runtime route does not run under OpenNext), built by @opennextjs/cloudflare into one Worker with Static Assets. app/api/vector-search/route.ts keeps upstream's steps, counts and prompt: moderation (only when the answer is OpenAI's), the question embedded, match_page_sections over the HYPERDRIVE binding with a postgres client per call, a 1500-token context, the answer streamed as plain text with AI SDK 5 to the dialog's useCompletion. lib/ai/models.ts: Workers AI's bge-base-en-v1.5 (768 dimensions) for every embedding and Llama 4 Scout for the answer through the AI binding; OPENAI_API_KEY, a Worker secret, switches only the answer to OpenAI's model straight from OpenAI — no gateway. Upstream's build-time embedding, which held OPENAI_KEY and the service-role key, is split: scripts/build-docs-index.ts runs upstream's MDX processing (lib/docs/process-mdx.ts) into the committed lib/docs/index.generated.json with no credential, and POST /api/embeddings (lib/docs/sync.ts) embeds every page whose checksum the database does not hold, one transaction per page under an advisory lock, the checksum set last; ?refresh=1 is upstream's --refresh. The web smoke POSTs it and requires /api/health to report sections, so every deploy indexes what changed. An empty index answers 200 and says so. packages/db: upstream's migration verbatim (010), the column at vector(768) with a cosine match returning token counts behind a guard against another model's vectors (020), both functions revoked from the Data API's roles (030), applied by infra/db-migrate after the infra/terraform/supabase project and the infra/terraform/cloudflare-hyperdrive config exist. lib/site.ts is the name seam (SITE_NAME, the page title) and the source link. tests/web (the models on Workers AI through the real provider and on OpenAI, the sync's skip, refresh, roll-back and lock, the routes over PGlite with pgvector, the empty index, the docs index's freshness, the name and the Worker's config) and tests/db (the manifest, the schema at 768, the cosine match, row-level security and the revoke, the guard, on PGlite). typecheck, lint, test and build are green; the Worker is 1.80 MiB gzipped.

🤖 Generated with Claude Code

The template in apps/web on Next.js 16.3.8, the page on the Pages Router with upstream's UI pins and the search an App Router route handler (an edge-runtime route does not run under OpenNext), built by @opennextjs/cloudflare into one Worker with Static Assets. app/api/vector-search/route.ts keeps upstream's steps, counts and prompt: moderation (only when the answer is OpenAI's), the question embedded, match_page_sections over the HYPERDRIVE binding with a postgres client per call, a 1500-token context, the answer streamed as plain text with AI SDK 5 to the dialog's useCompletion. lib/ai/models.ts: Workers AI's bge-base-en-v1.5 (768 dimensions) for every embedding and Llama 4 Scout for the answer through the AI binding; OPENAI_API_KEY, a Worker secret, switches only the answer to OpenAI's model straight from OpenAI — no gateway. Upstream's build-time embedding, which held OPENAI_KEY and the service-role key, is split: scripts/build-docs-index.ts runs upstream's MDX processing (lib/docs/process-mdx.ts) into the committed lib/docs/index.generated.json with no credential, and POST /api/embeddings (lib/docs/sync.ts) embeds every page whose checksum the database does not hold, one transaction per page under an advisory lock, the checksum set last; ?refresh=1 is upstream's --refresh. The web smoke POSTs it and requires /api/health to report sections, so every deploy indexes what changed. An empty index answers 200 and says so. packages/db: upstream's migration verbatim (010), the column at vector(768) with a cosine match returning token counts behind a guard against another model's vectors (020), both functions revoked from the Data API's roles (030), applied by infra/db-migrate after the infra/terraform/supabase project and the infra/terraform/cloudflare-hyperdrive config exist. lib/site.ts is the name seam (SITE_NAME, the page title) and the source link. tests/web (the models on Workers AI through the real provider and on OpenAI, the sync's skip, refresh, roll-back and lock, the routes over PGlite with pgvector, the empty index, the docs index's freshness, the name and the Worker's config) and tests/db (the manifest, the schema at 768, the cosine match, row-level security and the revoke, the guard, on PGlite). typecheck, lint, test and build are green; the Worker is 1.80 MiB gzipped.

Co-Authored-By: Claude <noreply@anthropic.com>
Orun-Task: DQ-2
@pullely
pullely merged commit 38d6bf8 into main Oct 28, 2026
2 checks passed
@pullely
pullely deleted the orun/DQ-2-the-doc-search-on-workers-and-supabase branch October 28, 2026 18:36
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.

2 participants