chroma-haystack 5.1.0__tar.gz → 5.1.2__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.1.0 → chroma_haystack-5.1.2}/CHANGELOG.md +14 -0
  2. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/PKG-INFO +1 -1
  3. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/chroma/document_store.py +52 -22
  4. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/test_document_store.py +49 -0
  5. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/test_document_store_async.py +13 -0
  6. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/.gitignore +0 -0
  7. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/LICENSE.txt +0 -0
  8. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/README.md +0 -0
  9. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_01.txt +0 -0
  10. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_02.txt +0 -0
  11. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_03.txt +0 -0
  12. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_04.txt +0 -0
  13. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_05.txt +0 -0
  14. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_06.txt +0 -0
  15. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_07.txt +0 -0
  16. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_08.txt +0 -0
  17. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_09.txt +0 -0
  18. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_10.txt +0 -0
  19. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_11.txt +0 -0
  20. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_12.txt +0 -0
  21. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_20.txt +0 -0
  22. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_21.txt +0 -0
  23. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_22.txt +0 -0
  24. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_23.txt +0 -0
  25. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_24.txt +0 -0
  26. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_25.txt +0 -0
  27. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_26.txt +0 -0
  28. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_27.txt +0 -0
  29. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_28.txt +0 -0
  30. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_29.txt +0 -0
  31. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_30.txt +0 -0
  32. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_31.txt +0 -0
  33. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_32.txt +0 -0
  34. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_40.txt +0 -0
  35. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_41.txt +0 -0
  36. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_42.txt +0 -0
  37. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_43.txt +0 -0
  38. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_44.txt +0 -0
  39. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_45.txt +0 -0
  40. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_46.txt +0 -0
  41. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_50.txt +0 -0
  42. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_51.txt +0 -0
  43. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_52.txt +0 -0
  44. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/data/usr_90.txt +0 -0
  45. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/example/example.py +0 -0
  46. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/pydoc/config_docusaurus.yml +0 -0
  47. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/pyproject.toml +0 -0
  48. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/components/retrievers/chroma/__init__.py +0 -0
  49. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/components/retrievers/chroma/retriever.py +0 -0
  50. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/components/retrievers/py.typed +0 -0
  51. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/chroma/__init__.py +0 -0
  52. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/chroma/errors.py +0 -0
  53. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/chroma/filters.py +0 -0
  54. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/chroma/utils.py +0 -0
  55. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/src/haystack_integrations/document_stores/py.typed +0 -0
  56. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/__init__.py +0 -0
  57. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/conftest.py +0 -0
  58. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/test_filters.py +0 -0
  59. {chroma_haystack-5.1.0 → chroma_haystack-5.1.2}/tests/test_retriever.py +0 -0
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/chroma-v5.1.1] - 2026-11-19
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - Chroma - handle IDs repeated within a write_documents batch (#4241)
8
+
9
+
10
+ ## [integrations/chroma-v5.1.0] - 2026-11-11
11
+
12
+ ### 🐛 Bug Fixes
13
+
14
+ - *(chroma)* Distinguish metadata ID filters from document IDs (#4124)
15
+
16
+
3
17
  ## [integrations/chroma-v5.0.0] - 2026-10-16
4
18
 
5
19
  ### ⚙️ CI
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: chroma-haystack
3
- Version: 5.1.0
3
+ Version: 5.1.2
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
@@ -478,18 +478,37 @@ class ChromaDocumentStore:
478
478
  return self._get_result_to_documents(result)
479
479
 
480
480
  @staticmethod
481
- def _filter_metadata(meta: dict[str, Any]) -> dict[str, str | int | float | bool | None]:
481
+ def _is_supported_metadata_value(value: Any) -> bool:
482
+ """
483
+ Checks whether Chroma can store a metadata value.
484
+
485
+ Chroma stores `str`, `int`, `float` and `bool` values, and non-empty lists whose items all share one of those
486
+ types.
487
+ """
488
+ if isinstance(value, SUPPORTED_TYPES_FOR_METADATA_VALUES):
489
+ return True
490
+ return (
491
+ isinstance(value, list)
492
+ and len(value) > 0
493
+ and type(value[0]) in SUPPORTED_TYPES_FOR_METADATA_VALUES
494
+ and all(isinstance(item, type(value[0])) for item in value)
495
+ )
496
+
497
+ @staticmethod
498
+ def _filter_metadata(
499
+ meta: dict[str, Any],
500
+ ) -> dict[str, SUPPORTED_METADATA_VALUES_TYPE | list[SUPPORTED_METADATA_VALUES_TYPE] | None]:
482
501
  """
483
502
  Filters metadata to only include supported types for Chroma.
484
503
 
485
504
  returns:
486
505
  A new dictionary with only valid metadata values.
487
506
  """
488
- valid_meta: dict[str, str | int | float | bool | None] = {}
507
+ valid_meta: dict[str, SUPPORTED_METADATA_VALUES_TYPE | list[SUPPORTED_METADATA_VALUES_TYPE] | None] = {}
489
508
  discarded_keys = []
490
509
 
491
510
  for k, v in meta.items():
492
- if v is None or isinstance(v, SUPPORTED_TYPES_FOR_METADATA_VALUES):
511
+ if v is None or ChromaDocumentStore._is_supported_metadata_value(v):
493
512
  valid_meta[k] = v
494
513
  else:
495
514
  discarded_keys.append(k)
@@ -557,16 +576,7 @@ class ChromaDocumentStore:
557
576
  discarded_keys = []
558
577
 
559
578
  for k, v in doc.meta.items():
560
- if isinstance(v, SUPPORTED_TYPES_FOR_METADATA_VALUES):
561
- valid_meta[k] = v
562
- # For list metadata values, list must not be empty, must be of all same type
563
- # and be one of `SUPPORTED_TYPES_FOR_METADATA_VALUES`
564
- elif (
565
- isinstance(v, list)
566
- and len(v) > 0
567
- and (first_type := type(v[0])) in SUPPORTED_TYPES_FOR_METADATA_VALUES
568
- and all(isinstance(item, first_type) for item in v)
569
- ):
579
+ if ChromaDocumentStore._is_supported_metadata_value(v):
570
580
  valid_meta[k] = v
571
581
  else:
572
582
  discarded_keys.append(k)
@@ -610,13 +620,15 @@ class ChromaDocumentStore:
610
620
  How to handle documents whose `id` already exists in the store:
611
621
  - `NONE` (default): treated as `FAIL`.
612
622
  - `OVERWRITE`: replace the existing document.
613
- - `SKIP`: keep the existing document and skip the new one.
623
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
624
+ `documents` is written once.
614
625
  - `FAIL`: raise `DuplicateDocumentError`.
615
626
 
616
627
  :raises ValueError:
617
628
  When input is not valid.
618
629
  :raises DuplicateDocumentError:
619
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
630
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
631
+ within `documents`.
620
632
 
621
633
  :returns:
622
634
  The number of documents written.
@@ -634,7 +646,8 @@ class ChromaDocumentStore:
634
646
  return 0
635
647
 
636
648
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
637
- existing_ids = set(self._collection.get(ids=[p["ids"][0] for p in chroma_payloads])["ids"])
649
+ existing = self._collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
650
+ existing_ids = set(existing["ids"])
638
651
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
639
652
  else:
640
653
  payloads_to_write = chroma_payloads
@@ -663,13 +676,15 @@ class ChromaDocumentStore:
663
676
  How to handle documents whose `id` already exists in the store:
664
677
  - `NONE` (default): treated as `FAIL`.
665
678
  - `OVERWRITE`: replace the existing document.
666
- - `SKIP`: keep the existing document and skip the new one.
679
+ - `SKIP`: keep the existing document and skip the new one. An `id` repeated within
680
+ `documents` is written once.
667
681
  - `FAIL`: raise `DuplicateDocumentError`.
668
682
 
669
683
  :raises ValueError:
670
684
  When input is not valid.
671
685
  :raises DuplicateDocumentError:
672
- When `policy` is `FAIL` (or `NONE`) and any document `id` already exists.
686
+ When `policy` is `FAIL` (or `NONE`) and any document `id` already exists or is repeated
687
+ within `documents`.
673
688
 
674
689
  :returns:
675
690
  The number of documents written.
@@ -687,7 +702,7 @@ class ChromaDocumentStore:
687
702
  return 0
688
703
 
689
704
  if policy in (DuplicatePolicy.FAIL, DuplicatePolicy.SKIP):
690
- existing = await self._async_collection.get(ids=[p["ids"][0] for p in chroma_payloads])
705
+ existing = await self._async_collection.get(ids=list(dict.fromkeys(p["ids"][0] for p in chroma_payloads)))
691
706
  existing_ids = set(existing["ids"])
692
707
  payloads_to_write = self._apply_duplicate_policy(chroma_payloads, existing_ids, policy)
693
708
  else:
@@ -707,14 +722,29 @@ class ChromaDocumentStore:
707
722
  existing_ids: set[str],
708
723
  policy: DuplicatePolicy,
709
724
  ) -> list[dict[str, Any]]:
725
+ # an id repeated within the batch counts as a duplicate of its first occurrence
726
+ seen = set(existing_ids)
710
727
  if policy == DuplicatePolicy.FAIL:
711
- duplicates = [p["ids"][0] for p in payloads if p["ids"][0] in existing_ids]
728
+ duplicates = []
729
+ for p in payloads:
730
+ doc_id = p["ids"][0]
731
+ if doc_id in seen:
732
+ duplicates.append(doc_id)
733
+ seen.add(doc_id)
712
734
  if duplicates:
713
- msg = f"Documents with ids {duplicates} already exist in the document store."
735
+ msg = (
736
+ f"Documents with ids {duplicates} already exist in the document store or are repeated in the batch."
737
+ )
714
738
  raise DuplicateDocumentError(msg)
715
739
  return payloads
716
740
  if policy == DuplicatePolicy.SKIP:
717
- return [p for p in payloads if p["ids"][0] not in existing_ids]
741
+ to_write = []
742
+ for p in payloads:
743
+ doc_id = p["ids"][0]
744
+ if doc_id not in seen:
745
+ to_write.append(p)
746
+ seen.add(doc_id)
747
+ return to_write
718
748
  return payloads
719
749
 
720
750
  def delete_documents(self, document_ids: list[str]) -> None:
@@ -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,
@@ -237,6 +239,11 @@ class TestDocumentStoreUnit:
237
239
  assert result == {"ok": "x", "also_ok": None}
238
240
  assert "bad" in caplog.text and "worse" in caplog.text
239
241
 
242
+ def test_filter_metadata_keeps_list_values(self):
243
+ meta = {"tags": ["a", "b"], "pages": [1, 2], "mixed": ["a", 1], "empty": []}
244
+ result = ChromaDocumentStore._filter_metadata(meta)
245
+ assert result == {"tags": ["a", "b"], "pages": [1, 2]}
246
+
240
247
  def test_convert_document_to_chroma_rejects_non_document(self):
241
248
  with pytest.raises(ValueError, match="must contain a list of objects of type Document"):
242
249
  ChromaDocumentStore._convert_document_to_chroma("not a document") # type: ignore[arg-type]
@@ -335,6 +342,24 @@ class TestDocumentStore(
335
342
 
336
343
  assert [document.id for document in document_store.filter_documents(filters=filters)] == expected_ids
337
344
 
345
+ def test_update_by_filter_with_list_metadata(self, document_store: ChromaDocumentStore):
346
+ document_store.write_documents(
347
+ [
348
+ Document(id="1", content="first", meta={"lang": "en", "tags": ["draft"]}),
349
+ Document(id="2", content="second", meta={"lang": "de", "tags": ["draft"]}),
350
+ ]
351
+ )
352
+
353
+ updated = document_store.update_by_filter(
354
+ filters={"field": "meta.lang", "operator": "==", "value": "en"},
355
+ meta={"tags": ["draft", "reviewed"]},
356
+ )
357
+
358
+ assert updated == 1
359
+ documents = {document.id: document for document in document_store.filter_documents()}
360
+ assert documents["1"].meta["tags"] == ["draft", "reviewed"]
361
+ assert documents["2"].meta["tags"] == ["draft"]
362
+
338
363
  def test_delete_by_filter_metadata_id(self, document_store: ChromaDocumentStore):
339
364
  document_store.write_documents(
340
365
  [
@@ -714,6 +739,30 @@ class TestDocumentStore(
714
739
  assert len(result_empty_filters) == 1
715
740
  assert len(result_empty_filters[0]) == 2
716
741
 
742
+ def test_write_documents_skip_drops_ids_repeated_in_the_batch(self, document_store: ChromaDocumentStore):
743
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
744
+
745
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 2
746
+ assert document_store.count_documents() == 2
747
+
748
+ @pytest.mark.parametrize("policy", [DuplicatePolicy.FAIL, DuplicatePolicy.NONE])
749
+ def test_write_documents_fail_raises_on_ids_repeated_in_the_batch(
750
+ self, document_store: ChromaDocumentStore, policy: DuplicatePolicy
751
+ ):
752
+ docs = [Document(content="refund policy"), Document(content="shipping"), Document(content="refund policy")]
753
+
754
+ with pytest.raises(DuplicateDocumentError):
755
+ document_store.write_documents(docs, policy=policy)
756
+ assert document_store.count_documents() == 0
757
+
758
+ def test_write_documents_skip_with_repeated_ids_already_stored(self, document_store: ChromaDocumentStore):
759
+ stored = Document(content="refund policy")
760
+ document_store.write_documents([stored])
761
+
762
+ docs = [stored, Document(content="shipping"), stored]
763
+ assert document_store.write_documents(docs, policy=DuplicatePolicy.SKIP) == 1
764
+ assert document_store.count_documents() == 2
765
+
717
766
 
718
767
  @pytest.mark.integration
719
768
  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",