From bee50abbcf505fda19c6ab09fb55e28716b7cf1b Mon Sep 17 00:00:00 2001 From: AnshuS1310 Date: Mon, 18 May 2026 16:37:41 +0530 Subject: [PATCH 1/2] feat(llama_hub): refactor connector to support LlamaIndex v0.14+ direct imports --- integrations/llama_hub/=0.10.0 | Bin 0 -> 26256 bytes integrations/llama_hub/CHANGELOG.md | 7 + integrations/llama_hub/LICENSE.txt | 201 ++++++++++++++++++ integrations/llama_hub/README.md | 15 ++ .../examples/llamahub_connector_example.py | 29 +++ integrations/llama_hub/mypy.ini | 4 + .../llama_hub/pydoc/config_docusaurus.yml | 14 ++ integrations/llama_hub/pyproject.toml | 34 +++ .../connectors/llamahub/__init__.py | 7 + .../connectors/llamahub/connector.py | 59 +++++ .../components/connectors/llamahub/py.typed | 0 integrations/llama_hub/tests/__init__.py | 2 + .../llama_hub/tests/test_connector.py | 61 ++++++ 13 files changed, 433 insertions(+) create mode 100644 integrations/llama_hub/=0.10.0 create mode 100644 integrations/llama_hub/CHANGELOG.md create mode 100644 integrations/llama_hub/LICENSE.txt create mode 100644 integrations/llama_hub/README.md create mode 100644 integrations/llama_hub/examples/llamahub_connector_example.py create mode 100644 integrations/llama_hub/mypy.ini create mode 100644 integrations/llama_hub/pydoc/config_docusaurus.yml create mode 100644 integrations/llama_hub/pyproject.toml create mode 100644 integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/__init__.py create mode 100644 integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/connector.py create mode 100644 integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/py.typed create mode 100644 integrations/llama_hub/tests/__init__.py create mode 100644 integrations/llama_hub/tests/test_connector.py diff --git a/integrations/llama_hub/=0.10.0 b/integrations/llama_hub/=0.10.0 new file mode 100644 index 0000000000000000000000000000000000000000..4c098d73aeca158afba5d4df4be26da016462cb0 GIT binary patch literal 26256 zcmeI5U2hvz5Qfh+692*66@;rePSX^nNKkH&id0c?MNySFY3jyyOx9Hsemw9#XMD2j zc-Jk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GELOG.md b/integrations/llama_hub/CHANGELOG.md new file mode 100644 index 0000000000..0c83923fb7 --- /dev/null +++ b/integrations/llama_hub/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +## [integrations/llamahub-v0.1.0] - 2026-05-18 + +### 🚀 Features + +- Add LlamaHubConnector for dynamic data loader integration (#1121) \ No newline at end of file diff --git a/integrations/llama_hub/LICENSE.txt b/integrations/llama_hub/LICENSE.txt new file mode 100644 index 0000000000..6134ab324f --- /dev/null +++ b/integrations/llama_hub/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2023-present deepset GmbH + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/integrations/llama_hub/README.md b/integrations/llama_hub/README.md new file mode 100644 index 0000000000..3a6ffe46d9 --- /dev/null +++ b/integrations/llama_hub/README.md @@ -0,0 +1,15 @@ +# llamahub-haystack + +[![PyPI - Version](https://img.shields.io/pypi/v/llamahub-haystack.svg)](https://pypi.org/project/llamahub-haystack) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/llamahub-haystack.svg)](https://pypi.org/project/llamahub-haystack) + +- [Integration page](https://haystack.deepset.ai/integrations/llamahub) +- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/llamahub/CHANGELOG.md) + +--- + +## Contributing + +Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md). + +To run integration tests locally, you need to ensure your local environment has the required dependencies installed via Hatch and that network dependencies for specific LlamaHub readers are mocked appropriately in the unit test suite. \ No newline at end of file diff --git a/integrations/llama_hub/examples/llamahub_connector_example.py b/integrations/llama_hub/examples/llamahub_connector_example.py new file mode 100644 index 0000000000..1a52856713 --- /dev/null +++ b/integrations/llama_hub/examples/llamahub_connector_example.py @@ -0,0 +1,29 @@ +from haystack import Pipeline +from haystack_integrations.components.connectors.llamahub import LlamaHubConnector + +def main(): + print("Initializing Haystack 2.0 Pipeline layout...") + pipeline = Pipeline() + + # 1. Add our custom dynamic connector, identifying the target LlamaHub loader class + pipeline.add_component( + "loader", + LlamaHubConnector(reader_module="llama_index.readers.web",reader_class="SimpleWebPageReader") + ) + + print("Executing pipeline processing stream...") + # 2. Run the pipeline passing parameters expected by SimpleWebPageReader's load_data method + response = pipeline.run({ + "loader": {"urls": ["https://example.com"]} + }) + + # 3. Parse and print structural layout output results + documents = response["loader"]["documents"] + print(f"\nSuccess! Processed {len(documents)} document(s).") + for doc in documents: + print(f"--- Document Content Snippet ---") + print(doc.content[:200] + "...") + print(f"Metadata properties: {doc.meta}\n") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/integrations/llama_hub/mypy.ini b/integrations/llama_hub/mypy.ini new file mode 100644 index 0000000000..ba3e75552c --- /dev/null +++ b/integrations/llama_hub/mypy.ini @@ -0,0 +1,4 @@ +[mypy] +ignore_missing_imports = True +explicit_package_bases = True +mypy_path = src \ No newline at end of file diff --git a/integrations/llama_hub/pydoc/config_docusaurus.yml b/integrations/llama_hub/pydoc/config_docusaurus.yml new file mode 100644 index 0000000000..c0a984fa73 --- /dev/null +++ b/integrations/llama_hub/pydoc/config_docusaurus.yml @@ -0,0 +1,14 @@ +# Documentation generation profile for llamahub-haystack +loaders: + - type: haystack_pydoc_tools.loaders.GitRegistryLoader + options: + project_name: llamahub-haystack + +processors: + - type: haystack_pydoc_tools.processors.DocstringProcessor + +renderers: + - type: haystack_pydoc_tools.renderers.DocusaurusRenderer + options: + excerpt: A unified connector component wrapping arbitrary LlamaHub data readers cleanly for native deployment inside Haystack 2.0 processing pipelines. + sidebar_label: LlamaHub Connector \ No newline at end of file diff --git a/integrations/llama_hub/pyproject.toml b/integrations/llama_hub/pyproject.toml new file mode 100644 index 0000000000..d69eae9cc3 --- /dev/null +++ b/integrations/llama_hub/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "llamahub-haystack" +dynamic = ["version"] +description = "A Haystack 2.0 integration to use LlamaHub data loaders inside pipelines." +readme = "README.md" +requires-python = ">=3.8" +license = "Apache-2.0" +dependencies = [ + "haystack-ai>=2.0.0", + "llama-index-core>=0.10.0", +] + +[tool.hatch.version] +path = "src/haystack_integrations/components/connectors/llamahub/__init__.py" + +[tool.hatch.build.targets.wheel] +packages = ["src/haystack_integrations"] + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "mypy", + "black", + "ruff", +] + +[tool.hatch.envs.default.scripts] +unit = "pytest tests/" +types = "mypy src/haystack_integrations" +fmt = ["black src/ tests/", "ruff check --fix src/ tests/"] \ No newline at end of file diff --git a/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/__init__.py b/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/__init__.py new file mode 100644 index 0000000000..b96c3a2993 --- /dev/null +++ b/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/__init__.py @@ -0,0 +1,7 @@ +from haystack_integrations.components.connectors.llamahub.connector import ( + LlamaHubConnector, +) + +__version__ = "0.1.0" + +__all__ = ["LlamaHubConnector"] diff --git a/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/connector.py b/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/connector.py new file mode 100644 index 0000000000..408c545f9f --- /dev/null +++ b/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/connector.py @@ -0,0 +1,59 @@ +import importlib +from typing import Any, Dict, List, Optional +from haystack import Document, component + + +@component +class LlamaHubConnector: + """ + A unified components wrapper enabling the execution of modern, explicitly installed + LlamaIndex readers directly within native Haystack 2.0 pipelines. + """ + + def __init__( + self, + reader_module: str, + reader_class: str, + reader_kwargs: Optional[Dict[str, Any]] = None, + ): + """ + :param reader_module: The specific sub-package name (e.g., 'llama_index.readers.web'). + :param reader_class: The class name inside that module (e.g., 'SimpleWebPageReader'). + :param reader_kwargs: Initialization arguments to pass to the target reader. + """ + if not reader_module or not reader_class: + raise ValueError( + "Parameters 'reader_module' and 'reader_class' cannot be empty." + ) + + self.reader_module = reader_module + self.reader_class = reader_class + self.reader_kwargs = reader_kwargs or {} + + # Dynamically import the explicitly installed reader package + try: + module = importlib.import_module(self.reader_module) + self._loader_class = getattr(module, self.reader_class) + except (ImportError, AttributeError) as e: + raise ImportError( + f"Failed to load '{self.reader_class}' from '{self.reader_module}'. " + f"Ensure you have run: pip install {self.reader_module.replace('_', '-')}" + ) from e + + self._loader_instance = self._loader_class(**self.reader_kwargs) + + @component.output_types(documents=List[Document]) + def run(self, **kwargs: Any) -> Dict[str, List[Document]]: + # Invoke data extraction from the loaded LlamaIndex reader instance + llama_docs = self._loader_instance.load_data(**kwargs) + + haystack_docs: List[Document] = [] + for doc in llama_docs: + text_content = getattr(doc, "text", "") or getattr(doc, "content", "") + meta_payload = getattr(doc, "metadata", {}) or {} + + haystack_docs.append( + Document(content=text_content, meta=dict(meta_payload)) + ) + + return {"documents": haystack_docs} diff --git a/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/py.typed b/integrations/llama_hub/src/haystack_integrations/components/connectors/llamahub/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/integrations/llama_hub/tests/__init__.py b/integrations/llama_hub/tests/__init__.py new file mode 100644 index 0000000000..1466c0cbf0 --- /dev/null +++ b/integrations/llama_hub/tests/__init__.py @@ -0,0 +1,2 @@ +# This file is intentionally left empty to mark the tests directory +# as a valid Python package namespace for pytest. diff --git a/integrations/llama_hub/tests/test_connector.py b/integrations/llama_hub/tests/test_connector.py new file mode 100644 index 0000000000..c349b897c8 --- /dev/null +++ b/integrations/llama_hub/tests/test_connector.py @@ -0,0 +1,61 @@ +from unittest.mock import MagicMock, patch +from haystack import Document +from haystack_integrations.components.connectors.llamahub.connector import ( + LlamaHubConnector, +) + + +class MockLlamaIndexDocument: + + def __init__(self, text, metadata): + self.text = text + self.metadata = metadata + + +def test_connector_initialization(): + """Verify the connector dynamically imports explicitly installed reader classes.""" + with patch("importlib.import_module") as mock_import: + mock_module = MagicMock() + mock_class = MagicMock() + setattr(mock_module, "SimpleWebPageReader", mock_class) + mock_import.return_value = mock_module + + connector = LlamaHubConnector( + reader_module="llama_index.readers.web", + reader_class="SimpleWebPageReader", + reader_kwargs={"val": "test"}, + ) + + assert connector.reader_module == "llama_index.readers.web" + assert connector.reader_class == "SimpleWebPageReader" + mock_import.assert_called_once_with("llama_index.readers.web") + mock_class.assert_called_once_with(val="test") + + +def test_connector_run_execution(): + """Verify that run() successfully converts data node structures to Haystack 2.0 Documents.""" + with patch("importlib.import_module") as mock_import: + mock_module = MagicMock() + mock_instance = MagicMock() + mock_instance.load_data.return_value = [ + MockLlamaIndexDocument( + text="Hello Modern Integration", + metadata={"url": "https://example.com"}, + ) + ] + mock_class = MagicMock(return_value=mock_instance) + setattr(mock_module, "SimpleWebPageReader", mock_class) + mock_import.return_value = mock_module + + connector = LlamaHubConnector( + reader_module="llama_index.readers.web", + reader_class="SimpleWebPageReader", + ) + results = connector.run(urls=["https://example.com"]) + + assert "documents" in results + documents = results["documents"] + assert len(documents) == 1 + assert isinstance(documents[0], Document) + assert documents[0].content == "Hello Modern Integration" + assert documents[0].meta["url"] == "https://example.com" From 79c774c0af9a086303837dd31c2875eae8554957 Mon Sep 17 00:00:00 2001 From: anshuS1310 Date: Mon, 18 May 2026 16:46:11 +0530 Subject: [PATCH 2/2] Update pyproject.toml --- integrations/llama_hub/pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integrations/llama_hub/pyproject.toml b/integrations/llama_hub/pyproject.toml index d69eae9cc3..d70b7e8178 100644 --- a/integrations/llama_hub/pyproject.toml +++ b/integrations/llama_hub/pyproject.toml @@ -31,4 +31,5 @@ dependencies = [ [tool.hatch.envs.default.scripts] unit = "pytest tests/" types = "mypy src/haystack_integrations" -fmt = ["black src/ tests/", "ruff check --fix src/ tests/"] \ No newline at end of file +fmt = ["black src/ tests/", "ruff check --fix src/ tests/"] +docs = "pydoc-markdown pydoc/config.yml"