{"id":51255,"date":"2025-08-10T19:49:32","date_gmt":"2025-08-10T11:49:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/51255.html"},"modified":"2025-08-10T19:49:32","modified_gmt":"2025-08-10T11:49:32","slug":"rag-%e6%af%8f%e6%97%a5%e4%b8%80%e6%8a%80%ef%bc%88%e5%8d%81%e5%85%ad%ef%bc%89%ef%bc%9a%e7%bb%99%e4%bd%a0%e7%9a%84rag%e7%a9%bf%e4%b8%8a%e5%a4%96%e5%a5%97-%e7%94%a8grad","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/51255.html","title":{"rendered":"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528"},"content":{"rendered":"<h5>\u524d\u60c5\u56de\u987e<\/h5>\n<p>\u7ecf\u8fc7\u524d\u9762\u5341\u4e94\u5929\u7684\u93d6\u6218&#xff0c;\u6211\u4eec\u5df2\u7ecf\u62e5\u6709\u4e86\u4e00\u4e2a\u6781\u5176\u5f3a\u5927\u7684RAG\u201c\u5927\u8111\u201d\u3002\u65e0\u8bba\u662f\u5e95\u5c42\u539f\u7406\u3001\u9ad8\u7ea7\u7b56\u7565&#xff0c;\u8fd8\u662f\u9876\u7ea7\u7684\u5f00\u53d1\u6846\u67b6&#xff08;LangChain\/LlamaIndex&#xff09;&#xff0c;\u6211\u4eec\u90fd\u5df2\u4e86\u7136\u4e8e\u80f8\u3002\u6211\u4eec\u7684RAG\u5f15\u64ce\u73b0\u5728\u6b63\u5728\u6211\u4eec\u7684\u7535\u8111\u91cc&#xff0c;\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u4ee3\u7801\u7f16\u8f91\u5668&#xff0c;\u9759\u9759\u5730\u5c55\u793a\u7740\u5b83\u7684\u667a\u6167\u3002<\/p>\n<p>\u4f46\u4e00\u4e2a\u95ee\u9898\u968f\u4e4b\u800c\u6765&#xff1a;\u6211\u4eec\u5982\u4f55\u5411\u4e0d\u61c2\u4ee3\u7801\u7684\u540c\u4e8b\u3001\u8001\u677f\u6216\u5ba2\u6237\u5c55\u793a\u6211\u4eec\u7684\u6210\u679c&#xff1f; \u603b\u4e0d\u80fd\u8ba9\u4ed6\u4eec\u4e5f\u53bb\u8fd0\u884cPython\u811a\u672c\u5427&#xff1f;<\/p>\n<p>\u4e00\u4e2a\u5f3a\u5927\u7684\u201c\u5927\u8111\u201d&#xff0c;\u4e5f\u9700\u8981\u4e00\u4e2a\u53cb\u597d\u7684\u201c\u9762\u5b54\u201d\u3002\u4eca\u5929&#xff0c;\u6211\u4eec\u5c31\u6765\u5b66\u4e60\u5982\u4f55\u7528\u4e00\u4e2a\u6781\u5176\u7b80\u5355\u7684\u5de5\u5177&#xff0c;\u5728\u51e0\u5206\u949f\u5185\u4e3a\u6211\u4eec\u7684RAG\u7cfb\u7edf\u6784\u5efa\u4e00\u4e2a\u6f02\u4eae\u3001\u53ef\u4ea4\u4e92\u7684Web\u754c\u9762\u3002\u8fd9\u4e2a\u5de5\u5177&#xff0c;\u5c31\u662fGradio\u3002<\/p>\n<h5>Gradio\u662f\u4ec0\u4e48&#xff1f;<\/h5>\n<p>Gradio\u662f\u4e00\u4e2a\u5f00\u6e90\u7684Python\u5e93&#xff0c;\u5b83\u53ef\u4ee5\u8ba9\u4f60\u4e3a\u4f60\u7684\u673a\u5668\u5b66\u4e60\u6a21\u578b\u6216\u4efb\u610f\u7684Python\u51fd\u6570&#xff0c;\u5feb\u901f\u521b\u5efa\u7b80\u5355\u3001\u7f8e\u89c2\u3001\u53ef\u5b9a\u5236\u7684Web\u7528\u6237\u754c\u9762&#xff08;UI&#xff09;\u3002<\/p>\n<p>\u5728AI\/ML\u793e\u533a&#xff0c;Gradio\u5df2\u7ecf\u6210\u4e3a\u4e86\u5feb\u901f\u521b\u5efa\u548c\u5206\u4eab\u6a21\u578bDemo\u7684\u9996\u9009\u5de5\u5177&#xff0c;\u539f\u56e0\u65e0\u4ed6&#xff0c;\u5c31\u662f\u7b80\u5355&#xff01;\u4f60\u4e0d\u9700\u8981\u61c2\u4efb\u4f55\u524d\u7aef\u77e5\u8bc6&#xff08;HTML\/CSS\/JavaScript&#xff09;&#xff0c;\u53ea\u9700\u5199\u51e0\u884cPython\u4ee3\u7801&#xff0c;\u5c31\u80fd\u62e5\u6709\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684Web\u5e94\u7528\u3002<\/p>\n<h5>\u4e0a\u624b\u5b9e\u6218&#xff1a;\u201cChat with Your Doc\u201d Web App<\/h5>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f&#xff1a;\u5c06\u4e4b\u524d\u7528LlamaIndex\u6784\u5efa\u7684\u201c\u6587\u6863\u95ee\u7b54\u201dRAG\u5f15\u64ce&#xff0c;\u5305\u88c5\u6210\u4e00\u4e2a\u804a\u5929\u673a\u5668\u4eba\u754c\u9762\u3002<\/p>\n<p>\u9996\u5148&#xff0c;\u786e\u4fdd\u4f60\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u5e93&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> gradio llama-index llama-index-llms-openai<\/p>\n<h6>1. \u51c6\u5907\u4e00\u4e2a\u53ef\u590d\u73b0\u7684RAG\u540e\u7aef<\/h6>\n<p>\u4e3a\u4e86\u8ba9\u672c\u7bc7\u6587\u7ae0\u7684\u4ee3\u7801\u5b8c\u5168\u72ec\u7acb\u53ef\u8fd0\u884c&#xff0c;\u6211\u4eec\u5c06\u518d\u6b21\u4f7f\u7528LlamaIndex\u5feb\u901f\u6784\u5efa\u4e00\u4e2aRAG\u67e5\u8be2\u5f15\u64ce\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> os<br \/>\n<span class=\"token keyword\">from<\/span> llama_index<span class=\"token punctuation\">.<\/span>core <span class=\"token keyword\">import<\/span> VectorStoreIndex<span class=\"token punctuation\">,<\/span> SimpleDirectoryReader<br \/>\n<span class=\"token keyword\">import<\/span> gradio <span class=\"token keyword\">as<\/span> gr<\/p>\n<p><span class=\"token comment\"># &#8212; Step 1: \u51c6\u5907RAG\u540e\u7aef &#8212;<\/span><\/p>\n<p><span class=\"token comment\"># \u8bbe\u7f6e\u4f60\u7684OpenAI API Key<\/span><br \/>\n<span class=\"token comment\"># os.environ[&#034;OPENAI_API_KEY&#034;] &#061; &#034;sk-&#8230;&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#034;data&#034; \u7684\u6587\u4ef6\u5939<\/span><br \/>\n<span class=\"token comment\"># \u5e76\u653e\u5165\u4e00\u4e2a\u540d\u4e3a &#034;my_story.txt&#034; \u7684\u6587\u672c\u6587\u4ef6<\/span><br \/>\n<span class=\"token comment\"># \u4e3a\u4e86\u65b9\u4fbf\u6f14\u793a&#xff0c;\u6211\u4eec\u7528\u4ee3\u7801\u6765\u521b\u5efa\u5b83<\/span><br \/>\nos<span class=\"token punctuation\">.<\/span>makedirs<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;data&#034;<\/span><span class=\"token punctuation\">,<\/span> exist_ok<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">with<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;data\/my_story.txt&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;w&#034;<\/span><span class=\"token punctuation\">,<\/span> encoding<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;utf-8&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> f<span class=\"token punctuation\">:<\/span><br \/>\n    f<span class=\"token punctuation\">.<\/span>write<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u4ece\u524d\u6709\u5ea7\u5c71&#xff0c;\u5c71\u91cc\u6709\u5ea7\u5e99&#xff0c;\u5e99\u91cc\u6709\u4e2a\u8001\u548c\u5c1a\u5728\u7ed9\u5c0f\u548c\u5c1a\u8bb2\u6545\u4e8b\u3002\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    f<span class=\"token punctuation\">.<\/span>write<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8fd9\u4e2a\u6545\u4e8b\u662f\u5173\u4e8e\u4e00\u4e2a\u540d\u4e3aRAG\u7684\u82f1\u96c4&#xff0c;\u4ed6\u80fd\u591f\u9605\u8bfb\u65e0\u6570\u4e66\u7c4d&#xff0c;\u5e76\u56de\u7b54\u6240\u6709\u95ee\u9898\u3002\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    f<span class=\"token punctuation\">.<\/span>write<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;RAG\u7684\u6838\u5fc3\u6b66\u5668\u662f\u68c0\u7d22\u548c\u751f\u6210&#xff0c;\u8fd9\u8ba9\u4ed6\u53d8\u5f97\u65e0\u6bd4\u5f3a\u5927\u3002&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u6570\u636e\u5e76\u6784\u5efa\u7d22\u5f15\u548c\u67e5\u8be2\u5f15\u64ce<\/span><br \/>\n<span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    documents <span class=\"token operator\">&#061;<\/span> SimpleDirectoryReader<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.\/data&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>load_data<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    index <span class=\"token operator\">&#061;<\/span> VectorStoreIndex<span class=\"token punctuation\">.<\/span>from_documents<span class=\"token punctuation\">(<\/span>documents<span class=\"token punctuation\">)<\/span><br \/>\n    query_engine <span class=\"token operator\">&#061;<\/span> index<span class=\"token punctuation\">.<\/span>as_query_engine<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;RAG\u540e\u7aef\u51c6\u5907\u5c31\u7eea&#xff01;&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u540e\u7aef\u51c6\u5907\u5931\u8d25&#xff0c;\u8bf7\u68c0\u67e5API Key\u6216\u6587\u4ef6\u8def\u5f84: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u5982\u679c\u540e\u7aef\u5931\u8d25&#xff0c;\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u5f15\u64ce\u4ee5\u4fdd\u8bc1UI\u80fd\u8fd0\u884c<\/span><br \/>\n    <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">DummyQueryEngine<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">def<\/span> <span class=\"token function\">query<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> _<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\u540e\u7aef\u521d\u59cb\u5316\u5931\u8d25&#xff0c;\u8bf7\u68c0\u67e5\u540e\u53f0\u65e5\u5fd7\u3002&#034;<\/span><br \/>\n    query_engine <span class=\"token operator\">&#061;<\/span> DummyQueryEngine<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8bf7\u52a1\u5fc5\u786e\u4fdd\u4f60\u7684API Key\u5df2\u6b63\u786e\u8bbe\u7f6e&#xff0c;\u5426\u5219\u540e\u7aef\u4f1a\u521d\u59cb\u5316\u5931\u8d25\u3002<\/p>\n<h6>2. \u5b9a\u4e49Gradio\u8981\u8c03\u7528\u7684\u51fd\u6570<\/h6>\n<p>Gradio\u7684\u6838\u5fc3\u662f\u5c06\u4e00\u4e2a\u51fd\u6570\u6620\u5c04\u5230\u4e00\u4e2aUI\u754c\u9762\u3002\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u51fd\u6570&#xff0c;\u5b83\u63a5\u6536\u7528\u6237\u7684\u8f93\u5165&#xff0c;\u7136\u540e\u8c03\u7528\u6211\u4eec\u7684RAG\u5f15\u64ce\u8fd4\u56de\u7b54\u6848\u3002\u5bf9\u4e8e\u804a\u5929\u754c\u9762&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u901a\u5e38\u63a5\u6536 message \u548c chat_history \u4e24\u4e2a\u53c2\u6570\u3002<\/p>\n<p><span class=\"token comment\"># &#8212; Step 2: \u5b9a\u4e49\u804a\u5929\u51fd\u6570 &#8212;<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">respond<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">,<\/span> chat_history<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n    \u8fd9\u4e2a\u51fd\u6570\u4f1a\u88abGradio\u7684ChatInterface\u8c03\u7528\u3002<br \/>\n    :param message: \u7528\u6237\u5728\u804a\u5929\u6846\u4e2d\u8f93\u5165\u7684\u5185\u5bb9\u3002<br \/>\n    :param chat_history: \u4e00\u4e2a\u5217\u8868&#xff0c;\u5305\u542b\u4e86\u4e4b\u524d\u7684\u5bf9\u8bdd\u5386\u53f2\u3002<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u8c03\u7528\u6211\u4eec\u4e4b\u524d\u521b\u5efa\u7684RAG\u67e5\u8be2\u5f15\u64ce<\/span><br \/>\n    response <span class=\"token operator\">&#061;<\/span> query_engine<span class=\"token punctuation\">.<\/span>query<span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># Gradio\u7684ChatInterface\u671f\u671b\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><\/p>\n<h6>3. \u521b\u5efa\u5e76\u542f\u52a8Gradio\u804a\u5929\u754c\u9762<\/h6>\n<p>\u8fd9\u662f\u6700\u7b80\u5355&#xff0c;\u4e5f\u662f\u6700\u6fc0\u52a8\u4eba\u5fc3\u7684\u4e00\u6b65\u3002\u6211\u4eec\u53ea\u9700\u8981\u4e00\u884c\u4ee3\u7801&#xff0c;\u5c31\u80fd\u521b\u5efa\u5e76\u542f\u52a8\u6211\u4eec\u7684Web\u5e94\u7528\u3002<\/p>\n<p><span class=\"token comment\"># &#8212; Step 3: \u521b\u5efa\u5e76\u542f\u52a8Gradio\u754c\u9762 &#8212;<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528gr.ChatInterface&#xff0c;\u5b83\u662f\u4e00\u4e2a\u4e3a\u804a\u5929\u673a\u5668\u4eba\u4f18\u5316\u7684\u73b0\u6210\u7ec4\u4ef6<\/span><br \/>\n<span class=\"token comment\"># \u5b83\u4f1a\u81ea\u52a8\u5904\u7406\u8f93\u5165\u6846\u3001\u8f93\u51fa\u6846\u3001\u5bf9\u8bdd\u5386\u53f2\u7b49\u6240\u6709\u4e8b\u60c5<\/span><br \/>\ngr<span class=\"token punctuation\">.<\/span>ChatInterface<span class=\"token punctuation\">(<\/span><br \/>\n    fn<span class=\"token operator\">&#061;<\/span>respond<span class=\"token punctuation\">,<\/span>  <span class=\"token comment\"># \u5c06\u6211\u4eec\u7684\u804a\u5929\u51fd\u6570\u4f20\u7ed9\u5b83<\/span><br \/>\n    title<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;RAG \u6bcf\u65e5\u4e00\u6280&#xff1a;\u6587\u6863\u95ee\u7b54\u673a\u5668\u4eba&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    chatbot<span class=\"token operator\">&#061;<\/span>gr<span class=\"token punctuation\">.<\/span>Chatbot<span class=\"token punctuation\">(<\/span>height<span class=\"token operator\">&#061;<\/span><span class=\"token number\">500<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    textbox<span class=\"token operator\">&#061;<\/span>gr<span class=\"token punctuation\">.<\/span>Textbox<span class=\"token punctuation\">(<\/span>placeholder<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u8bf7\u8f93\u5165\u4f60\u5173\u4e8e\u6587\u6863\u7684\u95ee\u9898&#8230;&#034;<\/span><span class=\"token punctuation\">,<\/span> container<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">False<\/span><span class=\"token punctuation\">,<\/span> scale<span class=\"token operator\">&#061;<\/span><span class=\"token number\">7<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    theme<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;soft&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    examples<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;RAG\u662f\u4ec0\u4e48&#xff1f;&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;RAG\u7684\u6838\u5fc3\u6b66\u5668\u662f\u4ec0\u4e48&#xff1f;&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u8001\u548c\u5c1a\u5728\u5e72\u4ec0\u4e48&#xff1f;&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    cache_examples<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">False<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    retry_btn<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">None<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    undo_btn<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">None<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    clear_btn<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\u6e05\u7a7a\u5bf9\u8bdd&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>launch<span class=\"token punctuation\">(<\/span>share<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># launch()\u4f1a\u542f\u52a8\u4e00\u4e2a\u672c\u5730Web\u670d\u52a1\u5668<\/span><\/p>\n<p>\u4ee3\u7801\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>gr.ChatInterface(fn&#061;respond, &#8230;)&#xff1a;\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u804a\u5929\u754c\u9762\u5b9e\u4f8b&#xff0c;\u5e76\u5c06\u6211\u4eec\u7684\u6838\u5fc3\u903b\u8f91\u51fd\u6570 respond \u7ed1\u5b9a\u7ed9\u4e86\u5b83\u3002<\/li>\n<li>title, theme, examples \u7b49\u90fd\u662f\u7528\u4e8e\u7f8e\u5316\u548c\u589e\u5f3a\u7528\u6237\u4f53\u9a8c\u7684\u53c2\u6570\u3002<\/li>\n<li>.launch(share&#061;True)&#xff1a;\u542f\u52a8\u5e94\u7528&#xff01;Gradio\u4f1a\u5728\u4f60\u7684\u672c\u5730\u542f\u52a8\u4e00\u4e2aWeb\u670d\u52a1&#xff08;\u901a\u5e38\u662f http:\/\/127.0.0.1:7860&#xff09;&#xff0c;\u5e76\u751f\u6210\u4e00\u4e2a\u53ef\u5206\u4eab\u7684\u516c\u7f51\u94fe\u63a5&#xff08;\u6709\u6548\u671f72\u5c0f\u65f6&#xff09;&#xff0c;\u8ba9\u4f60\u7684\u670b\u53cb\u4e5f\u80fd\u8fdc\u7a0b\u8bbf\u95ee\u4f60\u7684\u5e94\u7528&#xff01;<\/li>\n<\/ul>\n<p>\u8fd0\u884c\u8fd9\u6bb5\u5b8c\u6574\u7684Python\u811a\u672c&#xff0c;\u7136\u540e\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\u5b83\u7ed9\u51fa\u7684\u94fe\u63a5&#xff0c;\u4f60\u5c06\u770b\u5230\u4e00\u4e2a\u6f02\u4eae\u7684\u804a\u5929\u673a\u5668\u4eba\u754c\u9762&#xff01;<\/p>\n<h5>\u603b\u7ed3\u4e0e\u9884\u544a<\/h5>\n<p>\u4eca\u65e5\u5c0f\u7ed3&#xff1a;<\/p>\n<ul>\n<li>RAG\u7cfb\u7edf\u9700\u8981\u4e00\u4e2a\u7528\u6237\u754c\u9762\u624d\u80fd\u65b9\u4fbf\u5730\u8fdb\u884c\u6f14\u793a\u548c\u4ea4\u4e92\u3002<\/li>\n<li>Gradio \u662f\u4e00\u4e2a\u6781\u5176\u7b80\u5355\u7684Python\u5e93&#xff0c;\u80fd\u8ba9\u4f60\u7528\u51e0\u884c\u4ee3\u7801\u5c31\u4e3aAI\u5e94\u7528\u6784\u5efa\u51fa\u6f02\u4eae\u7684Web UI\u3002<\/li>\n<li>gr.ChatInterface \u662fGradio\u4e2d\u4e13\u95e8\u7528\u4e8e\u6784\u5efa\u804a\u5929\u673a\u5668\u4eba\u7684\u9ad8\u7ea7\u7ec4\u4ef6&#xff0c;\u80fd\u81ea\u52a8\u5904\u7406\u5bf9\u8bdd\u5386\u53f2\u7b49\u7ec6\u8282\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u7684\u7cfb\u5217\u5b66\u4e60\u4e4b\u65c5&#xff0c;\u539f\u8ba1\u5212\u5728\u8fd9\u91cc\u753b\u4e0a\u4e00\u4e2a\u53e5\u53f7\u3002\u4f46\u770b\u5230\u5927\u5bb6\u5982\u6b64\u9ad8\u6da8\u7684\u70ed\u60c5\u548c\u6301\u7eed\u7684\u5173\u6ce8&#xff0c;\u6211\u4eec\u51b3\u5b9a&#xff1a;\u63a2\u7d22\u6c38\u4e0d\u505c\u6b62&#xff0c;\u5b66\u4e60\u7ee7\u7eed\u6df1\u5165&#xff01;<\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u5b8c\u5168\u638c\u63e1\u4e86\u5982\u4f55\u4e0e\u975e\u7ed3\u6784\u5316\u7684\u6587\u672c\u8fdb\u884c\u5bf9\u8bdd\u3002\u4f46\u73b0\u5b9e\u4e16\u754c\u4e2d&#xff0c;\u8fd8\u6709\u5927\u91cf\u7684\u4fe1\u606f\u5b58\u50a8\u5728\u7ed3\u6784\u5316\u7684\u6570\u636e\u4e2d&#xff0c;\u6bd4\u5982\u6570\u636e\u5e93\u8868\u683c\u3001Excel\u3001CSV\u6587\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7684\u8001\u677f\u7ed9\u4f60\u4e00\u4efd\u9500\u552e\u62a5\u8868&#xff0c;\u7136\u540e\u95ee\u4f60&#xff1a;\u201c\u4e0a\u4e2a\u5b63\u5ea6\u54ea\u4e2a\u4ea7\u54c1\u7684\u9500\u552e\u989d\u6700\u9ad8&#xff1f;\u201d \u6211\u4eec\u73b0\u5728\u7684RAG\u7cfb\u7edf\u80fd\u56de\u7b54\u5417&#xff1f;\u663e\u7136\u4e0d\u80fd\u3002<\/p>\n<p>\u660e\u5929\u9884\u544a&#xff1a;RAG \u6bcf\u65e5\u4e00\u6280&#xff08;\u5341\u4e03&#xff09;&#xff1a;\u4e0d\u6b62\u804a\u6587\u672c&#xff0c;\u5982\u4f55\u8ba9RAG\u201c\u770b\u61c2\u201d\u8868\u683c\u6570\u636e&#xff1f;<\/p>\n<p>\u660e\u5929&#xff0c;\u6211\u4eec\u5c06\u6311\u6218\u4e00\u4e2a\u5168\u65b0\u7684\u3001\u6781\u5177\u5546\u4e1a\u4ef7\u503c\u7684\u9886\u57df&#xff1a;\u7ed3\u6784\u5316\u6570\u636e\u95ee\u7b54\u3002\u6211\u4eec\u5c06\u63a2\u7d22\u5982\u4f55\u8ba9RAG\u7cfb\u7edf\u7406\u89e3\u8868\u683c\u6570\u636e&#xff0c;\u5e76\u5c06\u7528\u6237\u7684\u81ea\u7136\u8bed\u8a00\u95ee\u9898&#xff0c;\u667a\u80fd\u5730\u8f6c\u6362\u6210\u53ef\u4ee5\u6267\u884c\u7684\u67e5\u8be2\u4ee3\u7801&#xff08;\u5982SQL&#xff09;&#xff0c;\u6700\u7ec8\u4ece\u8868\u683c\u4e2d\u627e\u5230\u7cbe\u786e\u7b54\u6848&#xff01;\u8fd9\u4f1a\u662f\u4e00\u4e2a\u6fc0\u52a8\u4eba\u5fc3\u7684\u65b0\u8d77\u70b9&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb131\u6b21\u3002RAG\u5f15\u64ce\u53ea\u80fd\u5728\u547d\u4ee4\u884c\u91cc\u8fd0\u884c\uff1f\u592a\u4e0d\u9177\u4e86\uff01\u672c\u6587\u6559\u4f60\u4f7f\u7528\u8d85\u7b80\u5355\u7684UI\u5e93Gradio\uff0c\u53ea\u9700\u51e0\u884cPython\u4ee3\u7801\uff0c\u5c31\u80fd\u4e3a\u4f60\u7684RAG\u5e94\u7528\u7a7f\u4e0a\u4e00\u4ef6\u6f02\u4eae\u7684\u201c\u5916\u5957\u201d\uff0c\u5149\u901f\u6784\u5efa\u51fa\u4e00\u4e2a\u53ef\u4ea4\u4e92\u3001\u53ef\u5206\u4eab\u7684\u201c\u6587\u6863\u95ee\u7b54\u201dWeb\u804a\u5929\u673a\u5668\u4eba\uff01<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5061,50,87,292,207,427,224,51],"topic":[],"class_list":["post-51255","post","type-post","status-publish","format-standard","hentry","category-server","tag-rag-","tag-50","tag-87","tag-292","tag-207","tag-427","tag-224","tag-51"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/51255.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb131\u6b21\u3002RAG\u5f15\u64ce\u53ea\u80fd\u5728\u547d\u4ee4\u884c\u91cc\u8fd0\u884c\uff1f\u592a\u4e0d\u9177\u4e86\uff01\u672c\u6587\u6559\u4f60\u4f7f\u7528\u8d85\u7b80\u5355\u7684UI\u5e93Gradio\uff0c\u53ea\u9700\u51e0\u884cPython\u4ee3\u7801\uff0c\u5c31\u80fd\u4e3a\u4f60\u7684RAG\u5e94\u7528\u7a7f\u4e0a\u4e00\u4ef6\u6f02\u4eae\u7684\u201c\u5916\u5957\u201d\uff0c\u5149\u901f\u6784\u5efa\u51fa\u4e00\u4e2a\u53ef\u4ea4\u4e92\u3001\u53ef\u5206\u4eab\u7684\u201c\u6587\u6863\u95ee\u7b54\u201dWeb\u804a\u5929\u673a\u5668\u4eba\uff01\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/51255.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-10T11:49:32+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51255.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/51255.html\",\"name\":\"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-10T11:49:32+00:00\",\"dateModified\":\"2025-08-10T11:49:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/51255.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/51255.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/51255.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/51255.html","og_locale":"zh_CN","og_type":"article","og_title":"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb131\u6b21\u3002RAG\u5f15\u64ce\u53ea\u80fd\u5728\u547d\u4ee4\u884c\u91cc\u8fd0\u884c\uff1f\u592a\u4e0d\u9177\u4e86\uff01\u672c\u6587\u6559\u4f60\u4f7f\u7528\u8d85\u7b80\u5355\u7684UI\u5e93Gradio\uff0c\u53ea\u9700\u51e0\u884cPython\u4ee3\u7801\uff0c\u5c31\u80fd\u4e3a\u4f60\u7684RAG\u5e94\u7528\u7a7f\u4e0a\u4e00\u4ef6\u6f02\u4eae\u7684\u201c\u5916\u5957\u201d\uff0c\u5149\u901f\u6784\u5efa\u51fa\u4e00\u4e2a\u53ef\u4ea4\u4e92\u3001\u53ef\u5206\u4eab\u7684\u201c\u6587\u6863\u95ee\u7b54\u201dWeb\u804a\u5929\u673a\u5668\u4eba\uff01","og_url":"https:\/\/www.wsisp.com\/helps\/51255.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-10T11:49:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/51255.html","url":"https:\/\/www.wsisp.com\/helps\/51255.html","name":"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-10T11:49:32+00:00","dateModified":"2025-08-10T11:49:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/51255.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/51255.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/51255.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"RAG \u6bcf\u65e5\u4e00\u6280\uff08\u5341\u516d\uff09\uff1a\u7ed9\u4f60\u7684RAG\u7a7f\u4e0a\u201c\u5916\u5957\u201d\u2014\u2014\u7528Gradio\u5149\u901f\u6784\u5efa\u4ea4\u4e92\u5f0fWeb\u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=51255"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/51255\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=51255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=51255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=51255"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=51255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}