Skip to main content

Module embedding

Module embedding 

Source
Expand description

Phase 4.C foundation: pluggable embedder trait + record shape.

This module defines the contract every embedding backend must satisfy and the durable record shape the cortex_store side table stores. It is deliberately a foundation slice (D2-A): no concrete backend implementation lives here, and the existing deterministic lexical + salience retrieval pipeline (Phase 4.B baseline) is not regressed by this slice.

Pluggable backends are identified by Embedder::backend_id, a stable string the (memory_id, backend_id) durable key is composed against. A memory may carry embeddings from multiple backends simultaneously (the deterministic stub coexisting with a real model during a migration window is the canonical use case). The Embedder::dim contract is stable for a given backend_id — changing dimension is a backend version change and MUST be expressed as a new backend_id so old vectors stay readable.

Downstream slices:

  • D2-B (sibling agent) lands the first concrete backend in embedding/local_stub.rs (and any subsequent real model integrations). Re-exported below.
  • D2-C (sibling agent) wires the score composer to consume cosine similarity over EmbedRecord::vector alongside the existing lexical and salience components, gated so the additivity guardrail keeps the lexical + salience baseline from regressing.

Re-exports§

pub use local_stub::LocalStubEmbedder;
pub use local_stub::STUB_BACKEND_ID;
pub use local_stub::STUB_DIM;
pub use ollama::OllamaEmbedder;
pub use ollama::DEFAULT_OLLAMA_EMBED_MODEL;
pub use ollama::DEFAULT_OLLAMA_ENDPOINT;
pub use ollama::NOMIC_EMBED_DIM;
pub use ollama::OLLAMA_BACKEND_ID_PREFIX;

Modules§

local_stub
Deterministic BLAKE3-based stub embedder backend (Phase 4.C / D2-B).
ollama
Ollama-backed embedder (Phase 4.C enrichment layer).

Structs§

EmbedRecord
One persistable embedding row produced by an embedder backend.

Enums§

EmbedError
Errors raised by Embedder backends.

Traits§

Embedder
An embedder produces a deterministic, fixed-length vector from a memory’s claim text + tag context.

Functions§

cosine_similarity
Cosine similarity between two equal-length f32 vectors.

Type Aliases§

EmbedResult
Result type for embedder backends.