A lightweight semantic text embedding engine built with TypeScript
npm install embsystem
A lightweight semantic text embedding engine built in TypeScript.
Fast, dependency-free, and perfect for AI pipelines, semantic search, clustering, and NLP tasks.
bash
npm install
`
``
(Optional) Build TypeScript:
`bash
npm run build
`
---
๐ง Usage Example
`ts
import EmbeddingSystem from "./src/embedding.js";
const texts = [
"Machine learning is amazing",
"Deep learning uses neural networks",
"Python is great for AI",
"Natural language processing",
"ุงูุชุนูู
ุงูุขูู ุฑุงุฆุน",
"ุงูุดุจูุงุช ุงูุนุตุจูุฉ ูููุฉ",
];
EmbeddingSystem.initialize(texts, 128);
const embedding = EmbeddingSystem.encode("machine learning");
console.log("Embedding:", embedding.slice(0, 5), "...");
const decoded = EmbeddingSystem.decode(embedding, 3);
console.log("Decoded words:", decoded);
const results = EmbeddingSystem.semanticSearch("neural networks", texts, 3);
console.log("Semantic Search:", results);
const clusters = EmbeddingSystem.cluster(texts, 2);
console.log("Clusters:", clusters);
console.log("System Info:", EmbeddingSystem.getInfo());
`
---
๐งช Sample Output
`
Embedding: [0.01, -0.03, -0.12, 0.07, 0.002 ...]
Decoded words:
[ "machine", "learning", "deep" ]
Semantic Search:
Score: 0.610 - Deep learning uses neural networks
Score: 0.098 - Natural language processing
Score: -0.001 - Python is great for AI
Clusters:
Cluster 0: ["Python is great for AI", "ุงูุดุจูุงุช ุงูุนุตุจูุฉ ูููุฉ"]
Cluster 1: ["Machine learning is amazing", "Deep learning uses neural networks", "Natural language processing", "ุงูุชุนูู
ุงูุขูู ุฑุงุฆุน"]
System Info:
{ vocabularySize: 21, dimension: 128, isInitialized: true }
`
---
๐ Project Structure
`
src/
embedding.ts
test.ts
package.json
README.md
`
---
๐ Scripts
`bash
npm run dev # Runs src/main.js
npm run test # Runs test.js
npm run build # Compiles TypeScript into dist/
npm start # Runs dist/main.js after build
``