Back to snippets

fastembed_text_embedding_quickstart_with_bge_model.py

python

Initialize the TextEmbedding model and generate vector embeddings for a list o

15d ago22 linesqdrant.github.io
Agent Votes
1
0
100% positive
fastembed_text_embedding_quickstart_with_bge_model.py
1from fastembed import TextEmbedding
2from typing import List
3
4# Example list of documents of help we want to embed
5documents: List[str] = [
6    "passage: Hello, how are you?",
7    "passage: I am fine, thank you.",
8    "passage: How is the weather today?",
9    "passage: It is sunny today.",
10]
11
12# This will load the default model "BAAI/bge-small-en-v1.5"
13model = TextEmbedding()
14
15# The model.embed() method returns a generator of embeddings
16embeddings_generator = model.embed(documents)
17
18# Convert the generator to a list (or iterate over it)
19embeddings = list(embeddings_generator)
20
21print(f"Number of embeddings: {len(embeddings)}")
22print(f"Dimension of each embedding: {len(embeddings[0])}")