fix: pass batch_size to add_documents instead of Cassandra.__init__ - #13967
fix: pass batch_size to add_documents instead of Cassandra.__init__#13967gingeekrishna wants to merge 1 commit into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe ChangesCassandra ingestion fix
Estimated code review effort: 2 (Simple) | ~10 minutes Related issues: Fixes Suggested labels: bug, lfx Suggested reviewers: none identified 🐰
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (7 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes a runtime TypeError in the LFX Cassandra vector store component by ensuring batch_size is applied during ingestion (via add_documents) rather than being forwarded into Cassandra.__init__(), and it also makes setup_mode consistently applied even when ingesting documents.
Changes:
- Replace
Cassandra.from_documents(..., batch_size=...)with explicitCassandra(...)construction. - Ingest documents via
table.add_documents(..., batch_size=...)to avoid passing unsupported constructor kwargs. - Apply
setup_modeconsistently regardless of whether documents are provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lfx/src/lfx/components/cassandra/cassandra.py`:
- Around line 189-193: The Cassandra ingestion path in Cassandra.add_documents
is currently passing self.batch_size or None, which can drop the intended
default and send None into add_documents/add_texts. Update the batch_size
argument in the add_documents call to use an explicit integer fallback instead
of None, keeping the behavior in cassandra.py aligned with the component’s
default and IntInput normalization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aa613456-7dc4-4c0c-863e-866e6f9ea1c6
📒 Files selected for processing (1)
src/lfx/src/lfx/components/cassandra/cassandra.py
| if documents: | ||
| self.log(f"Adding {len(documents)} documents to the Vector Store.") | ||
| table = Cassandra.from_documents( | ||
| documents=documents, | ||
| embedding=self.embedding, | ||
| table_name=self.table_name, | ||
| keyspace=self.keyspace, | ||
| ttl_seconds=self.ttl_seconds or None, | ||
| batch_size=self.batch_size, | ||
| body_index_options=body_index_options, | ||
| ) | ||
| # batch_size controls per-call ingestion throughput and belongs on | ||
| # add_documents, not on Cassandra.__init__ (which does not accept it). | ||
| table.add_documents(documents, batch_size=self.batch_size or None) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
langchain_community Cassandra vectorstore add_documents add_texts batch_size parameter
💡 Result:
In the langchain-community Python library, the Cassandra vector store supports a batch_size parameter specifically within the add_texts method [1][2]. This parameter controls the number of concurrent requests sent to the server [1]. Regarding the add_documents method, official documentation and source code typically indicate that it accepts kwargs [1][3], which are passed through to underlying operations, but users should be aware that add_documents internally calls add_texts [4]. While batch_size is explicitly defined in the add_texts signature [1][2], consistent application or parameter passing behavior in add_documents may vary by specific package version [4]. Official documentation often recommends explicitly checking the method signatures or using add_texts directly if you need to strictly control batching behavior [5]. For the JavaScript implementation (@langchain/classic/vectorstores/cassandra), batchSize is a configuration parameter provided during the initialization of the CassandraStore, defining how many documents are sent in a single request to Cassandra [6]. Key takeaways: - Python: add_texts includes an explicit batch_size parameter (default is typically 16) [1]. - Python: add_documents supports kwargs, but if you experience issues with batching, consider using add_texts directly for more granular control [5][1]. - JavaScript: batchSize is configured at the store level during initialization, not as a parameter to the add methods themselves [6].
Citations:
- 1: https://aidoczh.com/langchain/api_reference/community/vectorstores/langchain_community.vectorstores.cassandra.Cassandra.html
- 2: https://sj-langchain.readthedocs.io/en/latest/_modules/langchain/vectorstores/cassandra.html
- 3: https://sj-langchain.readthedocs.io/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
- 4: index() API does not respect batch_size on vector_store.add_documents() langchain-ai/langchain#19415
- 5: https://docs.langchain.com/oss/python/integrations/vectorstores/cassandra
- 6: https://docs.langchain.com/oss/javascript/integrations/vectorstores/cassandra
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the target file and nearby context
sed -n '150,220p' src/lfx/src/lfx/components/cassandra/cassandra.py
# Find where batch_size is defined/used in this component
rg -n "batch_size|add_documents|add_texts" src/lfx/src/lfx/components/cassandra -S
# Search the repo for any pinned langchain-community references that may indicate the version
rg -n "langchain-community|langchain_community|Cassandra" -S pyproject.toml poetry.lock requirements*.txt uv.lock src README* .Repository: langflow-ai/langflow
Length of output: 50377
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show the component inputs around batch_size
sed -n '1,90p' src/lfx/src/lfx/components/cassandra/cassandra.py
# Inspect the pinned langchain-community version from the lockfile
python3 - <<'PY'
import re, pathlib
text = pathlib.Path("uv.lock").read_text()
m = re.search(r'name = "langchain-community".*?version = "([^"]+)"', text, re.S)
print("langchain-community version:", m.group(1) if m else "not found")
PY
# Search for any local vendor/docs references to Cassandra add_documents/add_texts
rg -n "class Cassandra|def add_documents|def add_texts|batch_size" docs src -SRepository: langflow-ai/langflow
Length of output: 50377
🌐 Web query:
langchain-community 0.4.2 Cassandra vectorstore add_documents add_texts batch_size source code
💡 Result:
In the langchain-community Python package (including version 0.4.2), the Cassandra vector store implementation manages document ingestion primarily through the add_documents and add_texts methods [1][2]. The add_texts method is defined to accept a batch_size parameter [2]. According to the source code and documentation, batch_size refers to the number of concurrent requests sent to the Cassandra server, with a default value of 16 [2][3][4]. While the terminology sometimes refers to this as concurrency, it acts as the primary mechanism for controlling the speed and volume of bulk ingestion operations [1][2]. The add_documents method, which ultimately wraps or utilizes the underlying insertion logic, also supports passing additional keyword arguments (kwargs) [2][5], which can include configurations relevant to the ingestion process. It is important to distinguish this from the JavaScript/TypeScript LangChain implementation, which explicitly separates concurrency (maxConcurrency) and the number of documents per request (batchSize) [6]. In the Python langchain-community implementation, the parameter is predominantly documented and utilized as batch_size to control the level of concurrency for bulk additions [1][2][3]. Recent updates to the class have also introduced other metadata-related methods, such as delete_by_metadata_filter, which also include their own batch_size parameters (often defaulting to 50) for managing operation volume [7].
Citations:
- 1: https://docs.langchain.com/oss/python/integrations/vectorstores/cassandra
- 2: https://aidoczh.com/langchain/api_reference/community/vectorstores/langchain_community.vectorstores.cassandra.Cassandra.html
- 3: langchain-ai/langchain@75733c5
- 4: langchain-ai/langchain@328d0c9
- 5: langchain-ai/langchain@f636c83
- 6: https://docs.langchain.com/oss/javascript/integrations/vectorstores/cassandra
- 7: langchain-ai/langchain@d05fdd9
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the batch_size input definition and any local usage that might coerce it
sed -n '40,75p' src/lfx/src/lfx/components/cassandra/cassandra.py
# Check if the codebase treats cleared IntInput values as None / empty elsewhere
rg -n "IntInput\\(|value=16|or None|batch_size or None|batch_size=.*None|if self\\.batch_size" src/lfx/src/lfx -SRepository: langflow-ai/langflow
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the input normalization path for empty values and IntInput behavior
sed -n '200,260p' src/lfx/src/lfx/inputs/inputs.py
sed -n '540,620p' src/lfx/src/lfx/inputs/inputs.py
# Read the Cassandra component's batch_size definition in full context
sed -n '45,70p' src/lfx/src/lfx/components/cassandra/cassandra.pyRepository: langflow-ai/langflow
Length of output: 6373
🌐 Web query:
langchain-community 0.4.2 Cassandra add_documents forwards kwargs to add_texts source
💡 Result:
In the langchain-community Cassandra vector store implementation, the add_documents method generally handles keyword arguments (kwargs) by passing them through to underlying operations, consistent with the standard LangChain VectorStore interface [1][2]. Within the langchain-community package, the add_documents method typically calls add_texts to perform the actual insertion of data into the Cassandra database [3]. The add_documents method takes a list of Document objects, converts them into texts and metadata, and then invokes add_texts (or an equivalent underlying insertion mechanism) while passing along the relevant parameters and kwargs [3][4]. While add_documents and add_texts serve different purposes—with add_documents being intended for objects that include metadata and add_texts being intended for raw strings—they are designed to be compatible, and kwargs are passed through to ensure consistent behavior across these methods [3][4]. In recent versions of langchain-community, including those surrounding the 0.4.2 timeframe, maintenance and modernization efforts have specifically ensured that these methods properly manage metadata and additional keyword arguments [5][4]. If you are encountering unexpected behavior, note that according to the base LangChain VectorStore specification, if kwargs contain IDs and documents also contain IDs, the IDs provided in the kwargs are designed to take precedence [2].
Citations:
- 1: https://sj-langchain.readthedocs.io/en/latest/vectorstores/langchain.vectorstores.cassandra.Cassandra.html
- 2: https://reference.langchain.com/python/langchain-core/vectorstores/base/VectorStore/add_documents
- 3: https://docs.langchain.com/oss/python/integrations/vectorstores/cassandra
- 4: langchain-ai/langchain@d05fdd9
- 5: langchain-ai/langchain@f636c83
Avoid passing None for Cassandra batch_size IntInput normalizes a blank value to 0, so self.batch_size or None drops the component’s default and can hand None to add_documents/add_texts, which expects an int. Use self.batch_size or 16 (or another explicit minimum) instead.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lfx/src/lfx/components/cassandra/cassandra.py` around lines 189 - 193,
The Cassandra ingestion path in Cassandra.add_documents is currently passing
self.batch_size or None, which can drop the intended default and send None into
add_documents/add_texts. Update the batch_size argument in the add_documents
call to use an explicit integer fallback instead of None, keeping the behavior
in cassandra.py aligned with the component’s default and IntInput normalization.
Cassandra.__init__() does not accept a batch_size argument. The component was passing batch_size=self.batch_size to Cassandra.from_documents(), which forwards all extra kwargs to __init__, causing: TypeError: Cassandra.__init__() got an unexpected keyword argument 'batch_size' batch_size controls per-call ingestion throughput and belongs on add_documents / add_texts, not on the constructor. Replace the from_documents path with an explicit construct-then-add pattern so setup_mode is consistently applied (it was previously ignored when documents were provided) and batch_size reaches the correct call site. Fixes langflow-ai#6255
c4baaf1 to
e39508f
Compare
Summary
Fixes #6255
Error:
Root cause:
Cassandra.from_documents()forwards all extra**kwargstoCassandra.__init__(), but__init__does not acceptbatch_size. Thebatch_sizeparameter controls per-call ingestion throughput and belongs onadd_documents/add_texts, not the constructor.Fix: Replace the
from_documents(batch_size=...)path with an explicit construct-then-add pattern:This also fixes a secondary inconsistency:
setup_modewas silently ignored whenever documents were present (it was only applied in theelsebranch).Changes
src/lfx/src/lfx/components/cassandra/cassandra.py— replacefrom_documents(batch_size=...)with explicitCassandra(...)+add_documents(batch_size=...)(11 lines added, 17 removed)Summary by CodeRabbit