feature-extraction · sentence-similarity · Chinese · WASM q8 · 24.45 MB

BGE Small ZH v1.5 — 24 MB Chinese 512-d CLS Embedding Workbench

Run BAAI/bge-small-zh-v1.5 (ONNX: Xenova/bge-small-zh-v1.5, MIT, ~24M params) locally in your browser via CPU WASM q8. A compact 4-layer Chinese BertModel mapping Simplified & Traditional Chinese passages to 512-d L2-normalized CLS vectors with zero server calls.

At a glance

Upstream & ONNX BAAI/bge-small-zh-v1.5 → Xenova/bge-small-zh-v1.5
Task / pipeline feature-extraction (HF tag: sentence-similarity · pooling: "cls", normalize: true)
Architecture BertModel · ~24M params · 4 layers · 8 heads · hidden_size: 512 · 2,048 FFN · 512 max tokens · 21,128 WordPiece vocab (do_lower_case: false)
Canonical query instruction Queries prepend "为这个句子生成表示以用于检索相关文章:" for retrieval; passages remain unprefixed
Quantization & size q8 WASM ONNX (onnx/model_quantized.onnx = 24,010,842 bytes = 24.01 MB + 0.44 MB tokenizer/config = 24.45 MB)
Backend CPU WebAssembly (wasm) via shared lib/webai.js (@huggingface/transformers@3.7.5 — no WebGPU required)
License & browser APIs MIT · Web Workers, WebAssembly, Cache Storage, Canvas 2D (Baseline Widely Available)
CLS pooling + compact 512-d geometry: Per 1_Pooling/config.json (pooling_mode_cls_token: true), BGE Small ZH v1.5 extracts token 0 ([CLS], ID 101) from its 4-layer Chinese BERT encoder and L2-normalizes to 512 unit floats (2,048 B FP32 / 512 B INT8 per doc). Toggle the canonical retrieval instruction below to observe how asymmetric query framing affects cosine separation.

1. Client-Side Chinese Retrieval & 2D PCA Workbench

    2. See inside: 2D PCA Constellation & 512-d CLS Vector

    2D PCA Semantic Constellation

    Run inference above to project passages and query into 2D PCA space.

    Active Query 512-d CLS Vector & Histogram

    3. Why it matters & what you can build

    4. How the API works & Show the code

    All inference runs inside a dedicated module Web Worker via shared ../../lib/webai.js (@huggingface/transformers@3.7.5 — CPU WASM q8) with strict FIFO queueing and epoch-safe disposal.

    Show the code: CLS-pooled feature-extraction forward pass (worker.js)
    Show the code: canonical Chinese retrieval query instruction formatter (bge-zh-core.mjs)

    5. References