diff --git a/integrations/chroma/example/example.py b/integrations/chroma/example/example.py index a1155b216..19763742d 100644 --- a/integrations/chroma/example/example.py +++ b/integrations/chroma/example/example.py @@ -6,8 +6,8 @@ from haystack.components.converters import TextFileToDocument from haystack.components.writers import DocumentWriter -from chroma_haystack import ChromaDocumentStore -from chroma_haystack.retriever import ChromaQueryRetriever +from haystack_integrations.document_stores.chroma import ChromaDocumentStore +from haystack_integrations.components.retrievers.chroma import ChromaQueryRetriever HERE = Path(__file__).resolve().parent file_paths = [HERE / "data" / Path(name) for name in os.listdir("data")] diff --git a/integrations/chroma/pyproject.toml b/integrations/chroma/pyproject.toml index fdabcf245..2e531005b 100644 --- a/integrations/chroma/pyproject.toml +++ b/integrations/chroma/pyproject.toml @@ -32,6 +32,9 @@ Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/m Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues" Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma" +[tool.hatch.build.targets.wheel] +packages = ["src/haystack_integrations"] + [tool.hatch.version] source = "vcs" tag-pattern = 'integrations\/chroma-v(?P.*)' @@ -69,7 +72,7 @@ dependencies = [ "numpy", # we need the stubs from the main package ] [tool.hatch.envs.lint.scripts] -typing = "mypy --install-types --non-interactive {args:src/chroma_haystack tests}" +typing = "mypy --install-types --non-interactive --explicit-package-bases {args:src/ tests}" style = [ "ruff {args:.}", "black --check --diff {args:.}", @@ -141,26 +144,25 @@ unfixable = [ exclude = ["example"] [tool.ruff.isort] -known-first-party = ["chroma_haystack"] +known-first-party = ["src"] [tool.ruff.flake8-tidy-imports] -ban-relative-imports = "all" +ban-relative-imports = "parents" [tool.ruff.per-file-ignores] # Tests can use magic values, assertions, and relative imports "tests/**/*" = ["PLR2004", "S101", "TID252"] [tool.coverage.run] -source_pkgs = ["chroma_haystack", "tests"] +source_pkgs = ["src", "tests"] branch = true parallel = true omit = [ - "src/chroma_haystack/__about__.py", "example" ] [tool.coverage.paths] -chroma_haystack = ["src/chroma_haystack", "*/chroma-haystack/src/chroma_haystack"] +chroma_haystack = ["src/haystack_integrations", "*/chroma-haystack/src/chroma_haystack"] tests = ["tests"] [tool.coverage.report] @@ -181,6 +183,7 @@ markers = [ module = [ "chromadb.*", "haystack.*", + "haystack_integrations.*", "pytest.*" ] ignore_missing_imports = true diff --git a/integrations/chroma/src/chroma_haystack/__init__.py b/integrations/chroma/src/chroma_haystack/__init__.py deleted file mode 100644 index b3581e87f..000000000 --- a/integrations/chroma/src/chroma_haystack/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2023-present John Doe -# -# SPDX-License-Identifier: Apache-2.0 -from chroma_haystack.document_store import ChromaDocumentStore - -__all__ = ["ChromaDocumentStore"] diff --git a/integrations/chroma/src/haystack_integrations/components/retrievers/chroma/__init__.py b/integrations/chroma/src/haystack_integrations/components/retrievers/chroma/__init__.py new file mode 100644 index 000000000..e449f0067 --- /dev/null +++ b/integrations/chroma/src/haystack_integrations/components/retrievers/chroma/__init__.py @@ -0,0 +1,3 @@ +from .retriever import ChromaEmbeddingRetriever, ChromaQueryRetriever, ChromaSingleQueryRetriever + +__all__ = ["ChromaQueryRetriever", "ChromaEmbeddingRetriever", "ChromaSingleQueryRetriever"] diff --git a/integrations/chroma/src/chroma_haystack/retriever.py b/integrations/chroma/src/haystack_integrations/components/retrievers/chroma/retriever.py similarity index 97% rename from integrations/chroma/src/chroma_haystack/retriever.py rename to integrations/chroma/src/haystack_integrations/components/retrievers/chroma/retriever.py index 70dae7a6d..f4b3909c6 100644 --- a/integrations/chroma/src/chroma_haystack/retriever.py +++ b/integrations/chroma/src/haystack_integrations/components/retrievers/chroma/retriever.py @@ -4,8 +4,7 @@ from typing import Any, Dict, List, Optional from haystack import Document, component, default_from_dict, default_to_dict - -from chroma_haystack import ChromaDocumentStore +from haystack_integrations.document_stores.chroma import ChromaDocumentStore @component diff --git a/integrations/chroma/src/haystack_integrations/document_stores/chroma/__init__.py b/integrations/chroma/src/haystack_integrations/document_stores/chroma/__init__.py new file mode 100644 index 000000000..c3a69fb17 --- /dev/null +++ b/integrations/chroma/src/haystack_integrations/document_stores/chroma/__init__.py @@ -0,0 +1,3 @@ +from .document_store import ChromaDocumentStore + +__all__ = ["ChromaDocumentStore"] diff --git a/integrations/chroma/src/chroma_haystack/document_store.py b/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py similarity index 98% rename from integrations/chroma/src/chroma_haystack/document_store.py rename to integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py index ad4777856..1b11d047c 100644 --- a/integrations/chroma/src/chroma_haystack/document_store.py +++ b/integrations/chroma/src/haystack_integrations/document_stores/chroma/document_store.py @@ -9,10 +9,10 @@ import numpy as np from chromadb.api.types import GetResult, QueryResult, validate_where, validate_where_document from haystack.dataclasses import Document -from haystack.document_stores.protocol import DuplicatePolicy +from haystack.document_stores.types import DuplicatePolicy -from chroma_haystack.errors import ChromaDocumentStoreFilterError -from chroma_haystack.utils import get_embedding_function +from .errors import ChromaDocumentStoreFilterError +from .utils import get_embedding_function logger = logging.getLogger(__name__) diff --git a/integrations/chroma/src/chroma_haystack/errors.py b/integrations/chroma/src/haystack_integrations/document_stores/chroma/errors.py similarity index 100% rename from integrations/chroma/src/chroma_haystack/errors.py rename to integrations/chroma/src/haystack_integrations/document_stores/chroma/errors.py diff --git a/integrations/chroma/src/chroma_haystack/utils.py b/integrations/chroma/src/haystack_integrations/document_stores/chroma/utils.py similarity index 95% rename from integrations/chroma/src/chroma_haystack/utils.py rename to integrations/chroma/src/haystack_integrations/document_stores/chroma/utils.py index b4c683590..b1a354af4 100644 --- a/integrations/chroma/src/chroma_haystack/utils.py +++ b/integrations/chroma/src/haystack_integrations/document_stores/chroma/utils.py @@ -15,7 +15,7 @@ Text2VecEmbeddingFunction, ) -from chroma_haystack.errors import ChromaDocumentStoreConfigError +from .errors import ChromaDocumentStoreConfigError FUNCTION_REGISTRY = { "default": DefaultEmbeddingFunction, diff --git a/integrations/chroma/tests/test_document_store.py b/integrations/chroma/tests/test_document_store.py index 90761f2e5..506920ac2 100644 --- a/integrations/chroma/tests/test_document_store.py +++ b/integrations/chroma/tests/test_document_store.py @@ -14,8 +14,7 @@ DeleteDocumentsTest, LegacyFilterDocumentsTest, ) - -from chroma_haystack.document_store import ChromaDocumentStore +from haystack_integrations.document_stores.chroma import ChromaDocumentStore class _TestEmbeddingFunction(EmbeddingFunction): @@ -42,7 +41,9 @@ def document_store(self) -> ChromaDocumentStore: This is the most basic requirement for the child class: provide an instance of this document store so the base class can use it. """ - with mock.patch("chroma_haystack.document_store.get_embedding_function") as get_func: + with mock.patch( + "haystack_integrations.document_stores.chroma.document_store.get_embedding_function" + ) as get_func: get_func.return_value = _TestEmbeddingFunction() return ChromaDocumentStore(embedding_function="test_function", collection_name=str(uuid.uuid1())) diff --git a/integrations/chroma/tests/test_retriever.py b/integrations/chroma/tests/test_retriever.py index c82b8ee0b..780b4144a 100644 --- a/integrations/chroma/tests/test_retriever.py +++ b/integrations/chroma/tests/test_retriever.py @@ -2,9 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 import pytest - -from chroma_haystack.document_store import ChromaDocumentStore -from chroma_haystack.retriever import ChromaQueryRetriever +from haystack_integrations.components.retrievers.chroma import ChromaQueryRetriever +from haystack_integrations.document_stores.chroma import ChromaDocumentStore @pytest.mark.integration @@ -14,7 +13,7 @@ def test_retriever_to_json(request): ) retriever = ChromaQueryRetriever(ds, filters={"foo": "bar"}, top_k=99) assert retriever.to_dict() == { - "type": "chroma_haystack.retriever.ChromaQueryRetriever", + "type": "haystack_integrations.components.retrievers.chroma.retriever.ChromaQueryRetriever", "init_parameters": { "filters": {"foo": "bar"}, "top_k": 99, @@ -30,7 +29,7 @@ def test_retriever_to_json(request): @pytest.mark.integration def test_retriever_from_json(request): data = { - "type": "chroma_haystack.retriever.ChromaQueryRetriever", + "type": "haystack_integrations.components.retrievers.chroma.retriever.ChromaQueryRetriever", "init_parameters": { "filters": {"bar": "baz"}, "top_k": 42,