The Phase-0 CI was red on all three runtimes: `src/embeddings/wasm/pkg/` (the
wasm-pack output the dynamic `import('./pkg/candle_embeddings.js')` resolves) was
gitignored + untracked, so tsc failed to resolve it on a fresh clone (TS2307), and
the Bun job ran test:bun without building dist first.
Fixes:
- Track the 3.1 MB prebuilt pkg (candle_embeddings.js/.d.ts + _bg.wasm/.d.ts). It
ships in the npm tarball anyway; versioning it lets consumers + CI build without
a Rust/wasm-pack toolchain and makes the shipped artifact reproducible (closes
the "publish ships whatever the maintainer last built" supply-chain gap). The
top-level .gitignore intended this (`!*.wasm` etc.) but excluded the whole dir,
so the re-includes were dead, and a nested wasm-pack `.gitignore *` also masked
it — force-added past both.
- CI Bun job: `npm run build` before `test:bun` (it imports the built dist/).
Verified against a tracked-files-only tree (fresh-clone sim): typecheck 0, build 0,
test:bun 8/8.
100 lines
3.6 KiB
TypeScript
100 lines
3.6 KiB
TypeScript
/* tslint:disable */
|
|
/* eslint-disable */
|
|
|
|
/**
|
|
* WASM-compatible embedding engine
|
|
*/
|
|
export class EmbeddingEngine {
|
|
free(): void;
|
|
[Symbol.dispose](): void;
|
|
/**
|
|
* Get the embedding dimension (384 for all-MiniLM-L6-v2)
|
|
*/
|
|
dimension(): number;
|
|
/**
|
|
* Generate embedding for a single text
|
|
*
|
|
* Returns a Float32Array of 384 dimensions
|
|
*/
|
|
embed(text: string): Float32Array;
|
|
/**
|
|
* Generate embeddings for multiple texts
|
|
*
|
|
* Takes a JavaScript Array of strings
|
|
* Returns a JavaScript Array of Float32Array
|
|
*/
|
|
embed_batch(texts: Array<any>): Array<any>;
|
|
/**
|
|
* Check if the engine is ready for inference
|
|
*/
|
|
is_ready(): boolean;
|
|
/**
|
|
* Load the model and tokenizer from bytes
|
|
*
|
|
* This is now the ONLY way to initialize the engine.
|
|
* Model weights are no longer embedded in WASM for faster initialization.
|
|
*
|
|
* # Arguments
|
|
* * `model_bytes` - SafeTensors format model weights
|
|
* * `tokenizer_bytes` - tokenizer.json contents
|
|
* * `config_bytes` - config.json contents
|
|
*/
|
|
load(model_bytes: Uint8Array, tokenizer_bytes: Uint8Array, config_bytes: Uint8Array): void;
|
|
/**
|
|
* Get the maximum sequence length
|
|
*/
|
|
max_sequence_length(): number;
|
|
/**
|
|
* Create a new embedding engine instance (not loaded)
|
|
*/
|
|
constructor();
|
|
}
|
|
|
|
/**
|
|
* Calculate cosine similarity between two embeddings
|
|
*/
|
|
export function cosine_similarity(a: Float32Array, b: Float32Array): number;
|
|
|
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
|
|
export interface InitOutput {
|
|
readonly memory: WebAssembly.Memory;
|
|
readonly __wbg_embeddingengine_free: (a: number, b: number) => void;
|
|
readonly cosine_similarity: (a: number, b: number, c: number, d: number) => number;
|
|
readonly embeddingengine_dimension: (a: number) => number;
|
|
readonly embeddingengine_embed: (a: number, b: number, c: number) => [number, number, number];
|
|
readonly embeddingengine_embed_batch: (a: number, b: any) => [number, number, number];
|
|
readonly embeddingengine_is_ready: (a: number) => number;
|
|
readonly embeddingengine_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
readonly embeddingengine_max_sequence_length: (a: number) => number;
|
|
readonly embeddingengine_new: () => number;
|
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
readonly __externref_table_alloc: () => number;
|
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
readonly __wbindgen_start: () => void;
|
|
}
|
|
|
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
|
|
/**
|
|
* Instantiates the given `module`, which can either be bytes or
|
|
* a precompiled `WebAssembly.Module`.
|
|
*
|
|
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
*
|
|
* @returns {InitOutput}
|
|
*/
|
|
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
|
|
/**
|
|
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
*
|
|
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
*
|
|
* @returns {Promise<InitOutput>}
|
|
*/
|
|
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|