feat: semantic learning network (RAG over our own approved designs) - #8
Open
slmatthiesen wants to merge 1 commit into
Open
feat: semantic learning network (RAG over our own approved designs)#8slmatthiesen wants to merge 1 commit into
slmatthiesen wants to merge 1 commit into
Conversation
Embeds every approved generation + curated run (Voyage, provider-abstracted behind EmbeddingProvider) and uses the corpus three ways on /api/generate: 1. Instant serve (cosine ≥ RETURN): return the nearest design verbatim, deep-linkable, $0, no LLM, no clarify, no daily-cap — a cache hit across SIMILAR prompts, not just identical ones. 2. Semantic grounding (GROUND ≤ cosine < RETURN): inject the nearest designs as exemplars into the generation prompt → faster convergence + consistency. 3. Learning: scripts/backfillEmbeddings.ts embeds approved+curated designs, so coverage compounds as the operator approves more. Fully non-fatal: no key / embed error / corpus miss all degrade to a normal generation — the network only ever helps. Brute-force cosine over a small corpus (no vector-index dep). "Generate fresh instead" (freshOnly) bypasses the instant-serve. New web badge surfaces library-served designs. Tests: +20 (vectorMath, designVectors, retrieve pipeline, instant-serve route). api 304 green, web 74 green, lint clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
A semantic learning network: RAG over our own approved designs so the app gets faster and cheaper as it's used. The corpus = approved generations + curated runs, embedded via Voyage (provider-abstracted behind
EmbeddingProvider).Three uses on
/api/generate, slotted right after the exact-cache miss:SEMANTIC_RETURN_THRESHOLD, default 0.93) — return the nearest design verbatim: deep-linkable, $0, no LLM, no clarify, no daily-cap. A cache hit across similar prompts, not just identical ones. This is the "user asks about notifications → serve our SQS design in milliseconds" behavior.GROUND≤ cosine <RETURN) — inject the nearest designs as exemplars into the generation prompt (viaassembleGrounding), so a fresh gen converges faster, cheaper, and more consistently.scripts/backfillEmbeddings.tsembeds approved + curated designs (idempotent); run it after approving designs and coverage compounds.Safety / design notes
EMBEDDING_PROVIDER=voyagewith no key auto-disables at boot.EmbeddingProvidervia the factory.DesignVectorStore.searchunchanged.freshOnly) bypasses the instant-serve; new web badge surfaces library-served designs.Tests
+20 tests (vector math, vector store, retrieval pipeline incl. non-fatal paths, instant-serve route). api 304 green, web 74 green, lint clean.
Ops
New env in
.env.example:EMBEDDING_PROVIDER,VOYAGE_API_KEY,EMBEDDING_MODEL,SEMANTIC_*thresholds. After deploy: set the key, runbackfillEmbeddings.tsonce to seed the corpus.🤖 Generated with Claude Code