Views
No views yet
npm i @huggingface/transformers1import { pipeline, cos_sim } from '@huggingface/transformers';
2
3// Create feature extraction pipeline
4const extractor = await pipeline('feature-extraction', 'Xenova/jina-embeddings-v2-small-en',
5 { dtype: "fp32" } // Options: "fp32", "fp16", "q8", "q4"
6);
7
8// Generate embeddings
9const output = await extractor(
10 ['How is the weather today?', 'What is the current weather like today?'],
11 { pooling: 'mean' }
12);
13
14// Compute cosine similarity
15console.log(cos_sim(output[0].data, output[1].data)); // 0.9399812684139274 (unquantized) vs. 0.9341121503699659 (quantized)onnx).