[BUG] rag: detectFormat never recognizes top-level JSON arrays, so "auto" chunking skips the JSON chunker
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start with packages/rag/src/utils/format-detector.ts and inspect the bracket checks in detectFormat; the reproduction shows an array currently returns "text" while an object returns "json". Check for existing tests of format detection, then add coverage for a top-level array and confirm objects and malformed input still behave as expected. Done means valid top-level JSON arrays are detected as json, allowing auto chunking to select the JSON chunker.
Written by the indexing model from the issue text.
Description
Describe the bug
packages/rag/src/utils/format-detector.ts decides whether the input is JSON with:
if ((text.startsWith("{") || text.startsWith("[")) && text.endsWith("}")) {
The opening check accepts { or [, but the closing check only ever accepts }. A top-level JSON array ends with ], so it can never satisfy the condition and the JSON.parse branch is never reached for arrays.
Steps To Reproduce
import { detectFormat } from "../utils/format-detector"; // packages/rag/src/utils/format-detector.ts
detectFormat('[{"id":1},{"id":2}]'); // returns "text", expected "json"
detectFormat('{"id":1}'); // returns "json"
Reproduced on main at 72a46c7. No API key or network needed — detectFormat is a pure function.
Expected behavior
A well-formed top-level JSON array should be detected as json.
Impact
detectStrategy() in packages/rag/src/document/transformers.ts maps the detected format to a chunker, so with strategy: "auto" any document whose content is a JSON array — API response dumps, exported record sets, .json fixtures — is routed to RecursiveChunker instead of JsonChunker. The structural path: value representation and the fields / samplePaths metadata are silently not produced.
Objects ({ ... }) are unaffected, so this only misroutes array payloads.
Notes
- Possible fix: pair the brackets, i.e.
(text.startsWith("{") && text.endsWith("}")) || (text.startsWith("[") && text.endsWith("]")). The existingJSON.parsein a try/catch still guards against malformed input. - While testing this I hit a separate, unrelated problem:
JsonChunkerspreads the token chunker's metadata intobuildMetadata'sextra, andbuildMetadatadoesObject.assign(meta, params.extra), so theformat: "json"it sets is overwritten by the inheritedformat: "text".sourceTypeis explicitly stripped from the inherited metadata butformatis not. I am not bundling that with a fix for this issue — happy to open a separate one if useful.
- Dominant language
- TypeScript
- Stars
- 10.9k
- Forks
- 1.3k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 2
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from VoltAgent/voltagent
-
[BUG] rag: sentence content can cross the reported sentence boundariesPossibly taken @LJK-ikun claimed this 3 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
[BUG] rag: recursive chunk expansion returns duplicate IDsPossibly taken @LJK-ikun claimed this 3 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
[BUG] updateAllPackages missing command injection protection present in updateSinglePackagePossibly taken @octo-patch claimed this 181 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
VoltAgent/voltagent#1205 · 3 comments · 6 reactions ·
Maintainers usually reply within 1 day
-
[BUG] Elysia server provider test suite entirely broken — stale mocks after Node.js HTTP refactorPossibly taken @Koushik-Salammagari claimed this 161 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
VoltAgent/voltagent#1204 · 1 comment ·
Maintainers usually reply within 1 day
-
[DOC] Regenerate the model provider registry and provider docs from models.devPossibly taken @MannXo claimed this today. Opendocumentation
VoltAgent/voltagent#1476 · 2 comments ·
Maintainers usually reply within 1 day
All issues in VoltAgent/voltagent
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
farion1231/cc-switch#8829 ·
Maintainers usually reply within 1 day
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutoverOpendoc-audit enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100