Skip to content

AgentiX-E/embed-code-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

103 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

embed-code-ts

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.

CI npm version npm version npm version npm version Docs Benchmark Report Coverage License Node.js

What is embed-code-ts?

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.

Architecture

Text → [WordPiece Tokenizer] → [ONNX Runtime] → [Mean Pool] → [L2 Norm] → 768d Embedding
         (40856 vocab, 512 max)   (int8 quantized)     (mask-aware)

Packages

Package npm Description
@agentix-e/embed-code-core npm Pure TypeScript core: WordPiece tokenizer, pooler, interfaces — zero dependencies
@agentix-e/embed-code-node npm Node.js ONNX Runtime inference (onnxruntime-node, AVX2/AVX-512)
@agentix-e/embed-code-web npm Browser inference (onnxruntime-web: WASM / WebGPU auto-upgrade)
@agentix-e/embed-code-cli npm CLI tool: embed-code setup, embed-code embed, embed-code info

Quick Start

Node.js

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();

Browser

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;');

CLI

embed-code setup                           # Download model (~137 MB)
embed-code embed "function add(a,b) {}"    # Generate embedding
embed-code info                            # Model + system info

Task Prefixes

For 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) { ... }

Model

  • 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)

Performance (int8 ONNX)

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

Documentation & Reports

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/

FAQ

How is embed-code-ts different from calling an embedding API?

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.

Which programming languages does it support?

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.

How do I use embeddings for code search?

  1. Index phase: Embed all your code snippets with the search_document: prefix, store embeddings in a vector database (e.g., LanceDB, Chroma, Milvus).
  2. Query phase: Embed search queries with the search_query: prefix, find nearest neighbors via cosine similarity.

Can I run this in a serverless function?

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.

Does embed-code-ts work with TypeScript?

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.

What is the accuracy impact of int8 quantization?

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.

How do I update the embedded model weights?

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.

Is this production-ready?

Yes. All packages pass their CI pipeline with >95% test coverage (line, branch, function, statement). Verified benchmarks run on every push.

Comparison

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

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

Apache 2.0. Model weights from nomic-ai/nomic-embed-text-v1.5 (Apache 2.0).

About

ONNX-powered code embeddings for Node.js & browser — int8 quantized BERT model, zero network dependency. Semantic code search, RAG, and AI tools for TypeScript/JavaScript.

Topics

Resources

License

Contributing

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors