arijeetmukherjee3108-droid opened a new issue, #41623:
URL: https://github.com/apache/beam/issues/41623

   ### What happened?
   
   ### What happened?
   
   There are two bugs in `apache_beam.ml.rag.chunking.langchain`:
   
   1. **Outdated import for modern LangChain (`langchain-text-splitters`):**
      `sdks/python/apache_beam/ml/rag/chunking/langchain.py` only imports 
`TextSplitter` from `langchain.text_splitter`. In modern LangChain, text 
splitters live in the standalone `langchain_text_splitters` package. When 
`langchain-text-splitters` is installed without the legacy 
`langchain.text_splitter` module, `LangChainChunker` sets `TextSplitter = 
None`, raises `ImportError` on initialization, and all tests in 
`langchain_test.py` are silently skipped.
   
   2. **Shared mutable `metadata` dict across chunks:**
      In `_LangChainTextSplitter.process`, a single `metadata` dict is created 
once per document and passed by reference to every `Chunk` yielded from that 
document:
      ```python
      metadata = {field: element[field] for field in self.metadata_fields}
      for i, text_chunk in enumerate(text_chunks):
        yield Chunk(content=Content(text=text_chunk), index=i, 
metadata=metadata)
      ```
      Mutating `chunk.metadata` in a `chunk_id_fn` or downstream transform 
silently mutates the metadata of all other chunks produced from the same 
document.
   
   ### Expected Behavior
   
   1. `LangChainChunker` (and `langchain_test.py`) should import from 
`langchain_text_splitters` first, falling back to `langchain.text_splitter` for 
backward compatibility.
   2. Each `Chunk` yielded by `_LangChainTextSplitter.process` should receive 
an independent copy (`metadata.copy()`).
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner


-- 
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]

  • [I] [Bug]: LangChainChu... arijeetmukherjee3108-droid (via GitHub) via github

Reply via email to