{"id":14542,"date":"2024-11-29T20:46:32","date_gmt":"2024-11-29T12:46:32","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=14542"},"modified":"2025-07-14T02:59:03","modified_gmt":"2025-07-13T18:59:03","slug":"raglite","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/raglite\/","title":{"rendered":"RAGLite\uff1a\u9ad8\u6548\u7684\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u5de5\u5177\uff0c\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u548c\u8bed\u8a00\u6a21\u578b\u3002"},"content":{"rendered":"<p>RAGLite \u662f\u4e00\u4e2a\u7528\u4e8e\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u7684 Python \u5de5\u5177\u5305\uff0c\u652f\u6301 PostgreSQL \u6216 SQLite \u6570\u636e\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879\uff0c\u5141\u8bb8\u7528\u6237\u9009\u62e9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u91cd\u6392\u5e8f\u5668\u3002RAGLite \u4ee5\u5176\u8f7b\u91cf\u7ea7\u548c\u9ad8\u6548\u7684\u7279\u6027\u8457\u79f0\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5e76\u652f\u6301\u591a\u79cd\u52a0\u901f\u9009\u9879\uff0c\u5982 Metal \u548c CUDA\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14543\" title=\"RAGLite\uff1a\u9ad8\u6548\u7684\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u5de5\u5177\uff0c\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u548c\u8bed\u8a00\u6a21\u578b\u3002-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e.png\" alt=\"RAGLite\uff1a\u9ad8\u6548\u7684\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u5de5\u5177\uff0c\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u548c\u8bed\u8a00\u6a21\u578b\u3002-1\" width=\"1149\" height=\"834\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e.png 1149w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e-300x218.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e-1024x743.png 1024w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e-768x557.png 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/11\/4f320fb7e96ca2e-18x12.png 18w\" sizes=\"auto, (max-width: 1149px) 100vw, 1149px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li>\u652f\u6301\u591a\u79cd\u8bed\u8a00\u6a21\u578b\uff0c\u5305\u62ec\u672c\u5730 llama-cpp-python \u6a21\u578b<\/li>\n<li>\u652f\u6301 PostgreSQL \u548c SQLite \u4f5c\u4e3a\u5173\u952e\u8bcd\u548c\u5411\u91cf\u68c0\u7d22\u6570\u636e\u5e93<\/li>\n<li>\u63d0\u4f9b\u591a\u79cd\u91cd\u6392\u5e8f\u5668\u9009\u9879\uff0c\u5305\u62ec\u591a\u8bed\u8a00 FlashRank<\/li>\n<li>\u8f7b\u91cf\u7ea7\u4f9d\u8d56\uff0c\u65e0\u9700 PyTorch \u6216 LangChain<\/li>\n<li>\u652f\u6301 PDF \u8f6c Markdown \u8f6c\u6362<\/li>\n<li>\u591a\u5411\u91cf\u5d4c\u5165\u548c\u4e0a\u4e0b\u6587\u5757\u6807\u9898<\/li>\n<li>\u63d0\u4f9b\u53ef\u5b9a\u5236\u7684 <a href=\"https:\/\/www.kdjingpai.com\/ja\/chatgpt-6\/\">ChatGPT<\/a> \u7c7b\u524d\u7aef\uff0c\u652f\u6301 Web\u3001Slack \u548c Teams<\/li>\n<li>\u652f\u6301\u591a\u79cd\u6587\u4ef6\u7c7b\u578b\u7684\u6587\u6863\u63d2\u5165\u548c\u68c0\u7d22<\/li>\n<li>\u63d0\u4f9b\u68c0\u7d22\u548c\u751f\u6210\u6027\u80fd\u8bc4\u4f30\u5de5\u5177<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5\u6d41\u7a0b<\/h3>\n<ol>\n<li>\u5b89\u88c5 spaCy \u7684\u591a\u8bed\u8a00\u53e5\u5b50\u6a21\u578b\uff1a\n<pre><code>pip install https:\/\/github.com\/explosion\/spacy-models\/releases\/download\/xx_sent_ud_sm-3.7.0\/xx_sent_ud_sm-3.7.0-py3-none-any.whl\r\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u52a0\u901f\u7684 llama-cpp-python \u9884\u7f16\u8bd1\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u53ef\u9009\u4f46\u63a8\u8350\uff09\uff1a\n<pre><code>LLAMA_CPP_PYTHON_VERSION=0.2.88 PYTHON_VERSION=310 ACCELERATOR=metal | cu121 | cu122 | cu123 | cu124 PLATFORM=macosx_11_0_arm64 | linux_x86_64 | win_amd64\r\npip install \"https:\/\/github.com\/abetlen\/llama-cpp-python\/releases\/download\/v$LLAMA_CPP_PYTHON_VERSION-$ACCELERATOR\/llama_cpp_python-$LLAMA_CPP_PYTHON_VERSION-cp$PYTHON_VERSION-cp$PYTHON_VERSION-$PLATFORM.whl\"\r\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5 RAGLite\uff1a\n<pre><code>pip install raglite\r\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u53ef\u5b9a\u5236\u7684 ChatGPT \u7c7b\u524d\u7aef\u652f\u6301\uff1a\n<pre><code>pip install raglite[chainlit]\r\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u5176\u4ed6\u6587\u4ef6\u7c7b\u578b\u652f\u6301\uff1a\n<pre><code>pip install raglite[pandoc]\r\n<\/code><\/pre>\n<\/li>\n<li>\u5b89\u88c5\u8bc4\u4f30\u652f\u6301\uff1a\n<pre><code>pip install raglite[<a href=\"https:\/\/www.kdjingpai.com\/ja\/ragas\/\">ragas<\/a>]\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u4f7f\u7528\u6307\u5357<\/h3>\n<ol>\n<li><strong>\u914d\u7f6e RAGLite<\/strong>\uff1a\n<ul>\n<li>\u914d\u7f6e PostgreSQL \u6216 SQLite \u6570\u636e\u5e93\u548c\u4efb\u610f\u652f\u6301\u7684\u8bed\u8a00\u6a21\u578b\uff1a\n<pre><code>from raglite import RAGLiteConfig\r\nmy_config = RAGLiteConfig(\r\ndb_url=\"postgresql:\/\/my_username:my_password@my_host:5432\/my_database\",\r\nllm=\"gpt-4o-mini\",\r\nembedder=\"text-embedding-3-large\"\r\n)\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u63d2\u5165\u6587\u6863<\/strong>\uff1a\n<ul>\n<li>\u63d2\u5165 PDF \u6587\u6863\u5e76\u8fdb\u884c\u8f6c\u6362\u548c\u5d4c\u5165\uff1a\n<pre><code>from pathlib import Path\r\nfrom raglite import insert_document\r\ninsert_document(Path(\"On the Measure of Intelligence.pdf\"), config=my_config)\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u68c0\u7d22\u548c\u751f\u6210<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528\u5411\u91cf\u68c0\u7d22\u3001\u5173\u952e\u8bcd\u68c0\u7d22\u6216\u6df7\u5408\u68c0\u7d22\u8fdb\u884c\u67e5\u8be2\uff1a\n<pre><code>from raglite import hybrid_search, keyword_search, vector_search\r\nprompt = \"How is intelligence measured?\"\r\nchunk_ids_hybrid, _ = hybrid_search(prompt, num_results=20, config=my_config)\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u91cd\u6392\u5e8f\u548c\u56de\u7b54\u95ee\u9898<\/strong>\uff1a\n<ul>\n<li>\u5bf9\u68c0\u7d22\u7ed3\u679c\u8fdb\u884c\u91cd\u6392\u5e8f\u5e76\u751f\u6210\u7b54\u6848\uff1a\n<pre><code>from raglite import rerank_chunks, <a href=\"https:\/\/www.kdjingpai.com\/ja\/rag\/\">rag<\/a>\r\nchunks_reranked = rerank_chunks(prompt, chunk_ids_hybrid, config=my_config)\r\nstream = rag(prompt, search=chunks_reranked, config=my_config)\r\nfor update in stream:\r\nprint(update, end=\"\")\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8bc4\u4f30\u68c0\u7d22\u548c\u751f\u6210<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 Ragas \u8fdb\u884c\u68c0\u7d22\u548c\u751f\u6210\u6027\u80fd\u8bc4\u4f30\uff1a\n<pre><code>from raglite import answer_evals, evaluate, insert_evals\r\ninsert_evals(num_evals=100, config=my_config)\r\nanswered_evals_df = answer_evals(num_evals=10, config=my_config)\r\nevaluation_df = evaluate(answered_evals_df, config=my_config)\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u90e8\u7f72 ChatGPT \u7c7b\u524d\u7aef<\/strong>\uff1a\n<ul>\n<li>\u90e8\u7f72\u53ef\u5b9a\u5236\u7684 ChatGPT \u7c7b\u524d\u7aef\uff1a\n<pre><code>raglite chainlit --db_url sqlite:\/\/\/raglite.sqlite --llm llama-cpp-python\/bartowski\/Llama-3.2-3B-Instruct-GGUF\/*Q4_K_M.gguf@4096 --embedder llama-cpp-python\/lm-kit\/bge-m3-gguf\/*F16.gguf\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>RAGLite \u662f\u4e00\u4e2a\u7528\u4e8e\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u7684 Python \u5de5\u5177\u5305\uff0c\u652f\u6301 PostgreSQL \u6216 SQLite \u6570\u636e\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879\uff0c\u5141\u8bb8\u7528\u6237\u9009\u62e9\u4e0d\u540c\u7684\u8bed\u8a00\u6a21\u578b\u548c\u91cd\u6392\u5e8f\u5668\u3002RAGLite \u4ee5\u5176\u8f7b\u91cf\u7ea7\u548c\u9ad8\u6548\u7684\u7279\u6027\u8457\u79f0\uff0c\u9002\u7528\u4e8e&#8230;<\/p>\n","protected":false},"author":1,"featured_media":61323,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[425,20,459],"tags":[230,243],"class_list":["post-14542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-professional","category-tool","category-rag-project","tag-aikaiyuanxiangmu","tag-aizhishikuyukefu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/14542","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=14542"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/14542\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/61323"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=14542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=14542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=14542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}