Skip to content

fix: pass batch_size to add_documents instead of Cassandra.__init__ - #13967

Open
gingeekrishna wants to merge 1 commit into
langflow-ai:mainfrom
gingeekrishna:fix/6255-cassandra-batch-size
Open

fix: pass batch_size to add_documents instead of Cassandra.__init__#13967
gingeekrishna wants to merge 1 commit into
langflow-ai:mainfrom
gingeekrishna:fix/6255-cassandra-batch-size

Conversation

@gingeekrishna

@gingeekrishna gingeekrishna commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #6255

Error:

TypeError: Cassandra.__init__() got an unexpected keyword argument 'batch_size'

Root cause: Cassandra.from_documents() forwards all extra **kwargs to Cassandra.__init__(), but __init__ does not accept batch_size. The batch_size parameter controls per-call ingestion throughput and belongs on add_documents / add_texts, not the constructor.

Fix: Replace the from_documents(batch_size=...) path with an explicit construct-then-add pattern:

table = Cassandra(embedding=..., table_name=..., setup_mode=setup_mode, ...)
if documents:
    table.add_documents(documents, batch_size=self.batch_size or None)

This also fixes a secondary inconsistency: setup_mode was silently ignored whenever documents were present (it was only applied in the else branch).

Changes

  • src/lfx/src/lfx/components/cassandra/cassandra.py — replace from_documents(batch_size=...) with explicit Cassandra(...) + add_documents(batch_size=...) (11 lines added, 17 removed)

Summary by CodeRabbit

  • Bug Fixes
    • Improved Cassandra vector store setup so it now creates the store first and ingests documents afterward, making document loading more reliable.
    • Preserved existing configuration settings while handling both populated and empty document inputs more consistently.
    • Improved batching behavior during ingestion for better control over how documents are added.

Copilot AI review requested due to automatic review settings July 4, 2026 16:09
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a9c2cd1-f439-4e59-a5b9-4056edd6c98e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The build_vector_store method in CassandraVectorStoreComponent was changed to always construct a Cassandra instance directly, then ingest documents afterward via table.add_documents(...) when documents exist, replacing the prior conditional use of Cassandra.from_documents(...).

Changes

Cassandra ingestion fix

Layer / File(s) Summary
Refactor document ingestion path
src/lfx/src/lfx/components/cassandra/cassandra.py
Constructs Cassandra(...) unconditionally, then ingests documents via table.add_documents(documents, batch_size=self.batch_size or None) when present, fixing a TypeError caused by passing batch_size to Cassandra.from_documents.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related issues: Fixes Cassandra.__init__() got an unexpected keyword argument 'batch_size' (#6255).

Suggested labels: bug, lfx

Suggested reviewers: none identified

🐰

A batch size bug once caused a fuss,
Cassandra's constructor made a fuss.
Now build first, then add with care,
Documents ingest without despair,
A tidy fix, no more error dust.


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR changes the Cassandra component, but the diff adds no test files, so the batch_size/setup_mode regression isn’t covered. Add a backend regression test (e.g. src/backend/tests/unit/components/vectorstores/test_cassandra_vector_store_component.py) that exercises docs ingestion and verifies batch_size is used on add_documents, not Cassandra.init().
Test Quality And Coverage ⚠️ Warning The PR adds no pytest coverage for the new Cassandra build/add flow; searches found no Cassandra tests, so the behavior isn’t validated. Add unit tests for CassandraVectorStoreComponent covering empty vs ingested data, no batch_size in Cassandra().init, and add_documents(batch_size=...) behavior.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: moving batch_size from Cassandra.init to add_documents.
Linked Issues check ✅ Passed The change addresses #6255 by avoiding batch_size in Cassandra.init and ingesting documents via add_documents.
Out of Scope Changes check ✅ Passed The PR stays focused on the Cassandra vector store ingestion fix and does not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Test File Naming And Structure ✅ Passed No test files were added or modified in this PR; only non-test files changed, so the test-file structure check is not applicable.
Excessive Mock Usage Warning ✅ Passed No test files were changed in this PR; only generated component metadata and Cassandra code were updated, so there’s no mock-heavy test code to review.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 explicit Cassandra(...) construction.
  • Ingest documents via table.add_documents(..., batch_size=...) to avoid passing unsupported constructor kwargs.
  • Apply setup_mode consistently regardless of whether documents are provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 315cc41 and d88271f.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/components/cassandra/cassandra.py

Comment on lines 189 to +193
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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:


🏁 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 -S

Repository: 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:


🏁 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 -S

Repository: 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.py

Repository: 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:


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
@gingeekrishna
gingeekrishna force-pushed the fix/6255-cassandra-batch-size branch from c4baaf1 to e39508f Compare August 16, 2026 16:23
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cassandra.__init__() got an unexpected keyword argument 'batch_size'

2 participants