Skip to content

feat: neural EmbeddingProvider — llama embedding FFI + backend + adapter + async trait (#11) - #1657

Merged
joelteply merged 4 commits into
canaryfrom
feat/persona-neural-embedder
Jun 20, 2026
Merged

joelteply merged 4 commits into
canaryfrom
feat/persona-neural-embedder

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Finishes #11 — the neural embedder, end to end:

  • llama embedding FFI: ContextParams embedding mode + pooling + Context::embed (pooled, L2-normalized, fail-loud)
  • LlamaCppBackend::embed — dedicated embedding-mode context, KV-cleared per text
  • LlamaCppAdapter::create_embedding — async → spawn_blocking → backend; supports_embeddings: true
  • EmbeddingProvider made async; NeuralEmbeddingProvider behind it (loads canonical Qwen3-Embedding-0.6B, id() = model slug, transport-invisible cache key), wrapped in the content-addressed shared cache (compute-once-per-content, GPU forward pass on the fast path)
  • RecallFaculty pre-embeds query+candidates async, blends, sorts

Compiles clean (--features metal,accelerate); embedding(8)+recall(7)+workspace(9)+persona_workspace(3) tests green on the lexical path.

Remaining (model-gated, follow-up): swap NeuralEmbeddingProvider in behind the cache when Qwen3-Embedding-0.6B is on disk + the #[ignore] real-model semantic-recall test.

NOTE: touches recall_faculty.rs contribute, which PR #1656 (relevance_weight tunable) also touches. Land #1656 first; this needs a trivial rebase to fold the relevance_weight field into the async re-rank loop (the const RELEVANCE_WEIGHT here becomes self.relevance_weight). I'll handle the reconcile.

joelteply and others added 4 commits June 19, 2026 20:19
…embed (#11 slice 1)

The core/llama crate had n_embd() but no embedding extraction. Added (bindgen
already allowlists llama_.*, so the raw FFI was bound — this is the safe wrapper):

- ContextParams.embeddings (bool) + pooling_type (PoolingType: None/Mean/Cls/Last
  → llama_pooling_type_*). Wired into new_context.
- Context::embed(tokens) -> Result<Vec<f32>>: decode as seq 0 → llama_get_
  embeddings_seq → pooled vector, L2-normalized (so cosine = dot). Fails LOUD on
  null (context not in embedding mode) or degenerate (zero/non-finite) — never a
  silent short vector into recall.

Compile-validated (cargo check -p llama --features metal, clean). This is the GPU
path for embedding generation (llama.cpp Metal/CUDA — per the high-volume→GPU
rule). Next #11 slices: backend embed() → LlamaCppAdapter::create_embedding →
NeuralEmbeddingProvider (behind the EmbeddingProvider trait + the shared cache) →
persist vectors. Neural runtime validation needs Qwen3-Embedding-0.6B on disk
(the locked canonical grid embedder) — an #[ignore] real-model test, follow-up.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ntext (#11 slice 2)

embed(texts) -> Vec<Vec<f32>> builds a separate EMBEDDING-mode context
(embeddings: true, last-token pooling for Qwen3-Embedding), tokenizes + calls
Context::embed per text, clearing the KV between so each pooled vector is
independent. The generation scheduler's context is embeddings:false and can't
embed — hence a dedicated context. Model-agnostic plumbing; the loaded model
should be the canonical Qwen3-Embedding-0.6B for grid-comparable vectors
(NeuralEmbeddingProvider loads it — next slice).

The two existing generation-context sites get embeddings:false + pooling None
(no behaviour change). cargo check -p continuum-core --features metal,accelerate
clean. Runtime validation = an #[ignore] real-model test once the embedding GGUF
is on disk.

Next #11 slices: LlamaCppAdapter::create_embedding (async, calls backend.embed via
spawn_blocking) → NeuralEmbeddingProvider behind the EmbeddingProvider trait (needs
the trait made async for the neural query path) + the content-addressed cache.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Overrides the AIProviderAdapter default (which errored "does not support
embeddings"). Maps EmbeddingRequest.input (Single/Multiple) → texts → backend.embed
on spawn_blocking (the blocking forward pass runs off the async executor, same
bridge as generate_text) → EmbeddingResponse. supports_embeddings flipped to true.

The loaded model determines the vector space — for grid-comparable vectors the
adapter must have loaded the canonical Qwen3-Embedding-0.6B; NeuralEmbeddingProvider
(slice 4) loads it. cargo check -p continuum-core --features metal,accelerate clean.

The adapter-level embedding path is now end-to-end: EmbeddingRequest → embedding-
mode context → pooled L2-normalized vector → EmbeddingResponse. Remaining #11:
NeuralEmbeddingProvider behind the EmbeddingProvider trait (needs the trait made
async for the recall query path) + persist vectors + the #[ignore] real-model test
(gated on Qwen3-Embedding-0.6B on disk).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…finishes #11

Made EmbeddingProvider::embed async (neural/grid embed is inherently IO — a GPU
forward pass or a cross-grid round-trip). The content-addressed cache keeps the
hot path a sync map hit, so the async cost is paid once per unique content.

- EmbeddingProvider trait + LexicalEmbedder + CachingEmbeddingProvider →
  async_trait; cache hit returns sync, miss awaits inner.embed.
- NeuralEmbeddingProvider: wraps an AIProviderAdapter loaded with the canonical
  Qwen3-Embedding-0.6B; embed() calls create_embedding (→ backend.embed → the
  llama embedding FFI = GPU forward pass). id() = the model slug (cache-key /
  vector-space identity; transport-invisible). Degrades to no-signal (empty →
  cosine 0) on failure, logged loud — never junk vectors into recall.
- RecallFaculty.contribute: pre-embeds query + candidates in an async loop (can't
  .await in a sort comparator), then sorts; blend() takes precomputed rel.
- Tests → async (#[tokio::test] + .await); CountingEmbedder async.

The full embedding chain now exists end-to-end: NeuralEmbeddingProvider →
create_embedding → backend.embed → embedding-mode Context → pooled L2-normalized
vector → shared cache → recall re-rank. Compiles clean; embedding(8)+recall(7)+
workspace(9)+persona_workspace(3) green on the lexical path. Remaining: swap
Neural in behind the cache when Qwen3-Embedding-0.6B is on disk + the #[ignore]
real-model semantic-recall test (model-gated). #11 code-complete.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply force-pushed the feat/persona-neural-embedder branch from 65e3c8d to 76b7617 Compare June 20, 2026 01:23
@joelteply
joelteply merged commit 1ceb01e into canary Jun 20, 2026
4 checks passed
@joelteply
joelteply deleted the feat/persona-neural-embedder branch June 20, 2026 01:30
joelteply added a commit that referenced this pull request Nov 4, 2026
…ain window excludes its commit, Shown reads a one-digit-off UUID (card 484b000b) (#5776)

The range is exactly three airc PRs:
- #1655 (card 0dc9af03): addressed admission reads trust through one held handle, a
  primary-key seek per frame (the daemon had opened ~24 SQLite connections/s on the IntelMac).
- #1656 (card e3077c20): the drain window is sized by its statements' work, not the commit's
  fixed sync (Windows CI compaction drain went from >120 s to an airc-store suite of 40.98 s).
- #1657 (airc slice of card 484b000b): Shown reads a UUID one hex digit off by its leading
  short form, against the caller's candidates only.

All three are additive to the APIs continuum uses (TrustStore and peer_trust are new; the
free airc_trust functions and Shown's existing forms are unchanged). Cargo.lock changes only
the 15 rev lines; no dependency is added or removed.


Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant