Repository navigation
fix(rag): detect top-level JSON arrays in auto format detection - #1459
Conversation
🦋 Changeset detectedLatest commit: 99c9cea The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Detect and validate JSON arrays packages/rag/src/utils/format-detector.ts, packages/rag/src/__tests__/format-detector.spec.ts, .changeset/curly-donkeys-detect.md |
The JSON candidate check pairs { with } and [ with ]. Tests cover detection of arrays and objects, malformed input, and automatic array chunking. The changeset records a patch release for @voltagent/rag. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: omeraplak
Merge Risk: 
Minimal · previous review 6e047
-
Well-formed top-level JSON arrays are now routed to the JSON chunker under the auto strategy. Object payloads and malformed input behave as before. No merge-blocking risk is evident.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description follows the repository template and includes the checklist, current and new behavior, issue reference, test coverage, changeset status, and reviewer notes. Documentation is marked as not updated, but this is non-critical for the fix.
Full details: Linked Issues check
-
Explanation
Issue
#1458requires well-formed top-level JSON arrays to return"json"and route throughJsonChunkerunderstrategy: "auto".format-detector.tsnow pairs{}and[]beforeJSON.parse. The new tests cover array detection, object compatibility, malformed input, and auto chunking withfieldsand indexed content. The changeset documents the fix.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to the bracket-pairing fix, focused regression tests, and a package changeset. These changes support issue
#1458. The separate inherited metadata problem and table detection problem remain unchanged, as required by the stated scope.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
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.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4b34a0c1-a3af-415d-b803-598eeffc6eb4
📒 Files selected for processing: 3
-
.changeset/curly-donkeys-detect.md
packages/rag/src/__tests__/format-detector.spec.ts
packages/rag/src/utils/format-detector.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.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4b34a0c1-a3af-415d-b803-598eeffc6eb4
📒 Files selected for processing: 3
-
.changeset/curly-donkeys-detect.mdpackages/rag/src/__tests__/format-detector.spec.tspackages/rag/src/utils/format-detector.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.
-
PR Checklist
What is the current behavior?
detectFormat()accepted{or[as the opening character but only ever accepted}as the closing one:A top-level JSON array ends with
], so it never entered theJSON.parsebranch and was reported as"text".detectStrategy()indocument/transformers.tsmaps that result to a chunker, so withstrategy: "auto"any document whose content is a JSON array — API response dumps, exported record sets,.jsonfixtures — went toRecursiveChunkerinstead ofJsonChunker, losing the structuralpath: valuechunks and thefields/samplePathsmetadata.Object payloads were unaffected.
What is the new behavior?
The brackets are paired, so arrays are detected too:
The existing
try { JSON.parse(text) } catchstill guards malformed input, so[unclosed]keeps falling through to the html / latex / code / table / markdown checks and still returns"text".fixes (issue)
fixes #1458
Notes for reviewers
/\n\|.+\|\n/requires a newline before the first row, so a table at the very start of a document is also missed) — that is a separate bug and I would rather not bundle it.JsonChunker'sformat: "json"is overwritten by theformat: "text"it inherits from the token chunker, becausebuildMetadataends withObject.assign(meta, params.extra)and onlysourceTypeis stripped from the inherited metadata.packages/rag/src/__tests__/format-detector.spec.tswith four cases: array detection, object detection, malformed fall-through, and an end-to-end check thatchunkByStrategy("auto", '[{"name":"alice"},{"name":"bob"}]')now yieldsmetadata.fields === 2and a chunk containing0.name: alice.Verified locally (Windows host, no network or API keys):
vitest runinpackages/rag-> 47 passed across 19 files.format-detector.tsreverted tomain, the array detection test and the end-to-end test fail (expected 'text' to be 'json',expected undefined to be 2); with the change they pass.biome checkclean on both changed files (the CRLF complaint when checking a raw Windows checkout disappears against the committed LF blob).AI assistance: this fix and its tests were produced with an AI coding agent under my direction. The bug, the paired-bracket fix, the duplicate check and every test result quoted above were verified by running those commands against a checkout of
mainat72a46c7.Summary by cubic
Fixes
detectFormat()so top-level JSON arrays are detected as JSON instead of"text". Previously the check accepted{or[as an opening bracket but only}as a closing one, so arrays ending in]fell through toRecursiveChunkerunder theautostrategy, losing JSON structural chunks and metadata. Brackets are now paired ({...}and[...]), andJSON.parsestill guards malformed input.fixes #1458
Written for commit 99c9cea. Summary will update on new commits.
Summary by CodeRabbit