mirror of
https://github.com/qdrant/fastembed.git
synced 2026-10-02 19:07:53 -05:00
* new: simplify imports * refactoring: update import * refactoring: update imports in notebooks * fix: fix notebook output * Re-run notebook with revised imports --------- Co-authored-by: Nirant Kasliwal <nirant.bits@gmail.com>
7.4 KiB
7.4 KiB
In [1]:
!pip install -Uqq fastembed # Install fastembedIn [2]:
import numpy as np
from fastembed import TextEmbedding
from typing import List
# Example list of documents
documents: List[str] = [
"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.",
"fastembed is supported by and maintained by Qdrant.",
]
# This will trigger the model download and initialization
embedding_model = TextEmbedding()
print("The model BAAI/bge-small-en-v1.5 is ready to use.")
embeddings_generator = embedding_model.embed(documents) # reminder this is a generator
embeddings_list = list(embeddings_generator)
# you can also convert the generator to a list, and that to a numpy array
len(embeddings_list[0]) # Vector of 384 dimensionsOut [2]:
Fetching 9 files: 0%| | 0/9 [00:00<?, ?it/s]
The model BAAI/bge-small-en-v1.5 is ready to use.
384
In [3]:
embeddings_generator = embedding_model.embed(documents) # reminder this is a generator
for doc, vector in zip(documents, embeddings_generator):
print("Document:", doc)
print(f"Vector of type: {type(vector)} with shape: {vector.shape}")Document: This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc. Vector of type: <class 'numpy.ndarray'> with shape: (384,) Document: fastembed is supported by and maintained by Qdrant. Vector of type: <class 'numpy.ndarray'> with shape: (384,)
In [4]:
embeddings_list = np.array(
list(embedding_model.embed(documents))
) # you can also convert the generator to a list, and that to a numpy array
embeddings_list.shapeOut [4]:
(2, 384)
In [5]:
multilingual_large_model = TextEmbedding("intfloat/multilingual-e5-large") # This can take a few minutes to downloadFetching 8 files: 0%| | 0/8 [00:00<?, ?it/s]
In [6]:
np.array(
list(multilingual_large_model.embed(["Hello, world!", "你好世界", "¡Hola Mundo!", "नमस्ते!"]))
).shape # Vector of 1024 dimensionsOut [6]:
(4, 1024)