/** * Local embedding provider using @huggingface/transformers (transformers.js v4). * * Implements the EmbeddingProvider interface for brain memory vector search. * Uses all-MiniLM-L6-v2 (22MB, 384 dimensions) — matches the brain_embeddings * vec0 table schema. The model loads from the transformers cache, and is * downloaded only when `brain.embedding.allowModelDownload` is true (T13716). * * @epic T134 * @task T136 * @why Ship vector search out-of-the-box without external API keys * @what Local embedding provider using @huggingface/transformers all-MiniLM-L6-v2 * @remarks Brain embeddings are a FIRST-CLASS CLEO feature — the transformers * package is a regular dependency of `@cleocode/core`, not optional. * Migrated from `@xenova/transformers` v2 to `@huggingface/transformers` * v4 (upstream rename, same author) which drops the deprecated * `prebuild-install` transitive via `sharp@0.34+`. */ import type { EmbeddingProvider } from './brain-embedding.js'; /** * How a user opts into the one-time model download (T13716). * * @task T13716 */ export declare const ENABLE_MODEL_DOWNLOAD_HINT = "cleo config set brain.embedding.allowModelDownload true --type boolean --scope global"; /** * Import transformers.js with hub access gated on the opt-in (T13716). * * The one gate for every CLEO model load (this embedding model and the * transcript extractor's text-generation model). transformers.js 4.0.1 still * fetches config and tokenizer metadata from the hub under `local_files_only`, * so the gate sets the process-global `env.allowRemoteModels` from * `brain.embedding.allowModelDownload` before every load: one rule, one value, * so concurrent loads cannot disagree and nothing needs restoring. * * @returns The transformers module and whether downloads are allowed. * @task T13716 */ export declare function importGatedTransformers(): Promise<{ transformers: typeof import('@huggingface/transformers'); allowDownload: boolean; }>; /** * Has the pipeline actually been loaded in this process? * * Distinct from {@link LocalEmbeddingProvider.isAvailable}, which reports * CAPABILITY. This reports STATE, and exists for diagnostics — notably to warn * when `brain.embedding.enabled` is true but nothing was ever embedded. * * @returns `true` once a real embedding pipeline exists. * * @task T12129 (gh#1217) */ export declare function isEmbeddingPipelineLoaded(): boolean; /** * Reset the module-level pipeline state. Test-only. * * @internal * @task T12129 (gh#1217) */ export declare function __resetLocalEmbeddingStateForTests(): void; /** * Override the weights hash a load must match. Test-only. * * @param sha256 - Expected hex sha256 of `onnx/model.onnx`. * @internal * @task T13740 */ export declare function __setExpectedModelSha256ForTests(sha256: string): void; /** * Local embedding provider backed by @huggingface/transformers. * * Produces 384-dimension Float32Array vectors compatible with the * brain_embeddings vec0 table. The model loads from the local cache; it is * downloaded only when `brain.embedding.allowModelDownload` is true (T13716). * * Use {@link initDefaultProvider} (in brain-embedding.ts) to register an * instance when brain.embedding.enabled=true and * brain.embedding.provider='local'. */ export declare class LocalEmbeddingProvider implements EmbeddingProvider { /** Number of dimensions produced — must match brain_embeddings vec0 table. */ readonly dimensions = 384; /** Model tag stored beside every vector this provider produces (T13740). */ readonly model: string; /** * Whether this provider CAN produce embeddings — not whether it already has. * * ## The deadlock this fixes (gh#1217) * * This previously returned `_ready`, the "pipeline has loaded" flag. But * `_ready` is set only by `loadPipeline()`, which runs only inside * {@link embed} — and every caller of `embed` first checks `isAvailable()`. * In any fresh CLI process `_ready` is false, so nothing ever called * `embed`, so `_ready` never became true. **The readiness check could only * be satisfied by the call it guarded.** * * The observable result was total, silent inertness: `cleo brain * maintenance` reported `{processed: 0, skipped: 0, errors: 0}` forever, * `brain_embeddings` stayed empty after dozens of observations, new writes * were never embedded, and every hybrid search quietly degraded to FTS5 — * while `brain.embedding.enabled` was true and the provider itself was * perfectly healthy when called directly. * * Availability is therefore capability: this provider can load its pipeline * on demand, and says so until a load actually fails. The ~22 MB first-call * download is the expected cost of the lazy design, not a reason to refuse * to begin. * * @returns `true` unless loading the pipeline has already failed here. * * @task T12129 (gh#1217) */ isAvailable(): boolean; /** * Convert a single text string into a 384-dimension float vector. * Loads the model on first call (downloading it only on opt-in, T13716). * * @param text - The text to embed. * @returns A Float32Array of length 384. */ embed(text: string): Promise; /** * Embed multiple texts in sequence, reusing the cached pipeline. * * @param texts - Array of text strings to embed. * @returns Array of Float32Array vectors, one per input text. */ embedBatch(texts: string[]): Promise; } /** * Get or create the shared LocalEmbeddingProvider singleton. * * @returns The shared LocalEmbeddingProvider instance. */ export declare function getLocalEmbeddingProvider(): LocalEmbeddingProvider; //# sourceMappingURL=embedding-local.d.ts.map