ONNX-powered code embeddings for Node.js and browser — int8 quantized BERT model, zero network dependency after install. Generate 768-dimensional semantic code embeddings for code search, RAG, and AI-powered developer tools.
embed-code-ts is a TypeScript-first code embedding library that runs the nomic-embed-code model (BERT-base, 137M parameters) directly in Node.js and browsers via ONNX Runtime. The model is int8-quantized to ~137MB and bundled into the npm package — no external API calls, no GPU required, fully offline.
Use cases: semantic code search, code-to-code similarity, retrieval-augmented generation (RAG) for codebases, code clustering, duplicate detection, and AI code assistant backends.
Text → [WordPiece Tokenizer] → [ONNX Runtime] → [Mean Pool] → [L2 Norm] → 768d Embedding
(40856 vocab, 512 max) (int8 quantized) (mask-aware)
import { NodeEmbedder } from '@agentix-e/embed-code-node';
const embedder = await NodeEmbedder.create({
modelPath: './models/nomic-embed-code-v1.5.int8.onnx',
});
const embedding = await embedder.embed('function hello() { return "world"; }');
// → Float32Array(768), L2 normalized
await embedder.dispose();import { WebEmbedder } from '@agentix-e/embed-code-web';
const tokenizerJson = await fetch('/models/tokenizer.json').then((r) => r.json());
const embedder = await WebEmbedder.create('/models/model.onnx', tokenizerJson);
const embedding = await embedder.embed('const x = 42;');embed-code setup # Download model (~137 MB)
embed-code embed "function add(a,b) {}" # Generate embedding
embed-code info # Model + system infoFor optimal retrieval performance, prefix inputs with search intent:
| Role | Prefix | Example |
|---|---|---|
| Query (what you search) | search_query: |
search_query: sort array by date |
| Document (what you index) | search_document: |
search_document: function quickSort(arr) { ... } |
- Architecture: BERT-base, 12 transformer layers, 768 hidden dim, 12 attention heads
- Parameters: 137 million
- Quantization: int8 dynamic quantization (~137 MB on disk)
- Max sequence length: 512 tokens
- Vocabulary: 40,856 WordPiece tokens
- Embedding dimension: 768 (L2 normalized)
- Training data: CoRNStack — curated code-text dataset
- Source model: nomic-ai/nomic-embed-text-v1.5 (Apache 2.0)
| Backend | Hardware | Latency per token | Throughput |
|---|---|---|---|
onnxruntime-node |
AVX-512 | ~5ms | ~200 req/s |
onnxruntime-node |
AVX2 | ~12ms | ~80 req/s |
onnxruntime-web |
WebGPU | ~20ms | ~50 req/s |
onnxruntime-web |
WASM | ~50ms | ~20 req/s |
| Resource | Description | URL |
|---|---|---|
| 📚 API Docs | Full TypeDoc reference for all packages | agentix-e.github.io/embed-code-ts/api/ |
| 📊 Benchmark | Inference latency, throughput & accuracy reports | agentix-e.github.io/embed-code-ts/benchmark/ |
| 📈 Coverage | Line, branch, function & statement coverage | agentix-e.github.io/embed-code-ts/coverage/ |
embed-code-ts runs entirely locally — no API keys, no network latency, no data leaving your machine. The int8-quantized model is bundled in the npm package, so after npm install everything works offline. This is critical for CI/CD pipelines, air-gapped environments, and privacy-sensitive codebases.
The nomic-embed-code model was trained on the CoRNStack dataset covering 20+ programming languages including JavaScript, TypeScript, Python, Java, Go, Rust, C++, Ruby, PHP, and more. It understands code structure, not just surface-level syntax.
- Index phase: Embed all your code snippets with the
search_document:prefix, store embeddings in a vector database (e.g., LanceDB, Chroma, Milvus). - Query phase: Embed search queries with the
search_query:prefix, find nearest neighbors via cosine similarity.
Yes. The Node.js package (@agentix-e/embed-code-node) works in any Node.js ≥22 environment. For serverless, pre-download the ONNX model during build and include it in your deployment package. Cold start with int8 model is <100ms.
Yes, 100%. The entire codebase is written in TypeScript with full type declarations. All packages ship .d.ts files — you get autocomplete and type checking out of the box.
Negligible. Our benchmarks show cosine similarity between fp32 and int8 embeddings exceeds 0.995 on standard code search evaluation sets. The int8 model is essentially lossless for retrieval tasks.
Run embed-code setup to download the latest model, or manually place an ONNX file in the models directory. The package supports any BERT-base ONNX model following the nomic architecture.
Yes. All packages pass their CI pipeline with >95% test coverage (line, branch, function, statement). Verified benchmarks run on every push.
| Feature | embed-code-ts | OpenAI Embeddings | Cohere Embed | Sentence Transformers (Python) |
|---|---|---|---|---|
| Offline | ✅ Yes | ❌ API only | ❌ API only | ✅ Yes |
| Language | TypeScript | REST API | REST API | Python |
| Model size | 137 MB (int8) | N/A | N/A | 400+ MB (fp32) |
| Node.js | ✅ Native | ✅ HTTP | ✅ HTTP | ❌ |
| Browser | ✅ WASM/WebGPU | ❌ | ❌ | ❌ |
| Cost | Free | Per-token | Per-token | Free |
| Privacy | Local only | Data sent to API | Data sent to API | Local only |
| License | Apache 2.0 | Proprietary | Proprietary | Apache 2.0 |
See CONTRIBUTING.md for development setup and guidelines.
Apache 2.0. Model weights from nomic-ai/nomic-embed-text-v1.5 (Apache 2.0).