Skip to content

fix(rag): preserve CSV cell text in batch segment import - #42159

Merged
fatelei merged 1 commit into
langgenius:mainfrom
CoralGarden52:fix/batch-import-preserve-csv-cell-text
Sep 11, 2026
Merged

fatelei merged 1 commit into
langgenius:mainfrom
CoralGarden52:fix/batch-import-preserve-csv-cell-text

Conversation

@CoralGarden52

Copy link
Copy Markdown
Contributor

Summary

Fixes #42157

The batch segment import task now reads uploaded CSV files with dtype=str and keep_default_na=False. This preserves numeric-looking values and literal NA values as text for both paragraph and QA imports, including leading zeros in values such as 00123.

No new dependency is required.

Root cause and scope

The batch task used the default Pandas type inference. Values such as 00123 and NA could become NumPy numeric or missing-value scalars, and the subsequent len(content) call raised TypeError.

This change is limited to the batch segment import path. It is separate from #41922, which fixes the standard CSVExtractor path, and #38863, which addresses batch-task Redis error status handling.

Validation

Before

On the pre-fix upstream/main commit f0d69e7b39, the same CSV:

content,answer
00123,NA
NA,00456

was read as:

before: dtypes={'content': 'float64', 'answer': 'float64'}, values=[('float64', np.float64(123.0), 'float64', np.float64(nan)), ('float64', np.float64(nan), 'float64', np.float64(456.0))]

The task-level reproduction failed with:

TypeError: object of type 'numpy.float64' has no len()

After

The same task-level reproduction, using the real task function and real Pandas parsing with database, storage, Redis, and vector service boundaries mocked in memory, passed with:

observed=[('str', '00123', 'NA', 7), ('str', 'NA', '00456', 7)]
redis=[('segment_batch_import_job-id', 600, 'completed')]

The direct Pandas comparison now reports:

after: dtypes={'content': 'str', 'answer': 'str'}, values=[('str', '00123', 'str', 'NA'), ('str', 'NA', 'str', '00456')]

Other checks:

  • pytest -q api/tests/unit_tests/core/rag/extractor/test_csv_extractor.py --no-cov: 15 passed
  • Targeted ruff check: All checks passed
  • Targeted ruff format --check: 2 files already formatted
  • git diff --check: passed
  • Added a task-level regression test covering numeric-looking content, literal NA, and QA answers.

The container integration test was not runnable to completion locally because the current user cannot access the Docker daemon socket (Permission denied on /var/run/docker.sock). The production fix itself does not require Docker; this limitation only affects the repository's Testcontainers-based PostgreSQL/Redis integration fixture. CI can run the integration test in its normal container-enabled environment.

Screenshots

Before After
Not applicable - backend-only change Not applicable - backend-only change

Checklist

  • This change requires a documentation update
  • I understand that this PR may be closed in case there was no previous discussion or issues
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change
  • I've updated the documentation accordingly
  • I ran make lint && make type-check; targeted Ruff checks were run instead

From Codex.

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-10 14:50:56.482520631 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-10 14:50:46.214447694 +0000
@@ -1381,7 +1381,7 @@
 ERROR `>` is not supported between `None` and `Literal[0]` [unsupported-operation]
    --> tests/test_containers_integration_tests/tasks/test_batch_create_segment_to_index_task.py:314:16
 ERROR `>` is not supported between `None` and `Literal[0]` [unsupported-operation]
-   --> tests/test_containers_integration_tests/tasks/test_batch_create_segment_to_index_task.py:707:16
+   --> tests/test_containers_integration_tests/tasks/test_batch_create_segment_to_index_task.py:750:16
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:113:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 64.06% 64.06% -0.00%
Strict coverage 63.67% 63.67% -0.00%
Typed symbols 45,912 45,913 +1
Untyped symbols 25,912 25,914 +2
Modules 3397 3397 0

@fatelei
fatelei added this pull request to the merge queue Sep 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 11, 2026
@fatelei
fatelei added this pull request to the merge queue Sep 11, 2026
Merged via the queue into langgenius:main with commit c6c8914 Sep 11, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: batch segment import fails when CSV content is inferred as numeric or NA

2 participants