Repository navigation
fix(rag): map Markdown chunks to original source ranges #1543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/rag": patch | ||
| --- | ||
|
|
||
| fix(rag): map MarkdownChunker ranges and position metadata back to the original Markdown source, including sections, CRLF, list/quote markers, and fenced code. Addresses the Markdown offsets portion of #1542. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,10 @@ export class RecursiveChunker implements Chunker<RecursiveChunkerOptions> { | |
| ]; | ||
| } | ||
|
|
||
| // The sentence chunk's content may omit leading whitespace. Token | ||
| // offsets are relative to that content, not to the whole paragraph. | ||
| const groupStart = paragraph.text.indexOf(chunk.content, chunk.start); | ||
| const contentStart = groupStart >= 0 ? groupStart : chunk.start; | ||
| // Fallback to token chunking for oversized sentence group | ||
| return this.tokenChunker | ||
| .chunk(chunk.content, { | ||
|
|
@@ -101,8 +105,8 @@ export class RecursiveChunker implements Chunker<RecursiveChunkerOptions> { | |
| .map((tokenChunk, idx) => ({ | ||
| ...tokenChunk, | ||
| id: `recursive-${chunks.length + idx}`, | ||
| start: paragraph.start + (tokenChunk.start ?? 0), | ||
| end: paragraph.start + (tokenChunk.end ?? 0), | ||
| start: paragraph.start + contentStart + (tokenChunk.start ?? 0), | ||
| end: paragraph.start + contentStart + (tokenChunk.end ?? 0), | ||
|
Comment on lines
+108
to
+109
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default tokenizer offsets drift for characters split across tokens.
The new lines in Fix the coordinate calculation in
|
||
| metadata: { | ||
| ...tokenChunk.metadata, | ||
| ...buildMetadata({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.