From 564e3415135fa16283e8c87c66619c287ecee24f Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Mon, 4 Mar 2024 17:25:29 +0100 Subject: [PATCH] attending PR comments --- .../gradient/gradient_document_embedder.py | 19 ++++++++++--------- .../gradient/gradient_text_embedder.py | 11 +++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_document_embedder.py b/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_document_embedder.py index c5dded9f1..56aeb0a0a 100644 --- a/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_document_embedder.py +++ b/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_document_embedder.py @@ -28,11 +28,12 @@ class GradientDocumentEmbedder: Usage example: ```python - from haystack_integrations.components.embedders.gradient import GradientDocumentEmbedder - from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever from haystack import Pipeline + from haystack.document_stores.in_memory import InMemoryDocumentStore + from haystack.components.writers import DocumentWriter + from haystack import Document - embedder = GradientDocumentEmbedder(model="bge_large") + from haystack_integrations.components.embedders.gradient import GradientDocumentEmbedder documents = [ Document(content="My name is Jean and I live in Paris."), @@ -40,12 +41,12 @@ class GradientDocumentEmbedder: Document(content="My name is Giorgio and I live in Rome."), ] - p = Pipeline() - p.add_component(embedder, name="document_embedder") - p.add_component(instance=GradientDocumentEmbedder(), name="document_embedder") - p.add_component(instance=DocumentWriter(document_store=InMemoryDocumentStore()), name="document_writer") - p.connect("document_embedder", "document_writer") - p.run(data={"document_embedder": {"documents": documents}}) + indexing_pipeline = Pipeline() + indexing_pipeline.add_component(instance=GradientDocumentEmbedder(), name="document_embedder") + indexing_pipeline.add_component(instance=DocumentWriter(document_store=InMemoryDocumentStore()), name="document_writer") + indexing_pipeline.connect("document_embedder", "document_writer") + indexing_pipeline.run({"document_embedder": {"documents": documents}}) + >>> {'document_writer': {'documents_written': 3}} ``` """ diff --git a/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_text_embedder.py b/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_text_embedder.py index a33ad3d40..77b2d6250 100644 --- a/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_text_embedder.py +++ b/integrations/gradient/src/haystack_integrations/components/embedders/gradient/gradient_text_embedder.py @@ -14,14 +14,17 @@ class GradientTextEmbedder: ```python from haystack_integrations.components.embedders.gradient import GradientTextEmbedder from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever + from haystack.document_stores.in_memory import InMemoryDocumentStore from haystack import Pipeline - embedder = GradientTextEmbedder(model="bge_large") + embedder = p = Pipeline() - p.add_component(instance=embedder, name="text_embedder") - p.add_component(instance=InMemoryEmbeddingRetriever(document_store=InMemoryDocumentStore()), name="retriever") + p.add_component("text_embedder", GradientTextEmbedder(model="bge-large")) + p.add_component("retriever", InMemoryEmbeddingRetriever(document_store=InMemoryDocumentStore())) p.connect("text_embedder", "retriever") - p.run("embed me!!!") + p.run(data={"text_embedder": {"text":"You can embed me put I'll return no matching documents"}}) + >>> No Documents found with embeddings. Returning empty list. To generate embeddings, use a DocumentEmbedder. + >>> {'retriever': {'documents': []}} ``` """