Skip to content

RAG core library (M1): chunking, ingestion and cited context retrieval - #17

Open
roshni-shah-promact wants to merge 17 commits into
masterfrom
feat/rag-core
Open

roshni-shah-promact wants to merge 17 commits into
masterfrom
feat/rag-core

Conversation

@roshni-shah-promact

@roshni-shah-promact roshni-shah-promact commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Milestone M1 of the Node.js RAG spec (docs/specs/rag-service-spec.md, NRAG-06 → NRAG-12): the @promact/rag-core library. The package is "private": true, so nothing gets published.

  • TXT/Markdown extraction into a structured element model, plus a compact Markdown renderer
  • Cleaner chain (whitespace/Unicode, invisible-character stripping, duplicate blocks)
  • Structure-aware, token-budgeted chunker (heading path, parent–child, no mid-table/code splits)
  • In-memory VectorStore + incremental ingestion (doc-hash skip, chunk reuse, last-writer-wins)
  • Retriever (mandatory in-query tenant/ACL filter, MMR) + budgeted context packer with [n] citations
  • Spec update: file-based store (no database server) added to v0.1 as NRAG-34

Review notes

Built by unattended cloud runs, then reviewed by Opus, which fixed 3 defects, each with a regression test:

  • cross-tenant record overwrite in the memory store
  • over-budget chunks with fenced code
  • version bump not recorded

Please decide the open questions listed in docs/specs/rag-progress.md → "Blocked / questions". Most important:

  • store record identity is (tenantId, chunkId)
  • aclGroups: [] hides a document from everyone
  • findByContentHash is not tenant-scoped

Checks

npm run build && npm run lint && npx jest all pass. rag-core has 100% line coverage.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

roshni-shah-23 and others added 17 commits November 9, 2026 15:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tible mdast stack)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…verage gate

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… validation

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…enderer (NRAG-08)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjihb1EBKPQCRVnkGtu
…l stats (NRAG-09)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjihb1EBKPQCRVnkGtu
…), follow-up to NRAG-09

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjihb1EBKPQCRVnkGtu
…ble ids (NRAG-10)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjihb1EBKPQCRVnkGtu
…AG-11)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjihb1EBKPQCRVnkGtu
…ss-tenant overwrite

Chunk ids hash documentId, which is only unique per tenant. Two tenants ingesting the same
documentId with identical content produced the same chunk ids, and the second upsert silently
replaced the first tenant's records (tenant A lost its index; a deleteDocument by A then
removed nothing). Records are now keyed by (tenantId, chunkId) and the VectorStore contract
documents that adapters must do the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjmJ9SAbwyR7KkkFZzs
…budgets

When the code fence markers alone exceeded the budget (e.g. a `typescript` fence with
maxTokens 4), code was split down to single characters but each piece was still wrapped in a
fence, yielding chunks above maxTokens. Such code is now emitted unfenced, and make() refuses
(throws) instead of silently emitting an over-budget chunk when no valid chunking exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjmJ9SAbwyR7KkkFZzs
Re-ingesting identical content under a higher version returned 'unchanged' without touching
the stored records, so they kept the old version number. A later ingest of an in-between
older version (e.g. v1 stored, v3 identical, then v2) passed the staleness check and replaced
the newest content, breaking last-writer-wins (§8.4). Such bumps now re-upsert the records
with the new version (all vectors reused, nothing re-embedded) and still report 'unchanged'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjmJ9SAbwyR7KkkFZzs
…ver (NRAG-12)

- createRetriever: mandatory tenant/ACL filter validated and passed into the store query,
  hybrid degrades to vector with a one-time warning, minScore (re-checked after the adapter),
  MMR (default on, lambda 0.7, candidates capped at 50).
- packContext: fills highest score first up to maxTokens - margin (default 4000, counter
  margin 5%/15%), measured on the final rendered text so it can never go over budget; merges
  adjacent chunks of a section, expands to the parent only if it fits, strongest blocks at the
  edges, [n] labels with a citations array.
- VectorStore.getByIds (filtered like search) for parent expansion; createRag.getContext wired.
- Cross-tenant leakage, ACL trimming and over-budget property tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjmJ9SAbwyR7KkkFZzs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JotNjmJ9SAbwyR7KkkFZzs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

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: 9bd8fd33-df19-4916-bea9-fc19293792cc
  • 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

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.

3 participants