@chonkiejs/ chunk
最快的文本块库——最多1TB/s吞吐量
你知道每个块的图书馆 都声称是快的吗? 是的,我们真的是认真的.
@chonkiejs/ chunk 在语义边界(期,新行,常被怀疑者)中分出文字,这样做会很蠢快. 我们说的是"快把整个英语维基百科打入120米".
想知道如何吗? 读取博客文章 在那里,我们书呆子 关于SIMD指示和检索表.
安装
npm install @chonkiejs/chunk
使用时间
import { init, chunk } from '@chonkiejs/chunk';
// initialize wasm (required once)
await init();
const text = "Hello world. How are you? I'm fine.\nThanks for asking.";
// with defaults (4KB chunks, split at \n . ?)
for (const slice of chunk(text)) {
console.log(slice);
}
// with custom size
for (const slice of chunk(text, { size: 1024 })) {
console.log(slice);
}
// with custom delimiters
for (const slice of chunk(text, { delimiters: ".?!\n" })) {
console.log(slice);
}
// with multi-byte pattern (e.g., metaspace ▁ for SentencePiece tokenizers)
for (const slice of chunk(text, { pattern: "▁", prefix: true })) {
console.log(slice);
}
// with consecutive pattern handling (split at START of runs, not middle)
for (const slice of chunk("word next", { pattern: " ", consecutive: true })) {
console.log(slice);
}
// with forward fallback (search forward if no pattern in backward window)
for (const slice of chunk(text, { pattern: " ", forwardFallback: true })) {
console.log(slice);
}
// collect all chunks
const chunks = [...chunk(text)];
传递字符串,并获取字符串回来。 二进制数据的零复制性能,通过 Uint8Array 你会得到 Uint8Array 回头看.
引用语录
如果您在研究中使用了@chonkiejs/chunk,请引用如下:
@software{chunk2025,
author = {Minhas, Bhavnick},
title = {chunk: The fastest text chunking library},
year = {2025},
publisher = {GitHub},
howpublished = {\url{https://github.com/chonkie-inc/chunk}},
}
许可证
根据其中任何一种方式颁发许可证 Apache 许可证,2.0版本 或者说 麻省理工学院许可证 随便你.