2.6.0 โข Published 5 months ago
@allemandi/embed-utils v2.6.0
๐ @allemandi/embed-utils
Fast, type-safe utilities for comparing and searching vector embeddings.
Works in Node.js, browsers โ supports ESM, CommonJS, and UMD
๐ Table of Contents
- โจ Features
- ๐ ๏ธ Installation
- ๐ Quick Usage Examples
- ๐งช Tests
- ๐ Related Projects
- ๐ค Contributing
โจ Features
- ๐ Find nearest neighbors by cosine similarity
- ๐ Compute, normalize, and verify vector similarity
- โก Lightweight and fast vector operations
๐ ๏ธ Installation
# Yarn
yarn add @allemandi/embed-utils
# NPM
npm install @allemandi/embed-utils๐ Quick Usage Examples
๐ For a complete list of methods and options, see the API docs.
ESM
import { computeCosineSimilarity } from '@allemandi/embed-utils';CommonJS
const { findNearestNeighbors } = require('@allemandi/embed-utils');
const samples = [
{ embedding: [0.1, 0.2, 0.3], label: 'sports' },
{ embedding: [0.9, 0.8, 0.7], label: 'finance' },
{ embedding: [0.05, 0.1, 0.15], label: 'sports' },
];
const query = [0.09, 0.18, 0.27];
// Find top 2 neighbors with similarity โฅ 0.5
const results = findNearestNeighbors(query, samples, { topK: 2, threshold: 0.5 });
console.log(results);
// [ { embedding: [0.1, 0.2, 0.3], label: "sports", similarityScore: 1 },
// { embedding: [0.05, 0.1, 0.15], label: "sports", similarityScore: 1 } ] UMD (Browser)
<script src="https://unpkg.com/@allemandi/embed-utils"></script>
<script>
const vectorsToNormalize = [3, 4];
const result = window.allemandi.embedUtils.normalizeVector(vectorsToNormalize);
console.log(result);
</script>๐งช Tests
Available in the GitHub repo only.
# Run the test suite with Jest
yarn test
# or
npm test๐ Related Projects
Check out these related projects that might interest you:
- Node.js CLI tool for local text classification using word embeddings.
- A minimalist command-line knowledge system with semantic memory capabilities using vector embeddings for information retrieval.
๐ค Contributing
If you have ideas, improvements, or new features:
- Fork the project
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add some amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request