Skip to content

Commit

Permalink
small fixes; naive example
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Apr 10, 2024
1 parent a97c4ed commit 1a8c707
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

result = query_pipeline.run({"text_embedder": {"text": query}})

print(result["retriever"]["documents"][0]) # noqa: T201
print(result["retriever"]["documents"][0])

# Document(id=...,
# content: 'fastembed is supported by and maintained by Qdrant.',
Expand Down
32 changes: 32 additions & 0 deletions integrations/fastembed/examples/sparse_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Currently, this example shows how to use the FastembedSparseDocumentEmbedder component to embed a list of documents.

# TODO: Once we have a proper SparseEmbeddingRetriever, we should replace this naive example with a more realistic one,
# involving indexing and retrieval of documents.

from haystack import Document
from haystack_integrations.components.embedders.fastembed import FastembedSparseDocumentEmbedder

document_list = [
Document(
content="Oxidative stress generated within inflammatory joints can produce autoimmune phenomena and joint destruction. Radical species with oxidative activity, including reactive nitrogen species, represent mediators of inflammation and cartilage damage.",
meta={
"pubid": "25,445,628",
"long_answer": "yes",
},
),
Document(
content="Plasma levels of pancreatic polypeptide (PP) rise upon food intake. Although other pancreatic islet hormones, such as insulin and glucagon, have been extensively investigated, PP secretion and actions are still poorly understood.",
meta={
"pubid": "25,445,712",
"long_answer": "yes",
},
),
]

document_embedder = FastembedSparseDocumentEmbedder()
document_embedder.warm_up()
documents_with_embeddings = document_embedder.run(document_list)["documents"]

for doc in documents_with_embeddings:
print(f"Document Text: {doc.content}")
print(f"Document Sparse Embedding: {doc.sparse_embedding.to_dict()}")
2 changes: 2 additions & 0 deletions integrations/fastembed/pydoc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ loaders:
[
"haystack_integrations.components.embedders.fastembed.fastembed_document_embedder",
"haystack_integrations.components.embedders.fastembed.fastembed_text_embedder",
"haystack_integrations.components.embedders.fastembed.fastembed_sparse_document_embedder",
"haystack_integrations.components.embedders.fastembed.fastembed_sparse_text_embedder"
]
ignore_when_discovered: ["__init__"]
processors:
Expand Down
2 changes: 1 addition & 1 deletion integrations/fastembed/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ ban-relative-imports = "parents"
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]
# examples can contain "print" commands
"examples/**/*" = ["T201"]
"examples/**/*" = ["T201", "E501"]

[tool.coverage.run]
source = ["haystack_integrations"]
Expand Down

0 comments on commit 1a8c707

Please sign in to comment.