fix(rag): support inherited-property names as document IDs

EM
5d ago
+48-3

PR Checklist

  • The proposed commit message follows Conventional Commits.

Bugs / Features

  • Related issue(s) linked: source-discovered defect; no existing issue is claimed.
  • Tests for the changes have been added and run.
  • Docs: no new public API; the behavior correction is described in the changeset.
  • A patch changeset for @voltagent/rag has been added.

What is the current behavior?

StructuredDocument accepts arbitrary string docId values, but chunk() and getLinkGraph() throw for constructor, proto, toString and hasOwnProperty. Their dictionaries read inherited values and try to spread them as link arrays.

What is the new behavior?

Use prototype-free dictionaries while collecting links. Return a spread copy from getLinkGraph() to retain an ordinary Object prototype while safely retaining own proto keys. Add eleven public chunk/link regressions and controls, plus a RAG patch changeset. No IDs are renamed and no new API is introduced.

Notes for reviewers

Base: e9fc599f6059afcd88b34f2bfc50d0d1d6a0877c. Windows, Node 24.15.0; repository-locked pnpm 8.10.5, Vitest 3.2.4, TypeScript 5.9.2 and Biome 1.9.4.

Validation from packages/rag:

  • New regression file on unchanged source: 8 failed, 3 passed.
  • node ../../node_modules/vitest/vitest.mjs run: 58 passed across 20 RAG test files.
  • ../../node_modules/.bin/tsup: CommonJS, ESM and declaration builds pass; both built public exports were exercised successfully.
  • Scoped strict TypeScript check passes: node ../../node_modules/typescript/bin/tsc --noEmit --target ES2022 --module NodeNext --moduleResolution NodeNext --esModuleInterop --strict --skipLibCheck --types vitest/globals src/document/document.ts src/__tests__/document-keys.spec.ts.
  • Changed-file Biome, changeset Prettier and git diff --check pass.
  • Full package tsc --noEmit -p packages/rag/tsconfig.json still reports three existing test errors: code-chunker.spec.ts:60 and late-chunker.spec.ts:16,27. Baseline and patched diagnostics match; those unrelated tests are unchanged.

No live model or cloud service was used. The full monorepo suite and other Node versions were not run. The current CI package-test matrix does not include RAG, so its complete suite was run locally.

AI assistance: OpenAI Codex investigated, prepared and ran these checks. Separate account-owner manual validation is not claimed.


Summary by cubic

Fixes StructuredDocument so document IDs such as constructor and __proto__ no longer throw in chunk() and getLinkGraph(). The link graph is now built with prototype-free dictionaries, and getLinkGraph() returns a spread copy so callers still receive an ordinary object. Includes regression tests and a patch changeset for @voltagent/rag.

Summary by CodeRabbit

  • Bug Fixes
    • Document IDs such as constructor and __proto__ are now handled correctly when creating document chunks and reading link graphs. Links and metadata for these IDs are preserved alongside those for ordinary IDs.
    • Link graphs continue to be returned as ordinary objects, and empty documents produce no chunks or graph entries.