chroma-haystack 5.0.0__tar.gz → 5.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/CHANGELOG.md +18 -0
  2. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/PKG-INFO +1 -1
  3. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/document_store.py +29 -9
  4. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/filters.py +2 -3
  5. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/test_document_store.py +59 -0
  6. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/test_document_store_async.py +13 -0
  7. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/test_filters.py +41 -0
  8. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/.gitignore +0 -0
  9. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/LICENSE.txt +0 -0
  10. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/README.md +0 -0
  11. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_01.txt +0 -0
  12. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_02.txt +0 -0
  13. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_03.txt +0 -0
  14. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_04.txt +0 -0
  15. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_05.txt +0 -0
  16. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_06.txt +0 -0
  17. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_07.txt +0 -0
  18. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_08.txt +0 -0
  19. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_09.txt +0 -0
  20. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_10.txt +0 -0
  21. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_11.txt +0 -0
  22. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_12.txt +0 -0
  23. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_20.txt +0 -0
  24. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_21.txt +0 -0
  25. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_22.txt +0 -0
  26. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_23.txt +0 -0
  27. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_24.txt +0 -0
  28. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_25.txt +0 -0
  29. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_26.txt +0 -0
  30. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_27.txt +0 -0
  31. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_28.txt +0 -0
  32. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_29.txt +0 -0
  33. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_30.txt +0 -0
  34. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_31.txt +0 -0
  35. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_32.txt +0 -0
  36. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_40.txt +0 -0
  37. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_41.txt +0 -0
  38. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_42.txt +0 -0
  39. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_43.txt +0 -0
  40. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_44.txt +0 -0
  41. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_45.txt +0 -0
  42. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_46.txt +0 -0
  43. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_50.txt +0 -0
  44. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_51.txt +0 -0
  45. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_52.txt +0 -0
  46. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/data/usr_90.txt +0 -0
  47. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/example/example.py +0 -0
  48. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/pydoc/config_docusaurus.yml +0 -0
  49. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/pyproject.toml +0 -0
  50. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/chroma/__init__.py +0 -0
  51. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/chroma/retriever.py +0 -0
  52. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/components/retrievers/py.typed +0 -0
  53. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/__init__.py +0 -0
  54. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/errors.py +0 -0
  55. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/chroma/utils.py +0 -0
  56. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/src/haystack_integrations/document_stores/py.typed +0 -0
  57. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/__init__.py +0 -0
  58. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/conftest.py +0 -0
  59. {chroma_haystack-5.0.0 → chroma_haystack-5.1.1}/tests/test_retriever.py +0 -0
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/chroma-v5.1.0] - 2026-11-11
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - *(chroma)* Distinguish metadata ID filters from document IDs (#4124)
8
+
9
+
10
+ ## [integrations/chroma-v5.0.0] - 2026-10-16
11
+
12
+ ### ⚙️ CI
13
+
14
+ - Improve changelog generation; fix existing changelogs (#3883)
15
+
16
+ ### 🧹 Chores
17
+
18
+ - [**breaking**] Drop Python 3.10 support (#4105)
19
+
20
+
3
21
  ## [integrations/chroma-v4.5.0] - 2026-09-01
4
22
 
5
23
  ### 🐛 Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: chroma-haystack
3
- Version: 5.0.0
3
+ Version: 5.1.1
4
4
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma#readme
5
5
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
6
6
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma
@@ -610,13 +610,15 @@ class ChromaDocumentStore:
610
610
  How to handle documents whose `id` already exists in the store:
611
611
  - `NONE` (default): treated as `FAIL`.
612
612
  - `OVERWRITE`: replace the existing document.
613
- - `SKIP`: keep the existing document and skip the new one.
613
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
614
+ `documents` is written once.
614
615
  - `FAIL`: raise `DuplicateDocumentError`.
615
616
 
616
617
  :raises ValueError:
617
618
  When input is not valid.
618
619
  :raises DuplicateDocumentError:
619
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
620
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
621
+ within `documents`.
620
622
 
621
623
  :returns:
622
624
  The number of documents written.
@@ -634,7 +636,8 @@ class ChromaDocumentStore:
634
636
  return 0
635
637
 
636
638
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
637
- existing_ids = set(self._collection.get(ids=[p["ids"][0] for p in chroma_payloads])["ids"])
639
+ existing = self._collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
640
+ existing_ids = set(existing["ids"])
638
641
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
639
642
  else:
640
643
  payloads_to_write = chroma_payloads
@@ -663,13 +666,15 @@ class ChromaDocumentStore:
663
666
  How to handle documents whose `id` already exists in the store:
664
667
  - `NONE` (default): treated as `FAIL`.
665
668
  - `OVERWRITE`: replace the existing document.
666
- - `SKIP`: keep the existing document and skip the new one.
669
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
670
+ `documents` is written once.
667
671
  - `FAIL`: raise `DuplicateDocumentError`.
668
672
 
669
673
  :raises ValueError:
670
674
  When input is not valid.
671
675
  :raises DuplicateDocumentError:
672
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
676
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
677
+ within `documents`.
673
678
 
674
679
  :returns:
675
680
  The number of documents written.
@@ -687,7 +692,7 @@ class ChromaDocumentStore:
687
692
  return 0
688
693
 
689
694
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
690
- existing = await self._async_collection.get(ids=[p["ids"][0] for p in chroma_payloads])
695
+ existing = await self._async_collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
691
696
  existing_ids = set(existing["ids"])
692
697
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
693
698
  else:
@@ -707,14 +712,29 @@ class ChromaDocumentStore:
707
712
  existing_ids: set[str],
708
713
  policy: DuplicatePolicy,
709
714
  ) -> list[dict[str, Any]]:
715
+ # an id repeated within the batch counts as a duplicate of its first occurrence
716
+ seen = set(existing_ids)
710
717
  if policy == DuplicatePolicy.FAIL:
711
- duplicates = [p["ids"][0] for p in payloads if p["ids"][0] in existing_ids]
718
+ duplicates = []
719
+ for p in payloads:
720
+ doc_id = p["ids"][0]
721
+ if doc_id in seen:
722
+ duplicates.append(doc_id)
723
+ seen.add(doc_id)
712
724
  if duplicates:
713
- msg = f"Documents with ids {duplicates} already exist in the document store."
725
+ msg = (
726
+ f"Documents with ids {duplicates} already exist in the document store or are repeated in the batch."
727
+ )
714
728
  raise DuplicateDocumentError(msg)
715
729
  return payloads
716
730
  if policy == DuplicatePolicy.SKIP:
717
- return [p for p in payloads if p["ids"][0] not in existing_ids]
731
+ to_write = []
732
+ for p in payloads:
733
+ doc_id = p["ids"][0]
734
+ if doc_id not in seen:
735
+ to_write.append(p)
736
+ seen.add(doc_id)
737
+ return to_write
718
738
  return payloads
719
739
 
720
740
  def delete_documents(self, document_ids: list[str]) -> None:
@@ -49,7 +49,6 @@ def _convert_filters(filters: dict[str, Any]) -> ChromaFilter:
49
49
  Separates filters into ids, metadata filters, and content filters to be passed to chroma as ids, where,
50
50
  and where_document clauses respectively.
51
51
  """
52
-
53
52
  ids = []
54
53
  where: dict[str, Any] = defaultdict(list)
55
54
  where_document: dict[str, Any] = defaultdict(list)
@@ -66,8 +65,8 @@ def _convert_filters(filters: dict[str, Any]) -> ChromaFilter:
66
65
  where_document.update(_create_where_document_filter(field, value))
67
66
  if where_document:
68
67
  continue
69
- # if field is "id", it'll be passed to Chroma's ids filter
70
- elif field == "id":
68
+ # Only the unprefixed id field targets Chroma document IDs.
69
+ elif field == "id" and filters.get("field") == "id":
71
70
  if "$eq" not in value or not value["$eq"]:
72
71
  msg = f"id filter only supports '==' operator, got {value}"
73
72
  raise ChromaDocumentStoreFilterError(msg)
@@ -10,6 +10,8 @@ from unittest import mock
10
10
  import pytest
11
11
  from chromadb.api.shared_system_client import SharedSystemClient
12
12
  from haystack.dataclasses import ByteStream, Document, SparseEmbedding
13
+ from haystack.document_stores.errors import DuplicateDocumentError
14
+ from haystack.document_stores.types import DuplicatePolicy
13
15
  from haystack.testing.document_store import (
14
16
  TEST_EMBEDDING_1,
15
17
  CountDocumentsByFilterTest,
@@ -314,6 +316,39 @@ class TestDocumentStore(
314
316
  get_func.return_value = embedding_function
315
317
  return ChromaDocumentStore(embedding_function="test_function", collection_name=str(uuid.uuid1()))
316
318
 
319
+ @pytest.mark.parametrize(
320
+ ("filters", "expected_ids"),
321
+ [
322
+ ({"field": "meta.id", "operator": "==", "value": "target"}, ["document-a"]),
323
+ ({"field": "meta.id", "operator": "!=", "value": "target"}, ["target"]),
324
+ ({"field": "id", "operator": "==", "value": "target"}, ["target"]),
325
+ ],
326
+ ids=["equal", "not_equal", "document_id"],
327
+ )
328
+ def test_metadata_id_filters_preserve_document_identity(
329
+ self, document_store: ChromaDocumentStore, filters, expected_ids
330
+ ):
331
+ document_store.write_documents(
332
+ [
333
+ Document(id="document-a", content="matching metadata", meta={"id": "target"}),
334
+ Document(id="target", content="nonmatching metadata", meta={"id": "other"}),
335
+ ]
336
+ )
337
+
338
+ assert [document.id for document in document_store.filter_documents(filters=filters)] == expected_ids
339
+
340
+ def test_delete_by_filter_metadata_id(self, document_store: ChromaDocumentStore):
341
+ document_store.write_documents(
342
+ [
343
+ Document(id="document-a", content="matching metadata", meta={"id": "target"}),
344
+ Document(id="target", content="nonmatching metadata", meta={"id": "other"}),
345
+ ]
346
+ )
347
+
348
+ filters = {"field": "meta.id", "operator": "==", "value": "target"}
349
+ assert document_store.delete_by_filter(filters=filters) == 1
350
+ assert [document.id for document in document_store.filter_documents()] == ["target"]
351
+
317
352
  def assert_documents_are_equal(self, received: list[Document], expected: list[Document]):
318
353
  """
319
354
  Assert that two lists of Documents are equal.
@@ -681,6 +716,30 @@ class TestDocumentStore(
681
716
  assert len(result_empty_filters) == 1
682
717
  assert len(result_empty_filters[0]) == 2
683
718
 
719
+ def test_write_documents_skip_drops_ids_repeated_in_the_batch(self, document_store: ChromaDocumentStore):
720
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
721
+
722
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 2
723
+ assert document_store.count_documents() == 2
724
+
725
+ @pytest.mark.parametrize("policy", [DuplicatePolicy.FAIL, DuplicatePolicy.NONE])
726
+ def test_write_documents_fail_raises_on_ids_repeated_in_the_batch(
727
+ self, document_store: ChromaDocumentStore, policy: DuplicatePolicy
728
+ ):
729
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
730
+
731
+ with pytest.raises(DuplicateDocumentError):
732
+ document_store.write_documents(docs, policy=policy)
733
+ assert document_store.count_documents() == 0
734
+
735
+ def test_write_documents_skip_with_repeated_ids_already_stored(self, document_store: ChromaDocumentStore):
736
+ stored = Document(content="refund policy")
737
+ document_store.write_documents([stored])
738
+
739
+ docs = [stored, Document(content="shipping"), stored]
740
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 1
741
+ assert document_store.count_documents() == 2
742
+
684
743
 
685
744
  @pytest.mark.integration
686
745
  class TestMetadataOperations:
@@ -9,6 +9,7 @@ from unittest import mock
9
9
 
10
10
  import pytest
11
11
  from haystack.dataclasses import Document
12
+ from haystack.document_stores.types import DuplicatePolicy
12
13
  from haystack.testing.document_store import TEST_EMBEDDING_1
13
14
  from haystack.testing.document_store_async import (
14
15
  CountDocumentsAsyncTest,
@@ -44,6 +45,18 @@ class TestDocumentStoreAsyncUnit:
44
45
  with pytest.raises(ValueError, match="Invalid client_settings"):
45
46
  await store._ensure_initialized_async()
46
47
 
48
+ async def test_write_documents_async_skip_looks_up_each_id_once(self):
49
+ store = ChromaDocumentStore(host="localhost", port=8000)
50
+ collection = mock.AsyncMock()
51
+ collection.get.return_value = {"ids": []}
52
+ store._async_collection = collection
53
+ store._ensure_initialized_async = mock.AsyncMock() # type: ignore[method-assign]
54
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
55
+
56
+ assert await store.write_documents_async(docs, policy=DuplicatePolicy.SKIP) == 2
57
+ collection.get.assert_awaited_once_with(ids=[docs[0].id, docs[1].id])
58
+ assert collection.add.await_count == 2
59
+
47
60
 
48
61
  @pytest.mark.skipif(
49
62
  sys.platform == "win32",
@@ -51,3 +51,44 @@ def test_parse_logical_condition_errors(condition, match):
51
51
  def test_parse_comparison_condition_errors(condition, match):
52
52
  with pytest.raises(ChromaDocumentStoreFilterError, match=match):
53
53
  _parse_comparison_condition(condition)
54
+
55
+
56
+ @pytest.mark.parametrize(
57
+ ("operator", "value", "chroma_operator"),
58
+ [
59
+ ("==", "target", "$eq"),
60
+ ("!=", "target", "$ne"),
61
+ ("in", ["target"], "$in"),
62
+ ("not in", ["target"], "$nin"),
63
+ ("==", "", "$eq"),
64
+ ],
65
+ )
66
+ def test_metadata_id_filters_keep_metadata_comparisons(operator, value, chroma_operator):
67
+ result = _convert_filters({"field": "meta.id", "operator": operator, "value": value})
68
+
69
+ assert result.ids == []
70
+ assert result.where == {"id": {chroma_operator: value}}
71
+ assert result.where_document is None
72
+
73
+
74
+ def test_document_id_filter_uses_ids():
75
+ result = _convert_filters({"field": "id", "operator": "==", "value": "target"})
76
+
77
+ assert result.ids == ["target"]
78
+ assert result.where is None
79
+ assert result.where_document is None
80
+
81
+
82
+ @pytest.mark.parametrize(
83
+ ("condition", "category"),
84
+ [
85
+ ({"field": "meta.id", "operator": "in", "value": "target"}, "metadata filter"),
86
+ ({"field": "content", "operator": "contains", "value": 123}, "document content filter"),
87
+ ],
88
+ ids=["invalid_metadata_membership", "invalid_content_value"],
89
+ )
90
+ def test_invalid_filters_wrap_chroma_validation_errors(condition, category):
91
+ with pytest.raises(ChromaDocumentStoreFilterError, match=f"Invalid '{category}'") as exception_info:
92
+ _convert_filters(condition)
93
+
94
+ assert isinstance(exception_info.value.__cause__, ValueError)