fix(rag): preserve nested empty JSON containers
EM
3d ago+43+43+01234567890123456789-8-8-0123456789
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/raghas 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 --typecheckpassed 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 containingtags: []andsettings: {}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.
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.