Skip to content

feat: semantic learning network (RAG over our own approved designs) - #8

Open
slmatthiesen wants to merge 1 commit into
mainfrom
feat/semantic-learning-network
Open

feat: semantic learning network (RAG over our own approved designs)#8
slmatthiesen wants to merge 1 commit into
mainfrom
feat/semantic-learning-network

Conversation

@slmatthiesen

Copy link
Copy Markdown
Owner

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:

  1. Instant serve (cosine ≥ 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.
  2. Semantic grounding (GROUND ≤ cosine < RETURN) — inject the nearest designs as exemplars into the generation prompt (via assembleGrounding), so a fresh gen converges faster, cheaper, and more consistently.
  3. Learningscripts/backfillEmbeddings.ts embeds approved + curated designs (idempotent); run it after approving designs and coverage compounds.

Safety / design notes

  • Fully non-fatal: no Voyage key, an embedding error, or a corpus miss all degrade to a normal generation. The network only ever helps — it never blocks a generation. Forker-safe: EMBEDDING_PROVIDER=voyage with no key auto-disables at boot.
  • Provider-abstracted (KTD2 pattern): Gemini / local / etc. drop in behind EmbeddingProvider via the factory.
  • Small-corpus brute-force cosine in JS (sub-ms) — no vector-index dependency; an ANN backend can drop in behind DesignVectorStore.search unchanged.
  • Only approved designs are served (never pending); a hidden design is never instant-served.
  • "Generate fresh instead" (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, run backfillEmbeddings.ts once to seed the corpus.

🤖 Generated with Claude Code

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>
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