Repository navigation
DQ1: the doc search on Workers and Supabase - #2
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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