Skip to content

fix: preserve Capire chunk context and token budgets - #232

Open
larsPlessing wants to merge 1 commit into
mainfrom
fix/capire-chunk-budget-and-dedup
Open

larsPlessing wants to merge 1 commit into
mainfrom
fix/capire-chunk-budget-and-dedup

Conversation

@larsPlessing

Copy link
Copy Markdown
Contributor

Summary

  • Pack list-item openers as content that occurs once. Do not charge their token cost to every nested fragment.
  • Remove duplicates by rendered embedding text, display text, and runtime label. Preserve different headings and retrieval context. Identical content under different source anchors is still removed.
  • Add unit and pipeline regression tests for nested warnings, long openers, repeated prose under different headings, display context, split fragments, and runtime labels.

Cause and reproduction

The chunking pipeline for cds-mcp createCapireEmbeddings --model sentence-transformers/all-MiniLM-L6-v2 --model Xenova/all-MiniLM-L6-v2 dropped 235 duplicates for each model.

A list-item opener was included in every nested token measurement but emitted only once. With a 126-token content budget, this produced warning fragments containing only /, s, or -. The duplicate key also ignored headings and display context.

Live-document verification

Compared the original and updated chunking pipelines with the same documentation input and both model tokenizers. No embeddings were generated.

Result, per model Before After
Packed chunks 13,069 12,573
Duplicate drops 235 100
Retained chunks 12,091 11,770
Retained chunks in the affected section 96 12
Retained fragments of the affected warning 75 1

Affected section: https://cap.cloud.sap/docs/java/working-with-cql/query-execution#updatable-views

All updated rendered chunks pass the maximum-token check. Eleven short-body warnings remain.

Tests

  • npm test -- --test-reporter=dot
  • npm run lint
  • Formatting check for all five changed files
  • git diff --check

All checks passed locally on Node.js 24.15.0. No public API changes.

Pack list-item openers once instead of charging their token cost to every nested fragment. Compare rendered embedding text, display text, and runtime labels when removing duplicates so distinct headings and retrieval context remain available.

Add unit and pipeline regression tests. With both MiniLM models, live-document duplicate drops decrease from 235 to 100 and the affected warning remains one complete chunk. Full tests, lint, and formatting checks pass. No public API changes.
@larsPlessing
larsPlessing requested a review from a team as a code owner November 11, 2026 16:20
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Preserve Capire Chunk Context and Token Budgets

Bug Fix

🐛 Corrected Capire chunk packing so list-item openers consume the token budget only once, preventing nested warnings from being split into incomplete fragments. Deduplication now considers rendered embedding text, display context, and runtime labels, preserving semantically distinct chunks while still removing exact duplicates across source anchors.

Changes

  • lib/capireEmbeddings/chunker/stages/07-packBlocks.js: Packs list openers as standalone content instead of charging their token cost to every nested fragment.
  • lib/capireEmbeddings/chunker/stages/08-filter.js: Uses rendered embedding text, display text, and runtime labels as the duplicate key.
  • tests/markdownEmbeddings/pipeline.test.js: Adds pipeline regressions for nested warnings, token limits, and repeated prose under different headings.
  • tests/markdownEmbeddings/stages/07-packBlocks.test.js: Verifies short and oversized list openers are charged once while nested warnings remain intact.
  • tests/markdownEmbeddings/stages/08-filter.test.js: Covers heading context, display context, split fragments, runtime labels, and exact duplicate removal.

All rendered chunks remain within the configured token limit. No public API changes are introduced.

Validation

  • npm test -- --test-reporter=dot
  • npm run lint
  • Formatting checks
  • git diff --check

Images and Links


  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.33.47

  • Event Trigger: pull_request.opened
  • Correlation ID: dc468c20-ddeb-11f1-934e-c7dc2592b94b
  • File Content Strategy: Full file content
  • Output Template: Default Template
  • Summary Prompt: Default Prompt
  • LLM: gpt-5.6-sol

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No substantive correctness or maintainability issues found in the changed code. The regression tests cover the revised token-budget and deduplication behavior well.

PR Bot Information

Version: 1.33.47

  • Experiment Variant: control
  • Event Trigger: pull_request.opened
  • Correlation ID: dc468c20-ddeb-11f1-934e-c7dc2592b94b
  • File Content Strategy: Full file content
  • LLM: gpt-5.6-sol

@vkozyura vkozyura left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This branch has not been deployed

No deployments
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.

2 participants