FastEmbed is a lightweight Python library built for embedding generation. It supports popular embedding models and offers a user-friendly experience for embedding data into vector space.
By using FastEmbed, you can ensure that your embedding generation process is not only fast and efficient but also highly accurate, meeting the needs of various machine learning and natural language processing applications.
FastEmbed easily integrates with Qdrant for a variety of multimodal search purposes.
Why is FastEmbed useful?
- Light: Unlike other inference frameworks, such as PyTorch, FastEmbed requires very little external dependencies. Because it uses the ONNX runtime, it is perfect for serverless environments like AWS Lambda.
- Fast: By using ONNX, FastEmbed ensures high-performance inference across various hardware platforms.
- Accurate: FastEmbed aims for better accuracy and recall than models like OpenAI’s
Ada-002
. It always uses model which demonstrate strong results on the MTEB leaderboard. - Support: FastEmbed supports a wide range of models, including multilingual ones, to meet diverse use case needs.
How to Generate Text Embedings with FastEmbed
Install FastEmbed
Just for demo purposes, you will use Lists and NumPy to work with sample data.
Load default model
In this example, you will use the default text embedding model, BAAI/bge-small-en-v1.5
.
Add sample data
Now, add two sample documents. Your documents must be in a list, and each document must be a string
Download and initialize the model. Print a message to verify the process.
Embed data
Generate embeddings for both documents.
Here is the sample document list. The default model creates vectors with 384 dimensions.
Visualize embeddings
The embeddings don’t look too interesting, but here is a visual.