fix(rag): vectorize chapters from epub toc structure#430
Open
codedogQBY wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
numberfromragTocwhile keepingindexas the value to pass into chapter tools.Analysis
Before this change, desktop vectorization iterated
book.sectionsand created oneChapterDataper spine section. That means front matter, volume title pages, split XHTML files, and other non-chapter sections could become AI-visible “chapters”. For EPUBs with multi-volume TOCs, asking about a numbered chapter could lead the model to inspect the wrong section or a fallbackSection Ntitle instead of the actual book structure.The new grouping follows the EPUB TOC: leaf TOC entries become logical chapters, parent entries such as volume nodes are used as boundaries, and multiple spine sections between chapter anchors are merged into one vectorized chapter. If an EPUB has no usable TOC anchors, extraction falls back to the previous one-section-per-entry behavior.
Fixes #411
Verification
git diff --checkpnpm --filter @readany/core test -- chapter-structure toolspnpm --filter @readany/core exec tsc --noEmitpnpm --filter app exec tsc --noEmitpnpm exec biome check packages/core/src/rag/chapter-structure.ts packages/core/src/rag/chapter-structure.test.ts packages/core/src/rag/index.ts packages/core/src/ai/tools/rag-tools.ts packages/core/src/ai/__tests__/tools.test.ts packages/app/src/lib/rag/book-extractor.ts(passes with existingnoExplicitAnywarnings in legacy test/extractor code)