mirror of
https://github.com/qdrant/fastembed.git
synced 2026-09-21 13:37:57 -05:00
6.9 KiB
6.9 KiB
In [1]:
!pip install -Uqq fastembedIn [2]:
import numpy as np
from fastembed import TextEmbedding
# 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)
embeddings_list = list(embeddings_generator)
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)
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)))
embeddings_list.shapeOut [4]:
(2, 384)
In [5]:
multilingual_large_model = TextEmbedding("intfloat/multilingual-e5-large")Fetching 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)