{"id":13215,"date":"2024-11-13T18:24:04","date_gmt":"2024-11-13T10:24:04","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=13215"},"modified":"2025-08-25T01:23:40","modified_gmt":"2025-08-24T17:23:40","slug":"chonkie","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/chonkie\/","title":{"rendered":"Chonkie\uff1a\u8f7b\u91cf\u7ea7RAG\u6587\u672c\u5207\u5757\u5e93"},"content":{"rendered":"<p>Chonkie \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u4e14\u9ad8\u6548\u7684 RAG\uff08Retrieval-Augmented Generation\uff09\u6587\u672c\u5207\u5757\u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u3001\u7b80\u4fbf\u5730\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u5757\u5904\u7406\u3002\u8be5\u5e93\u652f\u6301\u591a\u79cd\u5206\u5757\u65b9\u6cd5\uff0c\u5305\u62ec\u57fa\u4e8e\u6807\u8bb0\u3001\u5355\u8bcd\u3001\u53e5\u5b50\u548c\u8bed\u4e49\u76f8\u4f3c\u6027\u7684\u5206\u5757\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u6587\u672c\u5904\u7406\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u3002\u9ed8\u8ba4\u5b89\u88c5\u53ea\u970021MB\uff08\u5176\u4ed6\u540c\u7c7b\u4ea7\u54c1\u9700\u898180-171MB\uff09 \u652f\u6301\u6240\u6709\u4e3b\u6d41\u5206\u8bcd\u5668\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li><strong>TokenChunker<\/strong>\uff1a\u5c06\u6587\u672c\u5206\u5272\u6210\u56fa\u5b9a\u5927\u5c0f\u7684\u6807\u8bb0\u5757\u3002<\/li>\n<li><strong>WordChunker<\/strong>\uff1a\u6839\u636e\u5355\u8bcd\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SentenceChunker<\/strong>\uff1a\u6839\u636e\u53e5\u5b50\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SemanticChunker<\/strong>\uff1a\u6839\u636e\u8bed\u4e49\u76f8\u4f3c\u6027\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SDPMChunker<\/strong>\uff1a\u4f7f\u7528\u8bed\u4e49\u53cc\u91cd\u5408\u5e76\u65b9\u6cd5\u5206\u5272\u6587\u672c\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5<\/h3>\n<p>\u8981\u5b89\u88c5 Chonkie\uff0c\u53ea\u9700\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>pip install chonkie\r\n<\/code><\/pre>\n<p>Chonkie \u9075\u5faa\u6700\u5c0f\u5316\u9ed8\u8ba4\u5b89\u88c5\u7684\u539f\u5219\uff0c\u5efa\u8bae\u6839\u636e\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7684\u5206\u5757\u5668\uff0c\u6216\u8005\u5982\u679c\u4e0d\u60f3\u8003\u8651\u4f9d\u8d56\u5173\u7cfb\uff0c\u53ef\u4ee5\u5b89\u88c5\u6240\u6709\u5206\u5757\u5668\uff08\u4e0d\u63a8\u8350\uff09\u3002<\/p>\n<pre><code>pip install chonkie[all]\r\n<\/code><\/pre>\n<h3>\u4f7f\u7528<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u793a\u4f8b\uff0c\u5e2e\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\uff1a<\/p>\n<ol>\n<li>\u9996\u5148\u5bfc\u5165\u6240\u9700\u7684\u5206\u5757\u5668\uff1a\n<pre><code>from chonkie import TokenChunker\r\n<\/code><\/pre>\n<\/li>\n<li>\u5bfc\u5165\u60a8\u559c\u6b22\u7684\u6807\u8bb0\u5668\u5e93\uff08\u652f\u6301 AutoTokenizers, TikToken \u548c AutoTikTokenizer\uff09\uff1a\n<pre><code>from tokenizers import Tokenizer\r\ntokenizer = Tokenizer.from_pretrained(\"gpt2\")\r\n<\/code><\/pre>\n<\/li>\n<li>\u521d\u59cb\u5316\u5206\u5757\u5668\uff1a\n<pre><code>chunker = TokenChunker(tokenizer)\r\n<\/code><\/pre>\n<\/li>\n<li>\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u5757\uff1a\n<pre><code>chunks = chunker(\"Woah! Chonkie, the chunking library is so cool! I love the tiny hippo hehe.\")\r\n<\/code><\/pre>\n<\/li>\n<li>\u8bbf\u95ee\u5206\u5757\u7ed3\u679c\uff1a\n<pre><code>for chunk in chunks:\r\nprint(f\"Chunk: {chunk.text}\")\r\nprint(f\"<a href=\"https:\/\/www.kdjingpai.com\/de\/tokenization\/\">Tokens<\/a>: {chunk.token_count}\")\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u652f\u6301\u7684\u65b9\u6cd5<\/h3>\n<p>Chonkie \u63d0\u4f9b\u591a\u79cd\u5206\u5757\u5668\uff0c\u5e2e\u52a9\u60a8\u9ad8\u6548\u5730\u4e3a <a href=\"https:\/\/www.kdjingpai.com\/de\/rag\/\">RAG<\/a> \u5e94\u7528\u7a0b\u5e8f\u62c6\u5206\u6587\u672c\u3002\u4ee5\u4e0b\u662f\u53ef\u7528\u5206\u5757\u5668\u7684\u7b80\u8981\u6982\u8ff0\uff1a<\/p>\n<ul>\n<li><strong>TokenChunker<\/strong>\uff1a\u5c06\u6587\u672c\u5206\u5272\u6210\u56fa\u5b9a\u5927\u5c0f\u7684\u6807\u8bb0\u5757\u3002<\/li>\n<li><strong>WordChunker<\/strong>\uff1a\u6839\u636e\u5355\u8bcd\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SentenceChunker<\/strong>\uff1a\u6839\u636e\u53e5\u5b50\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SemanticChunker<\/strong>\uff1a\u6839\u636e\u8bed\u4e49\u76f8\u4f3c\u6027\u5c06\u6587\u672c\u5206\u6210\u5757\u3002<\/li>\n<li><strong>SDPMChunker<\/strong>\uff1a\u4f7f\u7528\u8bed\u4e49\u53cc\u91cd\u5408\u5e76\u65b9\u6cd5\u5206\u5272\u6587\u672c\u3002<\/li>\n<\/ul>\n<h3>\u57fa\u51c6\u6d4b\u8bd5<\/h3>\n<p>Chonkie \u5728\u591a\u4e2a\u57fa\u51c6\u6d4b\u8bd5\u4e2d\u8868\u73b0\u51fa\u8272\uff1a<\/p>\n<ul>\n<li><strong>\u5c3a\u5bf8<\/strong>\uff1a\u9ed8\u8ba4\u5b89\u88c5\u4ec5 9.7MB\uff08\u5176\u4ed6\u7248\u672c\u4e3a 80-171MB\uff09\uff0c\u5373\u4f7f\u5305\u542b\u8bed\u4e49\u5206\u5757\uff0c\u4ecd\u7136\u6bd4\u7ade\u4e89\u5bf9\u624b\u66f4\u8f7b\u3002<\/li>\n<li><strong>\u901f\u5ea6<\/strong>\uff1a\u6807\u8bb0\u5206\u5757\u6bd4\u6700\u6162\u7684\u66ff\u4ee3\u65b9\u6848\u5feb 33 \u500d\uff0c\u53e5\u5b50\u5206\u5757\u6bd4\u7ade\u4e89\u5bf9\u624b\u5feb\u8fd1 2 \u500d\uff0c\u8bed\u4e49\u5206\u5757\u6bd4\u5176\u4ed6\u65b9\u6cd5\u5feb 2.5 \u500d\u3002<\/li>\n<\/ul>\n<h3>\u8be6\u7ec6\u64cd\u4f5c\u6d41\u7a0b<\/h3>\n<ol>\n<li><strong>\u5b89\u88c5\u5e93<\/strong>\uff1a\u901a\u8fc7 pip \u5b89\u88c5 Chonkie \u548c\u6240\u9700\u7684\u6807\u8bb0\u5668\u5e93\u3002<\/li>\n<li><strong>\u5bfc\u5165\u5e93<\/strong>\uff1a\u5728\u60a8\u7684 Python \u811a\u672c\u4e2d\u5bfc\u5165 Chonkie \u548c\u6807\u8bb0\u5668\u5e93\u3002<\/li>\n<li><strong>\u521d\u59cb\u5316\u5206\u5757\u5668<\/strong>\uff1a\u6839\u636e\u60a8\u7684\u9700\u6c42\u9009\u62e9\u5e76\u521d\u59cb\u5316\u5408\u9002\u7684\u5206\u5757\u5668\u3002<\/li>\n<li><strong>\u5206\u5757\u6587\u672c<\/strong>\uff1a\u4f7f\u7528\u521d\u59cb\u5316\u7684\u5206\u5757\u5668\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u5757\u5904\u7406\u3002<\/li>\n<li><strong>\u5904\u7406\u7ed3\u679c<\/strong>\uff1a\u904d\u5386\u5206\u5757\u7ed3\u679c\uff0c\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5904\u7406\u6216\u5206\u6790\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Chonkie \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u4e14\u9ad8\u6548\u7684 RAG\uff08Retrieval-Augmented Generation\uff09\u6587\u672c\u5207\u5757\u5e93\uff0c\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u3001\u7b80\u4fbf\u5730\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u5757\u5904\u7406\u3002\u8be5\u5e93\u652f\u6301\u591a\u79cd\u5206\u5757\u65b9\u6cd5\uff0c\u5305\u62ec\u57fa\u4e8e\u6807\u8bb0\u3001\u5355\u8bcd\u3001\u53e5\u5b50\u548c\u8bed\u4e49\u76f8\u4f3c\u6027\u7684\u5206\u5757\u65b9\u5f0f\uff0c\u9002\u7528&#8230;<\/p>\n","protected":false},"author":1,"featured_media":32782,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,499],"tags":[230,252],"class_list":["post-13215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","category-document-extraction","tag-aikaiyuanxiangmu","tag-markdown"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/13215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=13215"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/13215\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/32782"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=13215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=13215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=13215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}