Fast, light, accurate library built for retrieval embedding generation
Project description
⚡️ What is FastEmbed?
FastEmbed is a lightweight, fast, Python library built for embedding generation. We support popular text models. Please open a GitHub issue if you want us to add a new model.
The default text embedding (TextEmbedding
) model is Flag Embedding, the top model in the MTEB leaderboard. It supports "query" and "passage" prefixes for the input text. Here is an example for Retrieval Embedding Generation and how to use FastEmbed with Qdrant.
📈 Why FastEmbed?
-
Light: FastEmbed is a lightweight library with few external dependencies. We don't require a GPU and don't download GBs of PyTorch dependencies, and instead use the ONNX Runtime. This makes it a great candidate for serverless runtimes like AWS Lambda.
-
Fast: FastEmbed is designed for speed. We use the ONNX Runtime, which is faster than PyTorch. We also use data-parallelism for encoding large datasets.
-
Accurate: FastEmbed is better than OpenAI Ada-002. We also supported an ever expanding set of models, including a few multilingual models.
🚀 Installation
To install the FastEmbed library, pip works:
pip install fastembed
📖 Quickstart
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(embedding_model.embed(documents))
# you can also convert the generator to a list, and that to a numpy array
len(embeddings_list[0]) # Vector of 384 dimensions
Usage with Qdrant
Installation with Qdrant Client in Python:
pip install qdrant-client[fastembed]
You might have to use pip install 'qdrant-client[fastembed]'
on zsh.
from qdrant_client import QdrantClient
# Initialize the client
client = QdrantClient("localhost", port=6333) # For production
# client = QdrantClient(":memory:") # For small experiments
# Prepare your documents, metadata, and IDs
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
metadata = [
{"source": "Langchain-docs"},
{"source": "Llama-index-docs"},
]
ids = [42, 2]
# If you want to change the model:
# client.set_model("sentence-transformers/all-MiniLM-L6-v2")
# List of supported models: https://qdrant.github.io/fastembed/examples/Supported_Models
# Use the new add() instead of upsert()
# This internally calls embed() of the configured embedding model
client.add(
collection_name="demo_collection",
documents=docs,
metadata=metadata,
ids=ids
)
search_result = client.query(
collection_name="demo_collection",
query_text="This is a query document"
)
print(search_result)
Similar Work
Ilyas M. wrote about using FlagEmbeddings with Optimum over CUDA.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastembed-0.2.5.tar.gz
.
File metadata
- Download URL: fastembed-0.2.5.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b468ec4c7a26f73c4d7d18f398756580d6761c11cf3987a5f9677714aa70a70d |
|
MD5 | f0006cf9f33d2b206955e86af5bf9e74 |
|
BLAKE2b-256 | 492f481962c35c82a35d27deabac0d10eca0189377e6f7cb4c1932f486d5a9c2 |
File details
Details for the file fastembed-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: fastembed-0.2.5-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42911336653b3b7d33792d4fef1e8d6404314b429454364548def38cacc3f4a3 |
|
MD5 | 54bd0781ae179a401a8b93620bcd7fca |
|
BLAKE2b-256 | 8913c33e21a5965fccb599e6008f972e652883b03ec11a8e2f34f2be12e951a9 |