Skip to main content

Haystack 2.x component to embed strings and Documents using fastembed embedding model

Project description

fastembed-haystack

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install fastembed-haystack

Usage

You can use FastembedTextEmbedder and FastembedDocumentEmbedder by importing as:

from haystack_integrations.components.embedders.fastembed import FastembedTextEmbedder

text = "fastembed is supported by and maintained by Qdrant."
text_embedder = FastembedTextEmbedder(
    model="BAAI/bge-small-en-v1.5"
)
text_embedder.warm_up()
embedding = text_embedder.run(text)["embedding"]
from haystack_integrations.components.embedders.fastembed import FastembedDocumentEmbedder
from haystack import Document

embedder = FastembedDocumentEmbedder(
    model="BAAI/bge-small-en-v1.5",
)
embedder.warm_up()
doc = Document(content="fastembed is supported by and maintained by Qdrant.", meta={"long_answer": "no",})
result = embedder.run(documents=[doc])

You can use FastembedSparseTextEmbedder and FastembedSparseDocumentEmbedder by importing as:

from haystack_integrations.components.embedders.fastembed import FastembedSparseTextEmbedder

text = "fastembed is supported by and maintained by Qdrant."
text_embedder = FastembedSparseTextEmbedder(
    model="prithivida/Splade_PP_en_v1"
)
text_embedder.warm_up()
embedding = text_embedder.run(text)["sparse_embedding"]
from haystack_integrations.components.embedders.fastembed import FastembedSparseDocumentEmbedder
from haystack import Document

embedder = FastembedSparseDocumentEmbedder(
    model="prithivida/Splade_PP_en_v1",
)
embedder.warm_up()
doc = Document(content="fastembed is supported by and maintained by Qdrant.", meta={"long_answer": "no",})
result = embedder.run(documents=[doc])

You can use FastembedRanker by importing as:

from haystack import Document

from haystack_integrations.components.rankers.fastembed import FastembedRanker

query = "Who is maintaining Qdrant?"
documents = [
    Document(
        content="This is built to be faster and lighter than other embedding libraries e.g. Transformers, Sentence-Transformers, etc."
    ),
    Document(content="fastembed is supported by and maintained by Qdrant."),
]

ranker = FastembedRanker(model_name="Xenova/ms-marco-MiniLM-L-6-v2")
ranker.warm_up()
reranked_documents = ranker.run(query=query, documents=documents)["documents"]

print(reranked_documents[0])

# Document(id=...,
#  content: 'fastembed is supported by and maintained by Qdrant.',
#  score: 5.472434997558594..)

License

fastembed-haystack is distributed under the terms of the Apache-2.0 license.

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_haystack-1.4.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

fastembed_haystack-1.4.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file fastembed_haystack-1.4.1.tar.gz.

File metadata

  • Download URL: fastembed_haystack-1.4.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for fastembed_haystack-1.4.1.tar.gz
Algorithm Hash digest
SHA256 b1c583507c224ee110f07bd1c98c1d12cba7116d6f2ae4f578a2ad0fac047886
MD5 93cd1e3ff00b1293ba3ca4489e6de550
BLAKE2b-256 f002b5bdeaef76ff74265d6683ec2641c80a36034485b6380963b8a69cef6a52

See more details on using hashes here.

File details

Details for the file fastembed_haystack-1.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastembed_haystack-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7ebdb992687af10eefa5db7e1e5ca33664b20a9f25013791afff35b46ce10e4
MD5 7aab3a6aba9365d3090bf87d2d5e39a3
BLAKE2b-256 c5642d58644656623d381a02aebc3ee67f71b6cad62f0b4e35a6d0294441d396

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