Skip to content

divyanshsaraswat/clipkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clipkit-embeddings

npm version License: CC BY 4.0 License Issues

Fast CLIP text and image embedding toolkit for Node.js and browser using ONNX.

clipkit-embeddings is a TypeScript library and CLI that enables high-performance CLIP embeddings for both text and images, powered by onnxruntime-node. It allows you to use CLIP models offline for semantic search, similarity computation, or zero-shot classification — both programmatically and via the command line.


✨ Features

  • 🔤 Embed text using clip-text.onnx
  • 🖼️ Embed images using clip-image.onnx
  • 🧠 Cosine similarity for comparing embeddings
  • ⚡️ Fast inference with ONNXRuntime
  • 🧰 CLI tool for quick use in scripts
  • 🌐 Works in Node.js and browser (with bundler)

📦 Installation

As a library:

npm install clipkit-embeddings

As a library:

npm install -g clipkit-embeddings

🚀 Usage

🧠 Text Embedding

import { loadTextModel, embedText } from "clipkit-embeddings";

await loadTextModel("onnx/clip-text.onnx");
const embedding = await embedText("a photo of a dog");
console.log(embedding);

🖼️ Image Embedding

import { loadImageModel, embedImage } from "clipkit-embeddings";
import { preprocessImage } from "clipkit-embeddings/utils";

await loadImageModel("onnx/clip-image.onnx");
const tensor = await preprocessImage("test/cat.jpg");
const embedding = await embedImage(tensor);
console.log(embedding);

🔁 Cosine Similarity

import { cosineSimilarity } from "clipkit-embeddings/utils";

const similarity = cosineSimilarity(imageEmbedding, textEmbedding);
console.log("Cosine similarity:", similarity.toFixed(4));

🧪 CLI Usage

Embed text:

clipkit text "a photo of a cat"

Embed image:

clipkit image ./path/to/image.jpg

📁 Project Structure

clipkit-embeddings/
├── cli/              # CLI logic
├── src/              # Core logic (text/image/utils)
├── test/             # Sample test files and images
├── onnx/             # Model files (.onnx)
│   ├── clip-text.onnx
│   └── clip-image.onnx
├── package.json
├── tsconfig.json
├── README.md
└── LICENSE

👨‍💻 Contributing

Contributions, issues and feature requests are welcome!
Please open an issue to discuss any major changes beforehand.


📚 References


📝 License

This project is licensed under the MIT License.
See the LICENSE file for full text.


✍️ Author

Divyansh Saraswat
GitHubLinkedInTwitter

About

clipkit-embeddings is a TypeScript library and CLI that enables high-performance CLIP embeddings for both text and images, powered by onnxruntime-node

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors