Skip to content

fix(rag): preserve nested empty JSON containers - #1532

Open
embrace897 wants to merge 1 commit into
VoltAgent:mainfrom
embrace897:fix/rag-json-empty-fields
Open

embrace897 wants to merge 1 commit into
VoltAgent:mainfrom
embrace897:fix/rag-json-empty-fields

Conversation

@embrace897

@embrace897 embrace897 commented Nov 12, 2026 •

Copy link
Copy Markdown

PR Checklist

  • The proposed commit message follows Conventional Commits.

Bugs / Features

  • Related issue(s) linked. Reproduced directly on main.
  • Tests for the changes have been added.
  • Docs have been added or updated.
  • A patch changeset for @voltagent/rag has been added.

What is the current behavior?

JsonChunker.chunk('{"tags":[],"settings":{}}') returns no chunks. Empty arrays and objects also disappear from the flattened text and field metadata when other values are present.

What is the new behavior?

Emit [] or {} as a leaf at each nested empty path. A document with tags: [] and settings: {} now retains both fields. An empty root still has zero fields.

Notes for reviewers

  • The new test file on upstream main produced 2 failures and 2 passing controls.
  • vitest run --typecheck passed all 51 RAG tests in 20 files after the fix.
  • The modified source and test passed a scoped strict TypeScript check. CommonJS, ESM and declaration builds passed.
  • Changed-file Biome, changeset Prettier and whitespace checks passed.

OpenAI Codex assisted with reproduction, implementation and local validation.


Summary by cubic

Fixes JsonChunker so nested empty arrays and objects no longer disappear from flattened chunk text and field metadata.

  • {"tags":[],"settings":{}} now produces chunks containing tags: [] and settings: {} instead of returning no chunks.
  • Empty entries inside arrays are kept as leaves alongside populated entries, e.g. items.1: [].
  • An empty root ({} or []) still yields zero fields.

Written for commit f495be6. Summary will update on new commits.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Empty objects and arrays nested in JSON documents are now retained when the documents are split into chunks, including empty entries within otherwise populated arrays.
    • Empty root objects and arrays continue to produce no chunks.
  • Tests
    • Added coverage for preserving nested empty containers and handling empty root values.

@changeset-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f495be6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/rag Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The JSON chunker now preserves empty nested arrays and objects as path/value records. Empty root arrays and objects still produce no chunks. Tests cover these cases, and a patch changeset documents the update.

Changes: JSON Chunker

Layer / File(s) Summary
Preserve empty nested containers
packages/rag/src/chunkers/json-chunker.ts, packages/rag/src/chunkers/json-chunker.spec.ts, .changeset/preserve-empty-json-fields.md
The chunker records empty non-root arrays and objects. Tests cover empty containers and populated arrays with empty entries, and verify that empty root containers produce no chunks. The changeset declares a patch release for @voltagent/rag.

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

Change: Bug fix

Suggested reviewers: omeraplak

Merge Risk: Minimal · up to f495b

The JSON chunker now keeps empty nested arrays and objects in its output, and empty root containers still produce no chunks. I found no concrete merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the actual change: a fix in the rag package that preserves nested empty JSON containers. The changeset, the JsonChunker source change, and the new tests all target that behavior. The t…
Description check Passed The description follows the repository template. It includes the PR checklist, the bugs/features checklist, the current and new behavior sections, and the notes for reviewers. It explains the bug with…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the actual change: a fix in the rag package that preserves nested empty JSON containers. The changeset, the JsonChunker source change, and the new tests all target that behavior. The title uses a Conventional Commits prefix and is short and specific.

Full details: Description check

Explanation

The description follows the repository template. It includes the PR checklist, the bugs/features checklist, the current and new behavior sections, and the notes for reviewers. It explains the bug with a concrete example (JsonChunker.chunk on a document with empty tags and settings) and states the expected new behavior. The checklist marks tests and a patch changeset as done. Two gaps remain: the 'fixes (issue)' line has no linked issue, and the docs item is unchecked, which the author does not explain. The 'Related issue(s) linked' item is unchecked and the note says 'Reproduced directly on main' without an issue link.

Resolution

Link the related issue in the 'fixes (issue)' line or state that no issue exists. Confirm whether docs need an update, or explain why none are needed.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 88ddf244-dab1-482f-ba13-25a30e395214
Commits

Reviewing files that changed from the base of the PR and between e9fc599 and f495be6.

Files selected for processing: 3

  • .changeset/preserve-empty-json-fields.md
  • packages/rag/src/chunkers/json-chunker.spec.ts
  • packages/rag/src/chunkers/json-chunker.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

View guided diff | Re-trigger cubic

This branch has not been deployed

No deployments
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.

1 participant