Anush008 / fastembed-js

Library to generate vector embeddings in NodeJS
https://www.npmjs.com/package/fastembed/
MIT License
64 stars 5 forks source link

Question : embeddingModel.embed vs embeddingModel.passage #11

Closed x4080 closed 7 months ago

x4080 commented 8 months ago

Hi whats the difference and what's the relation with python version since the python version I believe only have 1 kind ?

from fastembed.embedding import FlagEmbedding as Embedding
from typing import List
import numpy as np

documents: List[str] = [
    "passage: Hello, World!",
    "query: Hello, World!", # these are two different embedding
    "passage: This is an example passage.",
    "fastembed is supported by and maintained by Qdrant." # You can leave out the prefix but it's recommended
]
embedding_model = Embedding(model_name="BAAI/bge-base-en", max_length=512) 
embeddings: List[np.ndarray] = list(embedding_model.embed(documents)) # Note the list() call - this is a generator 

Thanks

Anush008 commented 7 months ago

The Python version supports query_embed() and passage_embed() too. These methods prefix the text with 'query: ' and 'passage: ' respectively before generating embeddings for better results.

x4080 commented 7 months ago

Cool, thanks