You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{EmbeddingModel,FlagEmbedding}from"fastembed";// For CommonJS// const { EmbeddingModel, FlagEmbedding } = require("fastembed)constembeddingModel=awaitFlagEmbedding.init({model: EmbeddingModel.BGEBaseEN});letdocuments=["passage: Hello, World!","query: Hello, World!","passage: This is an example passage.",// You can leave out the prefix but it's recommended"fastembed-js is licensed under MIT"];constembeddings=embeddingModel.embed(documents,2);//Optional batch size. Defaults to 256forawait(constbatchofembeddings){// batch is list of Float32 embeddings(number[][]) with length 2console.log(batch);}
Supports passage and query embeddings for more accurate results
constembeddings=embeddingModel.passageEmbed(listOfLongTexts,10);//Optional batch size. Defaults to 256forawait(constbatchofembeddings){// batch is list of Float32 passage embeddings(number[][]) with length 10console.log(batch);}constqueryEmbeddings: number[]=awaitembeddingModel.queryEmbed(userQuery);console.log(queryEmbeddings)
🚒 Under the hood
Why fast?
It's important we justify the "fast" in FastEmbed. FastEmbed is fast because:
Quantized model weights
ONNX Runtime which allows for inference on CPU, GPU, and other dedicated runtimes
Why light?
No hidden dependencies via Huggingface Transformers