⚡️ 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.

  1. Light & Fast

    • Quantized model weights
    • ONNX Runtime for inference
  2. Accuracy/Recall

    • Better than OpenAI Ada-002
    • Default is Flag Embedding, which has shown good results on the MTEB leaderboard
    • List of supported models - including multilingual models

Here is an example for Retrieval Embedding Generation and how to use FastEmbed with Qdrant.

🚀 Installation

To install the FastEmbed library, pip works:

  1. pip install fastembed

📖 Usage

  1. from fastembed import TextEmbedding
  2. documents: list[str] = [
  3. "passage: Hello, World!",
  4. "query: Hello, World!",
  5. "passage: This is an example passage.",
  6. "fastembed is supported by and maintained by Qdrant."
  7. ]
  8. embedding_model = TextEmbedding()
  9. embeddings: list[np.ndarray] = embedding_model.embed(documents)

Usage with Qdrant

Installation with Qdrant Client in Python:

  1. pip install qdrant-client[fastembed]

Might have to use pip install 'qdrant-client[fastembed]' on zsh.

  1. from qdrant_client import QdrantClient
  2. # Initialize the client
  3. client = QdrantClient(":memory:") # Using an in-process Qdrant
  4. # Prepare your documents, metadata, and IDs
  5. docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
  6. metadata = [
  7. {"source": "Langchain-docs"},
  8. {"source": "Llama-index-docs"},
  9. ]
  10. ids = [42, 2]
  11. client.add(
  12. collection_name="demo_collection",
  13. documents=docs,
  14. metadata=metadata,
  15. ids=ids
  16. )
  17. search_result = client.query(
  18. collection_name="demo_collection",
  19. query_text="This is a query document"
  20. )
  21. print(search_result)