Nirant 81bab0cd1d Make 0.2.1 Release + Update docs (#116)
* Update version from 0.2.0 (yanked) to 0.2.1

* Update text embedding to include prefix for passages and queries

* Update supported models to use the latest API

* * fix(text_embedding_base.py): remove unnecessary prefix from texts in embed method
* feat(text_embedding_base.py): update query_embed method to updated instruction for the v1.5 model

* Remove comparison, since the ranking is identical even with varying embedding

* Refactor text embedding query handling
2024-02-08 09:06:00 +05:30
2024-02-02 15:51:19 +01:00
2023-07-05 08:49:59 +05:30
2024-01-16 15:06:54 +05:30
2024-02-07 20:36:46 +05:30
2024-02-05 10:49:45 +05:30

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.

Languages
Python 87%
Jupyter Notebook 13%