arijeetmukherjee3108-droid commented on code in PR #41625:
URL: https://github.com/apache/beam/pull/41625#discussion_r4686215965
##########
sdks/python/apache_beam/ml/rag/chunking/langchain_test.py:
##########
@@ -227,6 +231,39 @@ def test_empty_text(self):
assert_that(chunks, equal_to([]))
+ def test_chunks_have_independent_metadata(self):
+ """Test that each chunk receives an independent copy of metadata."""
+ doc = {**self.simple_text, 'tags': ['a']}
+ splitter = RecursiveCharacterTextSplitter(
+ chunk_size=30, chunk_overlap=0, separators=[".", " "])
+ provider = LangChainChunker(
+ document_field='content',
+ metadata_fields=['source', 'language', 'tags'],
+ text_splitter=splitter)
+
+ def check_independent_metadata(chunks):
+ if len(chunks) < 2:
+ raise BeamAssertException(
+ f"Expected at least 2 chunks, got {len(chunks)}")
Review Comment:
Great catch—I hadn't accounted for the GroupByKey/coder round-trip inside
assert_that deserializing separate Chunk objects. I updated
test_chunks_have_independent_metadata to call
list(_LangChainTextSplitter(...).process(doc)) directly and verify that
mutating both top-level and nested metadata does not affect sibling chunks or
the input doc.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]