2024-11-13 10:15 湖北
提供Token、词、句子、语义、双重语义切块
Chonkie:实用的RAG分块库,轻量级、速度快,可随时对文本进行分块
Chonkie 提供了多个分块器,可高效地为RAG应用程序拆分文本。以下是可用分块器的简要概述:
TokenChunker:将文本分割成固定大小的标记块。
WordChunker:根据单词将文本分成块。
SentenceChunker:根据句子将文本分成块。
SemanticChunker:根据语义相似性将文本分成块。
SDPMChunker:使用语义双重合并方法分割文本。
尺寸
默认安装: 9.7MB(其他版本为 80-171MB)
具有语义:仍然比竞争对手更轻!
速度
token分块:比最慢的替代方案快 33 倍
句子分块:比竞争对手快近 2 倍
语义分块:比其他方法快 2.5 倍
####
pip install chonkie
# First import the chunker you want from Chonkie
from chonkie import TokenChunker
# Import your favorite tokenizer library
# Also supports AutoTokenizers, TikToken and AutoTikTokenizer
from tokenizers import Tokenizer
tokenizer = Tokenizer.from_pretrained("gpt2")
# Initialize the chunker
chunker = TokenChunker(tokenizer)
# Chunk some text
chunks = chunker("Woah! Chonkie, the chunking library is so cool! I love the tiny hippo hehe.")
# Access chunks
for chunk in chunks:
print(f"Chunk: {chunk.text}")
print(f"Tokens: {chunk.token_count}")
https://github.com/bhavnicksm/chonkie
https://pypi.org/project/chonkie/
推荐阅读
• 对齐LLM偏好的直接偏好优化方法:DPO、IPO、KTO
• RAG全景图:从RAG启蒙到高级RAG之36技,再到终章Agentic RAG!
• Agent到多模态Agent再到多模态Multi-Agents系统的发展与案例讲解(1.2万字,20+文献,27张图)
欢迎关注我的公众号“PaperAgent”,每天一篇大模型(LLM)文章来锻炼我们的思维,简单的例子,不简单的方法,提升自己。