Repository navigation
fix(rag): use the configured tokenizer for Slumber overlap #1547
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
Open
embrace897
wants to merge
6
commits into
VoltAgent:main
Choose a base branch
from
embrace897:fix/rag-slumber-token-overlap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13c805f
fix(rag): use the configured tokenizer for Slumber overlap
embrace897 9d0cec3
fix(rag): derive overlap ranges from source text
embrace897 1e9b135
fix(rag): map tiktoken byte spans to source characters
embrace897 80d7574
fix(rag): strengthen Unicode range regressions and reuse encoding tables
embrace897 91b49fc
fix(rag): align token windows with complete source spans
embrace897 63fae48
fix(rag): normalize token budgets before indexing
embrace897 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/rag": patch | ||
| --- | ||
|
|
||
| Use the configured tokenizer to select overlap text in SlumberChunker. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { Tokenizer } from "../types"; | ||
| import { SlumberChunker } from "./slumber-chunker"; | ||
|
|
||
| const tokenize: Tokenizer["tokenize"] = (text) => | ||
| Array.from(text.matchAll(/[a-z]+|\S/gi), (match) => ({ | ||
| value: match[0], | ||
| start: match.index, | ||
| end: match.index + match[0].length, | ||
| })); | ||
|
|
||
| describe("SlumberChunker overlap", () => { | ||
| it.each([" ", " ", "\n", "\r\n"])("preserves the overlap source range after %j", (separator) => { | ||
| const text = `First.${separator}red-blue.`; | ||
| const chunks = new SlumberChunker().chunk(text, { | ||
| maxTokens: 4, | ||
| minTokens: 2, | ||
| overlapTokens: 1, | ||
| tokenizer: { tokenize, countTokens: (value) => tokenize(value).length }, | ||
| }); | ||
| const overlap = chunks.find((chunk) => chunk.label === "slumber-overlap"); | ||
| expect(overlap).toBeDefined(); | ||
| expect(overlap?.content).toBe("red"); | ||
| expect(overlap?.start).toBe(text.indexOf("red")); | ||
| expect(overlap?.end).toBe(text.indexOf("red") + 3); | ||
| expect(text.slice(overlap?.start, overlap?.end)).toBe(overlap?.content); | ||
| }); | ||
|
|
||
| it("uses the configured tokenizer to select the overlap and its source range", () => { | ||
| const text = "First.red-blue."; | ||
| const chunks = new SlumberChunker().chunk(text, { | ||
| maxTokens: 4, | ||
| minTokens: 2, | ||
| overlapTokens: 1, | ||
| tokenizer: { tokenize, countTokens: (value) => tokenize(value).length }, | ||
| }); | ||
|
|
||
| expect(chunks.map(({ content }) => content)).toEqual(["First.", "red", "red-blue."]); | ||
| expect(chunks[1]).toMatchObject({ start: 6, end: 9 }); | ||
| }); | ||
| }); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.