fastembed


Namefastembed JSON
Version 0.2.7 PyPI version JSON
download
home_pagehttps://github.com/qdrant/fastembed
SummaryFast, light, accurate library built for retrieval embedding generation
upload_time2024-05-03 16:37:51
maintainerNone
docs_urlNone
authorNirantK
requires_python<3.13,>=3.8.0
licenseApache License
keywords vector embedding neural search qdrant sentence-transformers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ⚡️ What is FastEmbed?

FastEmbed is a lightweight, fast, Python library built for embedding generation. We [support popular text models](https://qdrant.github.io/fastembed/examples/Supported_Models/). Please [open a GitHub issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.

The default text embedding (`TextEmbedding`) model is Flag Embedding, presented in the [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard. It supports "query" and "passage" prefixes for the input text. Here is an example for [Retrieval Embedding Generation](https://qdrant.github.io/fastembed/qdrant/Retrieval_with_FastEmbed/) and how to use [FastEmbed with Qdrant](https://qdrant.github.io/fastembed/qdrant/Usage_With_Qdrant/).

## 📈 Why FastEmbed?

1. 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. 

2. 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.

3. Accurate: FastEmbed is better than OpenAI Ada-002. We also [supported](https://qdrant.github.io/fastembed/examples/Supported_Models/) an ever expanding set of models, including a few multilingual models.

## 🚀 Installation

To install the FastEmbed library, pip works best. You can install it with or without GPU support:

```bash
pip install fastembed
```

### ⚡️ With GPU

```bash
pip install fastembed-gpu
```

## 📖 Quickstart

```python
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
```

### ⚡️ FastEmbed on a GPU

FastEmbed supports running on GPU devices. It requires installation of the `fastembed-gpu` package.
Make sure not to have the `fastembed` package installed, as it might interfere with the `fastembed-gpu` package.

```bash
pip install fastembed-gpu
``` 

```python
from fastembed import TextEmbedding

embedding_model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5", providers=["CUDAExecutionProvider"])
print("The model BAAI/bge-small-en-v1.5 is ready to use on a GPU.")

```

## Usage with Qdrant

Installation with Qdrant Client in Python:

```bash
pip install qdrant-client[fastembed]
```

or 

```bash
pip install qdrant-client[fastembed-gpu]
```

You might have to use quotes ```pip install 'qdrant-client[fastembed]'``` on zsh.

```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qdrant/fastembed",
    "name": "fastembed",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.8.0",
    "maintainer_email": null,
    "keywords": "vector, embedding, neural, search, qdrant, sentence-transformers",
    "author": "NirantK",
    "author_email": "nirant.bits@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0b/24/4385a6b81ac3f22d1e1533a84a216cd9b24fe1eb4390cad2928640e47713/fastembed-0.2.7.tar.gz",
    "platform": null,
    "description": "# \u26a1\ufe0f What is FastEmbed?\n\nFastEmbed is a lightweight, fast, Python library built for embedding generation. We [support popular text models](https://qdrant.github.io/fastembed/examples/Supported_Models/). Please [open a GitHub issue](https://github.com/qdrant/fastembed/issues/new) if you want us to add a new model.\n\nThe default text embedding (`TextEmbedding`) model is Flag Embedding, presented in the [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard. It supports \"query\" and \"passage\" prefixes for the input text. Here is an example for [Retrieval Embedding Generation](https://qdrant.github.io/fastembed/qdrant/Retrieval_with_FastEmbed/) and how to use [FastEmbed with Qdrant](https://qdrant.github.io/fastembed/qdrant/Usage_With_Qdrant/).\n\n## \ud83d\udcc8 Why FastEmbed?\n\n1. 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. \n\n2. 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.\n\n3. Accurate: FastEmbed is better than OpenAI Ada-002. We also [supported](https://qdrant.github.io/fastembed/examples/Supported_Models/) an ever expanding set of models, including a few multilingual models.\n\n## \ud83d\ude80 Installation\n\nTo install the FastEmbed library, pip works best. You can install it with or without GPU support:\n\n```bash\npip install fastembed\n```\n\n### \u26a1\ufe0f With GPU\n\n```bash\npip install fastembed-gpu\n```\n\n## \ud83d\udcd6 Quickstart\n\n```python\nfrom fastembed import TextEmbedding\nfrom typing import List\n\n# Example list of documents\ndocuments: List[str] = [\n    \"This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc.\",\n    \"fastembed is supported by and maintained by Qdrant.\",\n]\n\n# This will trigger the model download and initialization\nembedding_model = TextEmbedding()\nprint(\"The model BAAI/bge-small-en-v1.5 is ready to use.\")\n\nembeddings_generator = embedding_model.embed(documents)  # reminder this is a generator\nembeddings_list = list(embedding_model.embed(documents))\n  # you can also convert the generator to a list, and that to a numpy array\nlen(embeddings_list[0]) # Vector of 384 dimensions\n```\n\n### \u26a1\ufe0f FastEmbed on a GPU\n\nFastEmbed supports running on GPU devices. It requires installation of the `fastembed-gpu` package.\nMake sure not to have the `fastembed` package installed, as it might interfere with the `fastembed-gpu` package.\n\n```bash\npip install fastembed-gpu\n``` \n\n```python\nfrom fastembed import TextEmbedding\n\nembedding_model = TextEmbedding(model_name=\"BAAI/bge-small-en-v1.5\", providers=[\"CUDAExecutionProvider\"])\nprint(\"The model BAAI/bge-small-en-v1.5 is ready to use on a GPU.\")\n\n```\n\n## Usage with Qdrant\n\nInstallation with Qdrant Client in Python:\n\n```bash\npip install qdrant-client[fastembed]\n```\n\nor \n\n```bash\npip install qdrant-client[fastembed-gpu]\n```\n\nYou might have to use quotes ```pip install 'qdrant-client[fastembed]'``` on zsh.\n\n```python\nfrom qdrant_client import QdrantClient\n\n# Initialize the client\nclient = QdrantClient(\"localhost\", port=6333) # For production\n# client = QdrantClient(\":memory:\") # For small experiments\n\n# Prepare your documents, metadata, and IDs\ndocs = [\"Qdrant has Langchain integrations\", \"Qdrant also has Llama Index integrations\"]\nmetadata = [\n    {\"source\": \"Langchain-docs\"},\n    {\"source\": \"Llama-index-docs\"},\n]\nids = [42, 2]\n\n# If you want to change the model:\n# client.set_model(\"sentence-transformers/all-MiniLM-L6-v2\")\n# List of supported models: https://qdrant.github.io/fastembed/examples/Supported_Models\n\n# Use the new add() instead of upsert()\n# This internally calls embed() of the configured embedding model\nclient.add(\n    collection_name=\"demo_collection\",\n    documents=docs,\n    metadata=metadata,\n    ids=ids\n)\n\nsearch_result = client.query(\n    collection_name=\"demo_collection\",\n    query_text=\"This is a query document\"\n)\nprint(search_result)\n```\n",
    "bugtrack_url": null,
    "license": "Apache License",
    "summary": "Fast, light, accurate library built for retrieval embedding generation",
    "version": "0.2.7",
    "project_urls": {
        "Homepage": "https://github.com/qdrant/fastembed",
        "Repository": "https://github.com/qdrant/fastembed"
    },
    "split_keywords": [
        "vector",
        " embedding",
        " neural",
        " search",
        " qdrant",
        " sentence-transformers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8bbfa7620fd49aa073c16d410e6cbdb4f992b0c52135f4f12ca0b1dbff47287",
                "md5": "2ae6ee4adc086b2a2f705e93fb0710ac",
                "sha256": "8f21e65e6d5d06bd8727488906c6c4eda8eb86d81be8879a54846dfe8a23c9d3"
            },
            "downloads": -1,
            "filename": "fastembed-0.2.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ae6ee4adc086b2a2f705e93fb0710ac",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.8.0",
            "size": 27715,
            "upload_time": "2024-05-03T16:37:49",
            "upload_time_iso_8601": "2024-05-03T16:37:49.778116Z",
            "url": "https://files.pythonhosted.org/packages/d8/bb/fa7620fd49aa073c16d410e6cbdb4f992b0c52135f4f12ca0b1dbff47287/fastembed-0.2.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b244385a6b81ac3f22d1e1533a84a216cd9b24fe1eb4390cad2928640e47713",
                "md5": "4c70ffcc318933e9c7e4e512ba5fd4ac",
                "sha256": "f5537e3680694afcd3d806c19dd4514030fdc3144e7e9a9db0dfece771922503"
            },
            "downloads": -1,
            "filename": "fastembed-0.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "4c70ffcc318933e9c7e4e512ba5fd4ac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.8.0",
            "size": 20119,
            "upload_time": "2024-05-03T16:37:51",
            "upload_time_iso_8601": "2024-05-03T16:37:51.250937Z",
            "url": "https://files.pythonhosted.org/packages/0b/24/4385a6b81ac3f22d1e1533a84a216cd9b24fe1eb4390cad2928640e47713/fastembed-0.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 16:37:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qdrant",
    "github_project": "fastembed",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastembed"
}
        
Elapsed time: 0.33981s