Retrieval that
gets smarter

Typed orchestration for self-improving retrieval systems.
Three methods. One feedback loop. Deploy to any edge runtime.

$ deno add jsr:@semantic-loop/core
the entire API
const loop = createLoop({ store: "supabase", embedding: "openai" });

// 1. Seed content — embeddings are generated automatically
await loop.seed([{ content: "Your hook here", tribe: "founders" }]);

// 2. Select the best item for this context
const pick = await loop.select("growth strategies");

// 3. Later: feed back what happened
await loop.ingest(pick.candidate.item.id, "instagram", {
  views: 12400, likes: 340, shares: 89,
});
// Next select() is smarter. Every loop compounds.
// If the item scored well, the breeder generates variations automatically.

One function, any setup

createLoop() wires stores, embeddings, critics, breeders, and tuning from a single declarative config.

Minimal

in-memory, no embeddings
const loop = createLoop({
  store: "memory",
});

Production

supabase + openai embeddings
const loop = createLoop({
  store: "supabase",
  embedding: "openai",
});

With breeding

pool grows from winners
const loop = createLoop({
  store: "supabase",
  embedding: "openai",
  breeder: myLlmBreeder,
  breeding: { scoreThreshold: 0.7 },
});

Tuned

custom weights + decay
const loop = createLoop({
  store: "supabase",
  embedding: "openai",
  selection: {
    epsilon: 0.25,
    weights: {
      similarity: 0.5,
      scoreAvg: 0.3,
      exploration: 0.15,
      freshness: 0.05,
    },
  },
  aggregation: {
    decayFactor: 0.9,
  },
});

One loop. Compounding returns.

Every selection teaches the system. Every outcome sharpens the next pick. The loop never stops learning.

01

Seed

Load content variants with embeddings. Hooks, prompts, copy, templates — anything you want to optimize.

02

Select

Epsilon-greedy algorithm picks the best item, weighted by similarity, past performance, exploration, and freshness.

03

Observe

Real-world signals flow back via webhooks. Views, clicks, shares, ratings, conversions — any metric you track.

04

Critique

A critic scores the content. Start with keyword heuristics. Graduate to LLM-as-judge. Compose multiple critics.

05

Update

Decay-weighted aggregation updates running scores. Recent performance matters more than ancient history.

06

Breed & Loop

When items cross a score threshold, the breeder generates variations. New candidates enter the pool. The loop compounds and expands.

What you can build

Each is a single edge function backed by one Supabase table. What used to need a data team is now a weekend project.

Hook Optimizer

Seed 50 content hooks per audience tribe. Platform webhooks feed engagement signals. The loop surfaces which hooks land and retires the ones that don't.

attention economy

Prompt Loop

Register prompt variants per task type. Measure success rate, latency, user rating. Best prompt is selected per context, automatically.

agent economy

Copy Variants

Landing page headlines, CTAs, email subjects. Track clicks and conversions. The loop converges on what converts, even with low traffic.

conversion economy

Taste Engine

Personal recommendations for books, tools, restaurants, music. Accept/reject/rate signals shape a taste profile that sharpens over time.

discovery economy

Smart Feed

Self-curating content feeds for newsletters, communities, or learning paths. Click and read-time signals rank what surfaces next.

discovery economy

Adaptive Templates

Proposals, outreach emails, meeting agendas. Track win/loss and completion rates. Templates evolve toward what works for each segment.

process economy

Everything is an interface

Swap any part. The core defines contracts. Adapters implement them.

MemoryStore

Where items and scores live. Ship with InMemoryStore for testing, SupabaseRpcStore for production. Build your own.

EmbeddingProvider

How text becomes vectors. OpenAIEmbedding for production, NoopEmbedding for testing. Single and batch embed.

Critic

How content is judged. HeuristicCritic uses keywords. LlmCritic uses Claude or GPT as judge. Compose with MultiSignalCritic.

Telemetry

Observe the loop itself. NoopTelemetry by default. Plug in OpenTelemetry, Datadog, or any tracing provider.

Breeder

How the pool grows. NoopBreeder by default (static pool). Plug in an LLM breeder to generate variations from winners.

Built for humans and agents

AI coding assistants can discover and use this library natively.

/llms.txt

Machine-readable project index. Every AI assistant can understand what this library does and how to use it.

Context7

Indexed on Context7 for real-time doc retrieval. Agents get version-specific API docs injected into their context.

Typed everything

Full TypeScript types with JSDoc. Agents generate correct code on the first try because the type surface is explicit.

Start building

Everything you need to go from zero to a self-improving system.

Every doc page has three modes: Vibe Coder (just code), Beginner (explain everything), and Advanced (internals & tradeoffs).