Skip to main content

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.

  1. Light & Fast

    • Quantized model weights
    • ONNX Runtime, no PyTorch dependency
    • CPU-first design
    • Data-parallelism for encoding of large datasets
  2. Accuracy/Recall

    • Better than OpenAI Ada-002
    • Default is Flag Embedding, which is top of the MTEB leaderboard
    • List of supported models - including multilingual models

🚀 Installation

To install the FastEmbed library, pip works:

pip install fastembed

📖 Usage

from fastembed import TextEmbedding
from typing import List
import numpy as np

documents: List[str] = [
    "passage: Hello, World!",
    "query: Hello, World!", # these are two different embedding
    "passage: This is an example passage.",
    "fastembed is supported by and maintained by Qdrant." # You can leave out the prefix but it's recommended
]
embedding_model = TextEmbedding(model_name="BAAI/bge-base-en")
embeddings: List[np.ndarray] = list(embedding_model.embed(documents)) # Note the list() call - this is a generator

Usage with Qdrant

Installation with Qdrant Client in Python:

pip install qdrant-client[fastembed]

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
# OR if you just want to try it out quickly:
# client = QdrantClient(":memory:")
# client = QdrantClient(path="path/to/db")

# 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]

# Use the new add method
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastembed-0.2.1.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

fastembed-0.2.1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file fastembed-0.2.1.tar.gz.

File metadata

  • Download URL: fastembed-0.2.1.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for fastembed-0.2.1.tar.gz
Algorithm Hash digest
SHA256 694ee6db284e931382cfa26cd98a80ace37921fc1a8183cf00cb7b8eb06d52bd
MD5 42280b9f06cbc3d29869082b71621dce
BLAKE2b-256 688a882ac0dd895480ca1541c4655dabda0f3943aaf7163e02fadaf111b37079

See more details on using hashes here.

File details

Details for the file fastembed-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fastembed-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for fastembed-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e3d71e449a54e1c47bd502246ee9367259002691caba5d3c25b9ebb47d1f621
MD5 f7d829b063861804104a9c1cb8935b5d
BLAKE2b-256 9a0b010b682cc50e541e688346d2e53d5df7bf7669d479bb1e40388eb8c9969b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page