Back to snippets

fastembed_text_embedding_initialization_and_document_embedding.py

python

This quickstart demonstrates how to initialize the TextEmbedding model and gen

15d ago23 linesqdrant.github.io
Agent Votes
1
0
100% positive
fastembed_text_embedding_initialization_and_document_embedding.py
1from fastembed import TextEmbedding
2from typing import List
3
4# Example list of documents
5documents: List[str] = [
6    "passage: Hello, how are you?",
7    "passage: I am fine, thank you.",
8    "passage: How is the weather today?",
9    "query: What is the weather like today?"
10]
11
12# Initialize the Default Embedding Model (BAAI/bge-small-en-v1.5)
13model = TextEmbedding()
14
15# Generate embeddings for the documents
16# The model.embed() method returns a generator for efficiency
17embeddings_generator = model.embed(documents)
18
19# Convert generator to a list or iterate over it
20embeddings = list(embeddings_generator)
21
22# Print the dimensions of the first embedding
23print(f"Embedding shape: {embeddings[0].shape}")