[inter-v2-04] Chunking cho RAG embedding — trace + demo test - #426
Open
Supermonters wants to merge 5 commits into
Open
Supermonters wants to merge 5 commits into
Supermonters wants to merge 5 commits into
Conversation
Document chunk_markdown behavior for issue #411 via demo and break-it unit tests without changing production chunking logic. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Floor test does not lock 200
- Both floor tests now assert the first hard-cut piece is exactly 200 characters, so removing or lowering max(200) fails CI.
- ✅ Fixed: UTF-8 assert always succeeds
- Replaced the always-true str-end boundary check with source-span char-boundary asserts and a mid-glyph cut check on Vietnamese ệ.
Or push these changes by commenting:
@cursor push 5a8e6ab23c
Preview (5a8e6ab23c)
diff --git a/crates/core/src/chunk.rs b/crates/core/src/chunk.rs
--- a/crates/core/src/chunk.rs
+++ b/crates/core/src/chunk.rs
@@ -392,8 +392,13 @@
.count()
>= 2
);
+ let mut cursor = 0usize;
for c in &chunks {
- assert!(c.text.is_char_boundary(c.text.len()));
+ let (start, end) = locate_chunk_text(&md, cursor, &c.text).expect("span");
+ assert!(md.is_char_boundary(start));
+ assert!(md.is_char_boundary(end));
+ assert_eq!(&md[start..end], c.text.as_str());
+ cursor = end;
}
}
@@ -433,9 +438,21 @@
// max_chars=100 bị sàn lên 200 — vẫn phải cắt và UTF-8-safe.
let chunks = chunk_markdown(&md, 100);
assert!(chunks.len() >= 2);
+ assert_eq!(
+ chunks[0].chars, 200,
+ "first hard-cut piece must be the 200 floor"
+ );
+ assert!(chunks.iter().all(|c| c.chars <= 200));
+ let mut cursor = 0usize;
for c in &chunks {
- assert!(c.chars <= 200);
assert!(!c.text.is_empty());
+ let (start, end) = locate_chunk_text(&md, cursor, &c.text).expect("span");
+ assert!(md.is_char_boundary(start));
+ assert!(md.is_char_boundary(end));
+ assert_eq!(&md[start..end], c.text.as_str());
+ // ệ is 3 bytes — a mid-glyph offset must not be treated as a cut point.
+ assert!(!md.is_char_boundary(start + 1));
+ cursor = end;
}
}
@@ -466,6 +483,10 @@
let md = "# A\n\n".to_string() + &"y".repeat(250);
let chunks = chunk_markdown(&md, 50);
assert!(chunks.len() >= 2);
+ assert_eq!(
+ chunks[0].chars, 200,
+ "first hard-cut piece must be the 200 floor"
+ );
assert!(chunks.iter().all(|c| c.chars <= 200));
}
}You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 26c2f61. Configure here.
Drop inter_v2_04_* prefixes so chunk unit tests match existing naming style. Co-authored-by: Cursor <cursoragent@cursor.com>
Address Bugbot review on PR #426: lock max_chars floor at 200 and validate source spans instead of tautological str end checks. Co-authored-by: Cursor <cursoragent@cursor.com>
pnpm audit --audit-level high reported nanoid <3.3.18 via vite/postcss; override was pinned at 3.3.17. Co-authored-by: Cursor <cursoragent@cursor.com>
The Vietnamese hard-cut test only checked spans it had just located, so a cut that silently dropped a glyph between pieces still passed. Verify glyph integrity per piece and rejoin the located spans back into the source paragraph. Co-authored-by: Chi Dung Nguyen <Supermonters@users.noreply.github.com>
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.


Closes #411
cc @anhnth24 — em xin gửi PR inter-v2-04 để anh review ạ.
Summary
crates/core/src/chunk.rs(mod tests): demo chunk RAG + test phá adversarial trên Markdown inline.chunk_markdown→prepare_chunks(server) →canonical_input(embedding payload{heading}\n{body}).bench/INTER_V2_*hay fixture.mdriêng.Thay đổi file
crates/core/src/chunk.rsinter_v2_04_chunk_rag_trace_demomax_chars = 320để thấy split; production = 2000).inter_v2_04_empty_heading_body_only/inter_v2_04_crlf_embedding_body_is_lf\r\ntrên nguồn.inter_v2_04_adversarial_*(test phá)#KhôngSpacekhông phải heading; empty/whitespace → 0 chunk; hard cut chữ Việt UTF-8-safe; duplicate body anchor order;max_charsdưới sàn 200.Học tập — chunk-level vs run-level
conv/docx.rs): đơn vị<w:r>Word — gộp trước khi ra Markdown.chunk.rs): chia Markdown theo# headingcho RAG/embed; fieldheading="Cha > Con".ApprovedEmbeddingRuntime::canonical_input(heading_joined, body)→"{heading}\n{body}".bodyLF + span gốc).Demo chunk (max_chars=320) → chunk nào được embed?
Phần I\nGiới thiệu.→ Mọi chunk body non-empty sau
prepare_chunksđều embed; desktopbuild_corpuschỉ bỏ chunk page-marker-only.Test nào pass? Assertion nào validate?
chunks.len() >= 5Phần I,Phần I > Mục 1 > Tiểu mục 1.1chunks[i].index == i\r\n#KhôngSpace→ body not headingTest phá — kết quả
""/ whitespace only#KhôngSpaceệ×250 hard cut, max_chars=100xunder# A/# Bheading = String::new()trongpush_chunkVì sao test trong
chunk.rs(không integration server)?chunk_markdown/locate_chunk_spantrực tiếp; serverprepare_chunksđã có test riêng (chưa chạy local macOS —fileconv-servercompile fail sandbox mount trên Darwin).Test plan
cargo fmt --all -- --checkcargo metadata --locked --format-version 1 --no-depspython3 scripts/check-dependency-policy.pycargo test -p fileconv-core inter_v2_04 -- --nocapturecargo test -p fileconv-core chunk::cargo test -p fileconv-server prepare_chunks(blocked local: server crate compile trên macOS — CI Linux)push_chunkheading → test đỏ; restore → xanhMade with Cursor