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 embedding supports "query" and "passage" prefixes for the input text. The default model is Flag Embedding, which is top of the MTEB leaderboard. 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.embedding import FlagEmbedding as Embedding
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 = Embedding(model_name="BAAI/bge-base-en", max_length=512) 
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(":memory:")  # or 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": "Linkedin-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.1.2.tar.gz (6.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastembed-0.1.2-py3-none-any.whl (6.8 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastembed-0.1.2.tar.gz
  • Upload date:
  • Size: 6.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0

File hashes

Hashes for fastembed-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c89e5be3ff06912481992615a103c039ab7f1a47cd914c907afd009fa2f5009c
MD5 73ed3ae488139094969e11c65ea57f87
BLAKE2b-256 93afc82024d178dd8a5e6f968ef0a88255748a21b9992e83d2964265b32f992e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastembed-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0

File hashes

Hashes for fastembed-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed7dfe2474fddcb5532bea7777dffb6726874cb3162f884f50de1f030d3325c9
MD5 b93bc7dd601569b03cd31f917366066f
BLAKE2b-256 8463604227029eb0c5df04b17a2ee0bb4603b1302493d8bc9b7925d79f201861

See more details on using hashes here.

Supported by

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