{"id":78491,"date":"2026-02-27T18:05:56","date_gmt":"2026-02-27T10:05:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78491.html"},"modified":"2026-02-27T18:05:56","modified_gmt":"2026-02-27T10:05:56","slug":"elasticsearch-9-x-%e6%9c%ac%e5%9c%b0rag%e4%b8%aa%e4%ba%ba%e7%9f%a5%e8%af%86%e5%ba%93%e5%ae%9e%e6%93%8d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78491.html","title":{"rendered":"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd"},"content":{"rendered":"<h3>\u4e00\u3001\u6982\u8ff0<\/h3>\n<h4>\u6838\u5fc3\u539f\u7406&#xff1a;3\u4e2a\u89d2\u8272\u7ec4\u6210\u4f60\u7684\u79bb\u7ebf\u79c1\u4eba\u77e5\u8bc6\u5e93<\/h4>\n<p>\u6211\u4eec\u8981\u642d\u7684\u7cfb\u7edf&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u5b8c\u5168\u88c5\u5728\u4f60\u7535\u8111\u91cc\u3001\u4e0d\u8054\u7f51\u7684\u79c1\u4eba\u667a\u5e93&#xff0c;3\u4e2a\u6838\u5fc3\u89d2\u8272\u5206\u5de5\u660e\u786e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u9700\u8981\u8fde\u5916\u7f51&#xff1a;<\/p>\n<li>\n<p>\u300c\u56fe\u4e66\u7ba1\u7406\u5458\u300dElasticsearch 9.x&#xff1a;\u4f60\u7684\u79c1\u4eba\u6587\u6863\u56fe\u4e66\u9986<\/p>\n<ul>\n<li>\n<p>\u5b58\u50a8\u6240\u6709\u6587\u6863&#xff08;\u4f1a\u8bae\u7eaa\u8981\u3001\u62a5\u544a\u3001\u5236\u5ea6\u6587\u4ef6\u7b49&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u81ea\u52a8\u7ed9\u6bcf\u6bb5\u8bdd\u751f\u6210\u300c\u8bed\u4e49\u6807\u7b7e\u300d&#xff08;\u5411\u91cf&#xff09;&#xff0c;\u4e0d\u662f\u7b80\u5355\u7684\u5173\u952e\u8bcd\u5339\u914d&#xff0c;\u800c\u662f\u80fd\u8bc6\u522b\u201c\u8fd9\u53e5\u8bdd\u662f\u4ec0\u4e48\u610f\u601d\u201d\u7684\u8bed\u4e49\u7f16\u7801<\/p>\n<\/li>\n<li>\n<p>\u4f60\u95ee\u95ee\u9898\u65f6&#xff0c;10\u6beb\u79d2\u5185\u5c31\u80fd\u627e\u5230\u6240\u6709\u548c\u95ee\u9898\u76f8\u5173\u7684\u6587\u6863\u6bb5\u843d&#xff0c;\u6bd4\u4eba\u5de5\u7ffb\u627e\u6548\u7387\u63d0\u5347\u4e0a\u5343\u500d<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u300c\u6807\u7b7e\u751f\u6210\u5668\u300dmultilingual-e5-small \u5d4c\u5165\u6a21\u578b&#xff1a;\u7ed9\u6587\u6863\u548c\u95ee\u9898\u6253\u8bed\u4e49\u6807\u7b7e<\/p>\n<ul>\n<li>\n<p>\u628a\u4eba\u7c7b\u7684\u81ea\u7136\u8bed\u8a00&#xff0c;\u8f6c\u6362\u6210\u8ba1\u7b97\u673a\u80fd\u8bc6\u522b\u7684\u300c\u8bed\u4e49\u7f16\u7801\u300d\u3002\u6bd4\u5982\u201cAPI\u54cd\u5e94\u6162\u201d\u548c\u201c\u63a5\u53e3\u8d85\u65f6\u201d&#xff0c;\u4f1a\u88ab\u8f6c\u6362\u6210\u76f8\u8fd1\u7684\u7f16\u7801&#xff0c;\u5b9e\u73b0\u8bed\u4e49\u7ea7\u68c0\u7d22&#xff0c;\u800c\u975e\u5fc5\u987b\u5339\u914d\u5b8c\u5168\u4e00\u81f4\u7684\u5173\u952e\u8bcd<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u5168\u5185\u7f6e\u5728ES\u4e2d&#xff0c;\u79bb\u7ebf\u5373\u53ef\u8fd0\u884c&#xff0c;\u65e0\u9700\u989d\u5916\u90e8\u7f72\u670d\u52a1<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u300c\u6587\u6848\u52a9\u7406\u300ddolphin3.0-qwen2.5-0.5b \u5927\u6a21\u578b&#xff1a;\u6574\u7406\u7b54\u6848\u7684\u79c1\u4eba\u52a9\u7406<\/p>\n<ul>\n<li>\n<p>\u57fa\u4e8eES\u68c0\u7d22\u5230\u7684\u76f8\u5173\u6587\u6863&#xff0c;\u7528\u901a\u987a\u7684\u903b\u8f91\u603b\u7ed3\u6210\u7cbe\u51c6\u7b54\u6848&#xff0c;\u540c\u65f6\u6807\u6ce8\u6bcf\u53e5\u8bdd\u7684\u6765\u6e90\u6587\u4ef6&#xff0c;\u675c\u7edd\u51ed\u7a7a\u7f16\u9020<\/p>\n<\/li>\n<li>\n<p>\u4ec50.5B\u53c2\u6570\u3001200M\u5927\u5c0f&#xff0c;\u65e0\u72ec\u7acb\u663e\u5361\u4e5f\u80fd\u6d41\u7545\u8fd0\u884c&#xff0c;\u5b8c\u5168\u79bb\u7ebf\u8fd0\u884c&#xff0c;\u4e0d\u4f1a\u5c06\u4efb\u4f55\u6587\u6863\u6570\u636e\u5916\u4f20<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h4>\u5168\u6d41\u7a0b\u95ed\u73af<\/h4>\n<li>\n<p>\u628a\u6587\u6863\u653e\u5230\u79bb\u7ebf\u7535\u8111\u7684\u6307\u5b9a\u6587\u4ef6\u5939<\/p>\n<\/li>\n<li>\n<p>ES\u81ea\u52a8\u5b58\u50a8\u6587\u6863&#xff0c;\u751f\u6210\u8bed\u4e49\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>\u8f93\u5165\u95ee\u9898&#xff0c;ES\u5feb\u901f\u68c0\u7d22\u6240\u6709\u76f8\u5173\u6587\u6863\u6bb5\u843d<\/p>\n<\/li>\n<li>\n<p>\u628a\u68c0\u7d22\u5230\u7684\u5185\u5bb9\u53d1\u9001\u7ed9\u672c\u5730\u5927\u6a21\u578b&#xff0c;\u6574\u7406\u6210\u89c4\u8303\u7b54\u6848<\/p>\n<\/li>\n<li>\n<p>\u8f93\u51fa\u5e26\u5f15\u6587\u7684\u7cbe\u51c6\u7ed3\u679c&#xff0c;\u5168\u7a0b\u65e0\u4efb\u4f55\u6570\u636e\u79bb\u5f00\u4f60\u7684\u8bbe\u5907<\/p>\n<\/li>\n<hr \/>\n<h3>\u4e8c\u3001\u7b2c\u4e00\u6b65&#xff1a;\u73af\u5883\u51c6\u5907<\/h3>\n<p>\u5173\u952e\u63d0\u9192&#xff1a;\u7269\u7406\u9694\u79bb\u73af\u5883\u65e0\u5916\u7f51&#xff0c;\u5fc5\u987b\u5148\u5728\u6709\u5916\u7f51\u7684\u8bbe\u5907\u4e0a&#xff0c;\u628a\u6240\u6709\u5b89\u88c5\u5305\u3001\u955c\u50cf\u3001\u6a21\u578b\u3001\u4ee3\u7801\u5168\u90e8\u4e0b\u8f7d\u5b8c\u6210&#xff0c;\u518d\u901a\u8fc7U\u76d8\/\u5408\u89c4\u4ecb\u8d28\u62f7\u8d1d\u5230\u79bb\u7ebf\u73af\u5883&#xff0c;\u7f3a\u4e00\u4e0d\u53ef&#xff01;<\/p>\n<h4>\u3010\u5fc5\u4e0b\u7269\u6599\u6e05\u5355\u3011&#xff08;\u56fa\u5b9a\u7248\u672c&#xff0c;\u907f\u514d\u517c\u5bb9\u6027\u95ee\u9898&#xff0c;\u5168\u4e3a\u5b98\u65b9\u6b63\u7248\u5730\u5740&#xff09;<\/h4>\n<table>\n<tr>\u7269\u6599\u540d\u79f0\u7248\u672c\u8981\u6c42\u5b98\u65b9\u4e0b\u8f7d\/\u83b7\u53d6\u65b9\u5f0f\u6838\u5fc3\u4f5c\u7528\u79bb\u7ebf\u73af\u5883\u5b58\u653e\u8def\u5f84\u5efa\u8bae<\/tr>\n<tbody>\n<tr>\n<td>Docker \u79bb\u7ebf\u5b89\u88c5\u5305<\/td>\n<td>20.10&#043; \u7a33\u5b9a\u7248<\/td>\n<td>Linux\u5b98\u65b9\u4e0b\u8f7d\u9875\u3001Windows Desktop\u79bb\u7ebf\u5b89\u88c5\u5305<\/td>\n<td>\u8fd0\u884cES\u548cLocalAI\u7684\u5bb9\u5668\u73af\u5883&#xff0c;\u907f\u514d\u79bb\u7ebf\u73af\u5883\u4f9d\u8d56\u51b2\u7a81<\/td>\n<td>Linux&#xff1a;\/opt\/offline-packages\/docker\/&#xff1b;Windows&#xff1a;D:\\\\offline-packages\\\\docker\\\\<\/td>\n<\/tr>\n<tr>\n<td>Elasticsearch 9.x Docker\u955c\u50cf<\/td>\n<td>9.1.3 \u7a33\u5b9a\u7248<\/td>\n<td>\u6709\u7f51\u73af\u5883\u6267\u884cdocker pull docker.elastic.co\/elasticsearch\/elasticsearch:9.1.3&#xff0c;\u518d\u5bfc\u51fa\u955c\u50cf<\/td>\n<td>ES\u6838\u5fc3\u670d\u52a1&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5\u5728\u7ebf\u62c9\u53d6&#xff0c;\u5fc5\u987b\u63d0\u524d\u5bfc\u51fa<\/td>\n<td>Linux&#xff1a;\/opt\/offline-packages\/images\/&#xff1b;Windows&#xff1a;D:\\\\offline-packages\\\\images\\\\<\/td>\n<\/tr>\n<tr>\n<td>LocalAI CPU\u7248 Docker\u955c\u50cf<\/td>\n<td>latest-cpu \u7a33\u5b9a\u7248<\/td>\n<td>\u6709\u7f51\u73af\u5883\u6267\u884cdocker pull localai\/localai:latest-cpu&#xff0c;\u518d\u5bfc\u51fa\u955c\u50cf<\/td>\n<td>\u672c\u5730\u8fd0\u884c\u5927\u6a21\u578b\u7684\u670d\u52a1&#xff0c;\u517c\u5bb9OpenAI\u63a5\u53e3&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u9700\u989d\u5916\u5b89\u88c5Python\u4f9d\u8d56<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>multilingual-e5-small \u5d4c\u5165\u6a21\u578b\u79bb\u7ebf\u5305<\/td>\n<td>ES\u5b98\u65b9\u5185\u7f6e\u7248<\/td>\n<td>Elastic\u5b98\u65b9\u6a21\u578b\u5e93\u4e0b\u8f7d\u5730\u5740<\/td>\n<td>ES\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5\u81ea\u52a8\u4e0b\u8f7d\u6a21\u578b&#xff0c;\u5fc5\u987b\u63d0\u524d\u4e0b\u8f7d\u624b\u52a8\u5bfc\u5165<\/td>\n<td>Linux&#xff1a;\/opt\/offline-packages\/models\/&#xff1b;Windows&#xff1a;D:\\\\offline-packages\\\\models\\\\<\/td>\n<\/tr>\n<tr>\n<td>dolphin3.0-qwen2.5-0.5b \u5927\u6a21\u578b\u6587\u4ef6<\/td>\n<td>Q4_K_M\u91cf\u5316\u7248GGUF\u683c\u5f0f<\/td>\n<td>Hugging Face\u5b98\u65b9\u4e0b\u8f7d\u9875<\/td>\n<td>\u672c\u5730\u751f\u6210\u7b54\u6848\u7684\u5927\u6a21\u578b&#xff0c;GGUF\u683c\u5f0f\u53ef\u79bb\u7ebf\u76f4\u63a5\u52a0\u8f7d<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>Python 3.10&#043; \u79bb\u7ebf\u5b89\u88c5\u5305<\/td>\n<td>3.10.14 \u7a33\u5b9a\u7248&#xff08;\u517c\u5bb9\u6027\u6700\u4f18&#xff09;<\/td>\n<td>Python\u5b98\u65b9\u4e0b\u8f7d\u9875<\/td>\n<td>\u8fd0\u884cRAG\u6838\u5fc3\u811a\u672c&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5\u4f7f\u7528\u5728\u7ebf\u5b89\u88c5\u5668<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>Python\u4f9d\u8d56\u5305\u79bb\u7ebfwhl\u5408\u96c6<\/td>\n<td>\u5bf9\u5e94\u7248\u672c<\/td>\n<td>\u6709\u7f51\u73af\u5883\u6267\u884cpip download elasticsearch&#061;&#061;9.1.0 requests openai -d .\/whl-packages<\/td>\n<td>\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5pip\u5728\u7ebf\u5b89\u88c5&#xff0c;\u5fc5\u987b\u63d0\u524d\u4e0b\u8f7dwhl\u5b89\u88c5\u5305<\/td>\n<td>Linux&#xff1a;\/opt\/offline-packages\/whl\/&#xff1b;Windows&#xff1a;D:\\\\offline-packages\\\\whl\\\\<\/td>\n<\/tr>\n<tr>\n<td>RAG\u79bb\u7ebf\u8fd0\u884c\u811a\u672c<\/td>\n<td>\u672c\u6587\u4f18\u5316\u7248<\/td>\n<td>\u590d\u5236\u672c\u6587\u6700\u540e\u7684\u5b8c\u6574\u811a\u672c&#xff0c;\u4fdd\u5b58\u4e3arag_offline.py<\/td>\n<td>\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91&#xff0c;\u5168\u79bb\u7ebf\u65e0\u5916\u90e8\u4f9d\u8d56<\/td>\n<td>\u79bb\u7ebf\u73af\u5883\u5de5\u4f5c\u76ee\u5f55&#xff0c;\u5982\/opt\/rag-offline\/<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u3010\u6709\u7f51\u73af\u5883\u5fc5\u505a\u3011Docker\u955c\u50cf\u5bfc\u51fa\u547d\u4ee4<\/h4>\n<p>\u5728\u6709\u7f51\u8bbe\u5907\u4e0a\u62c9\u53d6\u5b8c\u955c\u50cf\u540e&#xff0c;\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u51fa\u955c\u50cf\u6587\u4ef6&#xff0c;\u62f7\u8d1d\u5230\u79bb\u7ebf\u73af\u5883&#xff1a;<\/p>\n<p># \u5bfc\u51faES 9.1.3\u955c\u50cf<br \/>\ndocker save -o es-9.1.3.tar docker.elastic.co\/elasticsearch\/elasticsearch:9.1.3<br \/>\n# \u5bfc\u51faLocalAI CPU\u955c\u50cf<br \/>\ndocker save -o localai-cpu.tar localai\/localai:latest-cpu<\/p>\n<p>\u6267\u884c\u5b8c\u6210\u540e&#xff0c;\u5f53\u524d\u76ee\u5f55\u4f1a\u751f\u6210es-9.1.3.tar\u548clocalai-cpu.tar\u4e24\u4e2a\u6587\u4ef6&#xff0c;\u5fc5\u987b\u548c\u5176\u4ed6\u7269\u6599\u4e00\u8d77\u62f7\u8d1d\u5230\u79bb\u7ebf\u73af\u5883\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u7b2c\u4e8c\u6b65&#xff1a;\u79bb\u7ebf\u73af\u5883\u57fa\u7840\u73af\u5883\u90e8\u7f72<\/h3>\n<p>\u6240\u6709\u64cd\u4f5c\u5747\u5728\u79bb\u7ebf\u73af\u5883\u7684\u670d\u52a1\u5668\/\u7535\u8111\u4e0a\u6267\u884c&#xff0c;\u5168\u7a0b\u65e0\u9700\u8054\u7f51<\/p>\n<h4>3.1 \u5b89\u88c5Docker&#xff08;\u5bb9\u5668\u8fd0\u884c\u73af\u5883&#xff09;<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>Docker\u5c31\u50cf\u4e00\u4e2a\u201c\u9694\u79bb\u7684\u76d2\u5b50\u201d&#xff0c;\u6211\u4eec\u628aES\u548cLocalAI\u5206\u522b\u88c5\u5728\u4e24\u4e2a\u72ec\u7acb\u7684\u76d2\u5b50\u91cc&#xff0c;\u4e0d\u4f1a\u548c\u8bbe\u5907\u4e0a\u7684\u5176\u4ed6\u8f6f\u4ef6\u51b2\u7a81&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u9700\u89e3\u51b3\u590d\u6742\u7684\u4f9d\u8d56\u95ee\u9898&#xff0c;\u5bfc\u5165\u955c\u50cf\u5373\u53ef\u76f4\u63a5\u8fd0\u884c\u3002<\/p>\n<h5>Linux\u79bb\u7ebf\u5b89\u88c5\u6b65\u9aa4<\/h5>\n<li>\u8fdb\u5165Docker\u5b89\u88c5\u5305\u5b58\u653e\u76ee\u5f55&#xff0c;\u89e3\u538b\u5e76\u5b89\u88c5&#xff1a;<\/li>\n<p># \u8fdb\u5165Docker\u5b89\u88c5\u5305\u76ee\u5f55<br \/>\ncd \/opt\/offline-packages\/docker\/<br \/>\n# \u89e3\u538b\u5b89\u88c5\u5305<br \/>\ntar -zxvf docker-20.10.24.tgz<br \/>\n# \u5c06Docker\u4e8c\u8fdb\u5236\u6587\u4ef6\u590d\u5236\u5230\u7cfb\u7edfPATH&#xff0c;\u5b9e\u73b0\u5168\u5c40\u8c03\u7528<br \/>\ncp docker\/* \/usr\/bin\/<\/p>\n<li>\u914d\u7f6eDocker\u7cfb\u7edf\u670d\u52a1&#xff0c;\u5b9e\u73b0\u5f00\u673a\u81ea\u542f&#xff1a;<\/li>\n<p># \u521b\u5efaDocker\u670d\u52a1\u914d\u7f6e\u6587\u4ef6<br \/>\ncat &gt; \/etc\/systemd\/system\/docker.service &lt;&lt;EOF<br \/>\n[Unit]<br \/>\nDescription&#061;Docker Application Container Engine<br \/>\nDocumentation&#061;https:\/\/docs.docker.com<br \/>\nAfter&#061;network-online.target firewalld.service<br \/>\nWants&#061;network-online.target<\/p>\n<p>[Service]<br \/>\nType&#061;notify<br \/>\nExecStart&#061;\/usr\/bin\/dockerd<br \/>\nExecReload&#061;\/bin\/kill -s HUP $MAINPID<br \/>\nTimeoutSec&#061;0<br \/>\nRestartSec&#061;2<br \/>\nRestart&#061;always<\/p>\n<p>LimitNOFILE&#061;infinity<br \/>\nLimitNPROC&#061;infinity<br \/>\nLimitCORE&#061;infinity<\/p>\n<p>TasksMax&#061;infinity<br \/>\nDelegate&#061;yes<br \/>\nKillMode&#061;process<\/p>\n<p>[Install]<br \/>\nWantedBy&#061;multi-user.target<br \/>\nEOF<\/p>\n<li>\u542f\u52a8Docker\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f&#xff1a;<\/li>\n<p># \u91cd\u8f7d\u7cfb\u7edf\u670d\u52a1\u914d\u7f6e<br \/>\nsystemctl daemon-reload<br \/>\n# \u542f\u52a8Docker\u670d\u52a1<br \/>\nsystemctl start docker<br \/>\n# \u8bbe\u7f6e\u5f00\u673a\u81ea\u542f<br \/>\nsystemctl enable docker<\/p>\n<li>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011\u6267\u884cdocker version&#xff0c;\u80fd\u6b63\u5e38\u8f93\u51fa\u7248\u672c\u53f7&#xff0c;\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<h5>Windows\u79bb\u7ebf\u5b89\u88c5\u6b65\u9aa4<\/h5>\n<p>\u76f4\u63a5\u53cc\u51fbDocker Desktop\u79bb\u7ebf\u5b89\u88c5\u5305&#xff0c;\u8ddf\u968f\u5411\u5bfc\u5b8c\u6210\u5b89\u88c5&#xff0c;\u5b89\u88c5\u5b8c\u6210\u540e\u542f\u52a8Docker Desktop&#xff0c;\u53f3\u4e0b\u89d2Docker\u56fe\u6807\u663e\u793arunning&#xff0c;\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<h5>\u79bb\u7ebf\u73af\u5883\u5e38\u89c1\u62a5\u9519\u5904\u7406<\/h5>\n<ul>\n<li>\n<p>\u62a5\u9519permission denied&#xff1a;\u4f7f\u7528root\u7528\u6237\u6267\u884c&#xff0c;\u6216\u7ed9\u5f53\u524d\u7528\u6237\u914d\u7f6esudo\u6743\u9650<\/p>\n<\/li>\n<li>\n<p>\u62a5\u9519docker\u670d\u52a1\u542f\u52a8\u5931\u8d25&#xff1a;\u68c0\u67e5\u9632\u706b\u5899\u662f\u5426\u5173\u95ed&#xff0c;\u7cfb\u7edf\u5185\u6838\u7248\u672c\u662f\u5426\u7b26\u5408Docker\u8981\u6c42&#xff08;3.10&#043;&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h4>3.2 \u5bfc\u5165\u79bb\u7ebfDocker\u955c\u50cf<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>\u6211\u4eec\u5728\u6709\u7f51\u73af\u5883\u628aES\u548cLocalAI\u7684\u201c\u5b8c\u6574\u5b89\u88c5\u5305\u201d\u5bfc\u51fa\u6210\u4e86tar\u6587\u4ef6&#xff0c;\u73b0\u5728\u628a\u8fd9\u4e9b\u6587\u4ef6\u5bfc\u5165\u5230\u79bb\u7ebf\u73af\u5883\u7684Docker\u4e2d&#xff0c;\u5c31\u50cf\u624b\u673a\u5b89\u88c5APK\u6587\u4ef6\u4e00\u6837&#xff0c;\u65e0\u9700\u8054\u7f51\u5373\u53ef\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n<h5>\u64cd\u4f5c\u6b65\u9aa4<\/h5>\n<p># \u8fdb\u5165\u955c\u50cftar\u6587\u4ef6\u5b58\u653e\u76ee\u5f55<br \/>\ncd \/opt\/offline-packages\/images\/<br \/>\n# \u5bfc\u5165ES 9.1.3\u955c\u50cf<br \/>\ndocker load -i es-9.1.3.tar<br \/>\n# \u5bfc\u5165LocalAI CPU\u955c\u50cf<br \/>\ndocker load -i localai-cpu.tar<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<p>\u6267\u884cdocker images&#xff0c;\u80fd\u770b\u5230docker.elastic.co\/elasticsearch\/elasticsearch:9.1.3\u548clocalai\/localai:latest-cpu\u4e24\u4e2a\u955c\u50cf&#xff0c;\u8bf4\u660e\u5bfc\u5165\u6210\u529f\u3002<\/p>\n<h4>3.3 \u5b89\u88c5Python\u4e0e\u79bb\u7ebf\u4f9d\u8d56\u5305<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>RAG\u6838\u5fc3\u811a\u672c\u57fa\u4e8ePython\u5f00\u53d1&#xff0c;\u9700\u8981\u5b89\u88c5Python\u73af\u5883\u548c\u5bf9\u5e94\u7684\u4f9d\u8d56\u5e93\u3002\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5\u4f7f\u7528pip install\u5728\u7ebf\u5b89\u88c5&#xff0c;\u56e0\u6b64\u6211\u4eec\u63d0\u524d\u628a\u6240\u6709\u4f9d\u8d56\u5305\u7684\u79bb\u7ebf\u5b89\u88c5\u6587\u4ef6&#xff08;whl\u683c\u5f0f&#xff09;\u4e0b\u8f7d\u5b8c\u6210&#xff0c;\u76f4\u63a5\u672c\u5730\u5b89\u88c5\u5373\u53ef\u3002<\/p>\n<h5>\u64cd\u4f5c\u6b65\u9aa4<\/h5>\n<li>\n<p>\u5b89\u88c5Python 3.10<\/p>\n<ul>\n<li>\n<p>Linux&#xff1a;\u6267\u884crpm -ivh python-3.10.14.rpm&#xff08;\u5bf9\u5e94\u7cfb\u7edf\u7248\u672c&#xff09;&#xff0c;\u6216\u901a\u8fc7\u89e3\u538b\u5305\u7f16\u8bd1\u5b89\u88c5<\/p>\n<\/li>\n<li>\n<p>Windows&#xff1a;\u53cc\u51fbPython\u79bb\u7ebf\u5b89\u88c5\u5305&#xff0c;\u52fe\u9009\u201cAdd Python to PATH\u201d&#xff0c;\u8ddf\u968f\u5411\u5bfc\u5b8c\u6210\u5b89\u88c5<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u3010\u6210\u529f\u6821\u9a8cPython\u3011\u6267\u884cpython3 &#8211;version&#xff08;Linux&#xff09;\u6216python &#8211;version&#xff08;Windows&#xff09;&#xff0c;\u8f93\u51fa\u7248\u672c\u53f73.10.14&#xff0c;\u8bf4\u660e\u5b89\u88c5\u6210\u529f<\/p>\n<\/li>\n<li>\n<p>\u79bb\u7ebf\u5b89\u88c5Python\u4f9d\u8d56\u5305&#xff08;\u590d\u5236\u5373\u7528&#xff09;<\/p>\n<\/li>\n<p># \u8fdb\u5165whl\u5305\u5b58\u653e\u76ee\u5f55<br \/>\ncd \/opt\/offline-packages\/whl\/<br \/>\n# \u672c\u5730\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\u5305&#xff0c;\u5b8c\u5168\u79bb\u7ebf&#xff0c;\u65e0\u5916\u7f51\u8c03\u7528<br \/>\npip install &#8211;no-index &#8211;find-links&#061;.\/ elasticsearch requests openai<\/p>\n<li>\u3010\u6210\u529f\u6821\u9a8c\u4f9d\u8d56\u3011\u6267\u884cpip list&#xff0c;\u80fd\u770b\u5230elasticsearch\u3001requests\u3001openai\u4e09\u4e2a\u5305&#xff0c;\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<hr \/>\n<h3>\u56db\u3001\u7b2c\u4e09\u6b65&#xff1a;Elasticsearch 9.x \u79bb\u7ebf\u90e8\u7f72<\/h3>\n<h4>4.1 \u63d0\u524d\u89c4\u5212&#xff1a;ES\u79bb\u7ebf\u73af\u5883\u76ee\u5f55<\/h4>\n<p>\u6240\u6709\u6570\u636e\u3001\u914d\u7f6e\u3001\u6a21\u578b\u5747\u5b58\u50a8\u5728\u5bbf\u4e3b\u673a\u76ee\u5f55&#xff0c;\u5bb9\u5668\u91cd\u542f\u4e0d\u4f1a\u4e22\u5931\u6570\u636e&#xff0c;\u79bb\u7ebf\u73af\u5883\u5fc5\u987b\u505a\u6301\u4e45\u5316\u914d\u7f6e<\/p>\n<p># \u521b\u5efaES\u5de5\u4f5c\u76ee\u5f55&#xff0c;\u6240\u6709\u6570\u636e\u5747\u5b58\u50a8\u5728\u6b64\u5904<br \/>\nmkdir -p \/opt\/rag-offline\/es\/{data,logs,config,models}<br \/>\n# \u7ed9\u76ee\u5f55\u8d4b\u8bfb\u5199\u6743\u9650&#xff0c;ES\u5bb9\u5668\u5185\u90e8\u7528\u6237\u4e3a1000&#xff0c;\u5fc5\u987b\u5f00\u653e\u6743\u9650\u5426\u5219\u542f\u52a8\u5931\u8d25<br \/>\nchmod -R 777 \/opt\/rag-offline\/es\/<\/p>\n<h4>4.2 \u542f\u52a8ES 9.x \u79bb\u7ebf\u5355\u8282\u70b9\u5bb9\u5668<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>\u6211\u4eec\u901a\u8fc7Docker\u542f\u52a8ES&#xff0c;\u6240\u6709\u914d\u7f6e\u5747\u9002\u914d\u79bb\u7ebf\u5355\u8282\u70b9\u73af\u5883&#xff0c;\u5173\u95ed\u4e86\u6240\u6709\u9700\u8981\u8054\u7f51\u7684\u529f\u80fd&#xff0c;\u5f00\u542f\u4e86\u5b89\u5168\u8ba4\u8bc1&#xff0c;\u540c\u65f6\u628a\u6570\u636e\u3001\u914d\u7f6e\u6301\u4e45\u5316\u5230\u5bbf\u4e3b\u673a&#xff0c;\u5373\u4f7f\u5bb9\u5668\u5220\u9664&#xff0c;\u6570\u636e\u4e5f\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n<h5>\u542f\u52a8\u547d\u4ee4<\/h5>\n<p>docker run -d \\\\<br \/>\n  &#8211;name es-rag-offline \\\\<br \/>\n  &#8211;restart&#061;always \\\\<br \/>\n  -p 9200:9200 \\\\<br \/>\n  -p 9300:9300 \\\\<br \/>\n  -e &#034;discovery.type&#061;single-node&#034; \\\\ # \u5355\u8282\u70b9\u6a21\u5f0f&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u9700\u96c6\u7fa4\u914d\u7f6e<br \/>\n  -e &#034;ES_JAVA_OPTS&#061;-Xms2g -Xmx2g&#034; \\\\ # \u5806\u5185\u5b58\u8bbe\u7f6e&#xff0c;\u5efa\u8bae\u4e3a\u8bbe\u5907\u5185\u5b58\u76841\/4&#xff0c;\u6700\u4f4e2G<br \/>\n  -e &#034;xpack.security.enabled&#061;true&#034; \\\\ # \u5f00\u542f\u5b89\u5168\u8ba4\u8bc1&#xff0c;\u7b26\u5408\u5185\u7f51\u5408\u89c4\u8981\u6c42<br \/>\n  -e &#034;xpack.security.authc.api_key.enabled&#061;true&#034; \\\\ # \u5f00\u542fAPI\u5bc6\u94a5\u8ba4\u8bc1&#xff0c;\u811a\u672c\u8c03\u7528\u4f7f\u7528<br \/>\n  -e &#034;xpack.ml.enabled&#061;true&#034; \\\\ # \u5f00\u542f\u673a\u5668\u5b66\u4e60\u529f\u80fd&#xff0c;\u7528\u4e8e\u52a0\u8f7d\u5d4c\u5165\u6a21\u578b<br \/>\n  -e &#034;xpack.ml.model_repository.file.enabled&#061;true&#034; \\\\ # \u5f00\u542f\u672c\u5730\u6a21\u578b\u5bfc\u5165&#xff0c;\u79bb\u7ebf\u73af\u5883\u6838\u5fc3\u914d\u7f6e<br \/>\n  -v \/opt\/rag-offline\/es\/data:\/usr\/share\/elasticsearch\/data \\\\<br \/>\n  -v \/opt\/rag-offline\/es\/logs:\/usr\/share\/elasticsearch\/logs \\\\<br \/>\n  -v \/opt\/rag-offline\/es\/config:\/usr\/share\/elasticsearch\/config \\\\<br \/>\n  -v \/opt\/rag-offline\/es\/models:\/usr\/share\/elasticsearch\/models \\\\ # \u6302\u8f7d\u79bb\u7ebf\u6a21\u578b\u76ee\u5f55<br \/>\n  docker.elastic.co\/elasticsearch\/elasticsearch:9.1.3<\/p>\n<h5>Windows\u73af\u5883\u9002\u914d<\/h5>\n<p>\u5c06\u76ee\u5f55\u66ff\u6362\u4e3aWindows\u8def\u5f84&#xff0c;\u6bd4\u5982D:\\\\rag-offline\\\\es\\\\data&#xff0c;\u547d\u4ee4\u4fee\u6539\u4e3a&#xff1a;<\/p>\n<p>docker run -d ^<br \/>\n  &#8211;name es-rag-offline ^<br \/>\n  &#8211;restart&#061;always ^<br \/>\n  -p 9200:9200 ^<br \/>\n  -p 9300:9300 ^<br \/>\n  -e &#034;discovery.type&#061;single-node&#034; ^<br \/>\n  -e &#034;ES_JAVA_OPTS&#061;-Xms2g -Xmx2g&#034; ^<br \/>\n  -e &#034;xpack.security.enabled&#061;true&#034; ^<br \/>\n  -e &#034;xpack.security.authc.api_key.enabled&#061;true&#034; ^<br \/>\n  -e &#034;xpack.ml.enabled&#061;true&#034; ^<br \/>\n  -e &#034;xpack.ml.model_repository.file.enabled&#061;true&#034; ^<br \/>\n  -v D:\\\\rag-offline\\\\es\\\\data:\/usr\/share\/elasticsearch\/data ^<br \/>\n  -v D:\\\\rag-offline\\\\es\\\\logs:\/usr\/share\/elasticsearch\/logs ^<br \/>\n  -v D:\\\\rag-offline\\\\es\\\\config:\/usr\/share\/elasticsearch\/config ^<br \/>\n  -v D:\\\\rag-offline\\\\es\\\\models:\/usr\/share\/elasticsearch\/models ^<br \/>\n  docker.elastic.co\/elasticsearch\/elasticsearch:9.1.3<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<li>\n<p>\u6267\u884cdocker ps&#xff0c;\u770b\u5230ES\u5bb9\u5668\u7684STATUS\u4e3aUp X seconds (healthy)&#xff0c;\u8bf4\u660e\u542f\u52a8\u6210\u529f&#xff08;\u5fc5\u987b\u663e\u793ahealthy&#xff0c;\u4ec5Up\u4e0d\u4ee3\u8868\u5b8c\u5168\u542f\u52a8&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff0c;\u80fd\u8fd4\u56deES\u7684\u7248\u672c\u4fe1\u606f&#xff0c;\u8bf4\u660eAPI\u53ef\u6b63\u5e38\u8bbf\u95ee&#xff1a;<\/p>\n<\/li>\n<p>curl -X GET &#034;http:\/\/localhost:9200\/&#034; -u &#034;elastic:\u4f60\u7684elastic\u5bc6\u7801&#034;<\/p>\n<p>\u8865\u5145\u8bf4\u660e&#xff1a;ES\u9996\u6b21\u542f\u52a8\u4f1a\u81ea\u52a8\u751f\u6210elastic\u7528\u6237\u7684\u5bc6\u7801&#xff0c;\u6267\u884cdocker logs es-rag-offline | grep &#034;Password for the elastic user is&#034;\u5373\u53ef\u83b7\u53d6&#xff0c;\u52a1\u5fc5\u59a5\u5584\u4fdd\u5b58\u3002<\/p>\n<h4>4.3 \u79bb\u7ebf\u5bfc\u5165multilingual-e5-small\u5d4c\u5165\u6a21\u578b\u5230ES<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>\u5728\u7ebf\u73af\u5883\u4e2d&#xff0c;ES\u4f1a\u81ea\u52a8\u4ece\u5b98\u7f51\u4e0b\u8f7d\u8be5\u5d4c\u5165\u6a21\u578b&#xff0c;\u4f46\u79bb\u7ebf\u73af\u5883\u65e0\u6cd5\u8054\u7f51&#xff0c;\u56e0\u6b64\u6211\u4eec\u9700\u8981\u63d0\u524d\u628a\u6a21\u578b\u6587\u4ef6\u4e0b\u8f7d\u597d&#xff0c;\u653e\u5230ES\u7684\u6a21\u578b\u76ee\u5f55\u4e2d&#xff0c;\u8ba9ES\u79bb\u7ebf\u52a0\u8f7d\u8be5\u6a21\u578b&#xff0c;\u624d\u80fd\u5728\u65e0\u5916\u7f51\u7684\u73af\u5883\u4e0b\u751f\u6210\u8bed\u4e49\u5411\u91cf\u3002<\/p>\n<h5>\u64cd\u4f5c\u6b65\u9aa4<\/h5>\n<li>\n<p>\u628a\u63d0\u524d\u4e0b\u8f7d\u597d\u7684multilingual-e5-small\u6a21\u578b\u538b\u7f29\u5305&#xff0c;\u89e3\u538b\u5230\/opt\/rag-offline\/es\/models\/\u76ee\u5f55&#xff0c;\u786e\u4fdd\u89e3\u538b\u540e\u7684\u6a21\u578b\u6587\u4ef6\u76f4\u63a5\u5728\u8be5\u76ee\u5f55\u4e0b<\/p>\n<\/li>\n<li>\n<p>\u7ed9\u6a21\u578b\u6587\u4ef6\u8d4b\u6743\u9650&#xff1a;chmod -R 777 \/opt\/rag-offline\/es\/models\/<\/p>\n<\/li>\n<li>\n<p>\u91cd\u542fES\u5bb9\u5668&#xff0c;\u8ba9ES\u52a0\u8f7d\u672c\u5730\u6a21\u578b&#xff1a;docker restart es-rag-offline<\/p>\n<\/li>\n<li>\n<p>\u7b49\u5f85ES\u91cd\u542f\u5b8c\u6210&#xff08;STATUS\u53d8\u4e3ahealthy&#xff09;&#xff0c;\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff0c;\u9a8c\u8bc1\u6a21\u578b\u662f\u5426\u52a0\u8f7d\u6210\u529f&#xff1a;<\/p>\n<\/li>\n<p>curl -X GET &#034;http:\/\/localhost:9200\/_ml\/trained_models\/.multilingual-e5-small&#034; -u &#034;elastic:\u4f60\u7684elastic\u5bc6\u7801&#034;<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<p>\u547d\u4ee4\u8fd4\u56de\u6a21\u578b\u7684\u8be6\u7ec6\u4fe1\u606f&#xff0c;\u65e0\u62a5\u9519&#xff0c;\u8bf4\u660e\u6a21\u578b\u79bb\u7ebf\u52a0\u8f7d\u6210\u529f&#xff0c;ES\u53ef\u5728\u79bb\u7ebf\u73af\u5883\u4f7f\u7528\u8be5\u6a21\u578b\u751f\u6210\u8bed\u4e49\u5411\u91cf\u3002<\/p>\n<h4>4.4 \u751f\u6210ES API\u5bc6\u94a5<\/h4>\n<h5>\u64cd\u4f5c\u6b65\u9aa4<\/h5>\n<p>curl -X POST &#034;http:\/\/localhost:9200\/_security\/api_key&#034; \\\\<br \/>\n  -u &#034;elastic:\u4f60\u7684elastic\u5bc6\u7801&#034; \\\\<br \/>\n  -H &#034;Content-Type: application\/json&#034; \\\\<br \/>\n  -d &#039;{<br \/>\n    &#034;name&#034;: &#034;rag-offline-api-key&#034;,<br \/>\n    &#034;expiration&#034;: &#034;10y&#034;,<br \/>\n    &#034;role_descriptors&#034;: {<br \/>\n      &#034;rag-admin&#034;: {<br \/>\n        &#034;cluster&#034;: [&#034;all&#034;],<br \/>\n        &#034;index&#034;: [<br \/>\n          {<br \/>\n            &#034;names&#034;: [&#034;*&#034;],<br \/>\n            &#034;privileges&#034;: [&#034;all&#034;]<br \/>\n          }<br \/>\n        ]<br \/>\n      }<br \/>\n    }<br \/>\n  }&#039;<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<p>\u8fd4\u56de\u7ed3\u679c\u4e2d\u7684encoded\u5b57\u6bb5&#xff0c;\u5c31\u662f\u4f60\u7684API\u5bc6\u94a5&#xff0c;\u52a1\u5fc5\u590d\u5236\u4fdd\u5b58&#xff0c;\u540e\u7eed\u811a\u672c\u9700\u8981\u4f7f\u7528&#xff0c;\u683c\u5f0f\u793a\u4f8b&#xff1a;MTk0NVRwa0IxRGRjVmVKSGl2ZFc6dUFaNkZTUHVXRzEzVjdrejQzSUNxZw&#061;&#061;<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u7b2c\u56db\u6b65&#xff1a;LocalAI&#043;\u5927\u6a21\u578b \u5b8c\u5168\u79bb\u7ebf\u90e8\u7f72<\/h3>\n<h4>5.1 \u63d0\u524d\u89c4\u5212&#xff1a;LocalAI\u79bb\u7ebf\u73af\u5883\u76ee\u5f55<\/h4>\n<p># \u521b\u5efaLocalAI\u5de5\u4f5c\u76ee\u5f55&#xff0c;\u5b58\u653e\u5927\u6a21\u578b\u6587\u4ef6<br \/>\nmkdir -p \/opt\/rag-offline\/localai\/models<br \/>\n# \u7ed9\u76ee\u5f55\u8d4b\u8bfb\u5199\u6743\u9650<br \/>\nchmod -R 777 \/opt\/rag-offline\/localai\/<\/p>\n<h4>5.2 \u653e\u7f6e\u5927\u6a21\u578b\u6587\u4ef6<\/h4>\n<p>\u628a\u63d0\u524d\u4e0b\u8f7d\u597d\u7684dolphin3.0-qwen2.5-0.5b-instruct.Q4_K_M.gguf\u6587\u4ef6&#xff0c;\u62f7\u8d1d\u5230\/opt\/rag-offline\/localai\/models\u76ee\u5f55\u4e2d&#xff0c;LocalAI\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8\u52a0\u8f7d\u8be5\u6a21\u578b&#xff0c;\u5b8c\u5168\u79bb\u7ebf&#xff0c;\u65e0\u9700\u901a\u8fc7API\u4e0b\u8f7d\u3002<\/p>\n<h4>5.3 \u542f\u52a8LocalAI\u79bb\u7ebf\u5bb9\u5668<\/h4>\n<h5>\u539f\u7406\u5927\u767d\u8bdd<\/h5>\n<p>LocalAI\u5c31\u50cf\u4e00\u4e2a\u672c\u5730\u7684OpenAI\u670d\u52a1&#xff0c;\u6211\u4eec\u628a\u5927\u6a21\u578b\u6587\u4ef6\u6302\u8f7d\u5230\u5bb9\u5668\u4e2d&#xff0c;\u5b83\u542f\u52a8\u65f6\u4f1a\u81ea\u52a8\u52a0\u8f7d&#xff0c;\u5bf9\u5916\u63d0\u4f9b\u548cOpenAI\u5b8c\u5168\u517c\u5bb9\u7684API\u63a5\u53e3&#xff0c;RAG\u811a\u672c\u65e0\u9700\u4fee\u6539\u4efb\u4f55\u4ee3\u7801&#xff0c;\u5373\u53ef\u8c03\u7528\u672c\u5730\u5927\u6a21\u578b&#xff0c;\u5168\u7a0b\u65e0\u5916\u7f51\u8c03\u7528\u3002<\/p>\n<h5>\u542f\u52a8\u547d\u4ee4<\/h5>\n<p>docker run -d \\\\<br \/>\n  &#8211;name localai-rag-offline \\\\<br \/>\n  &#8211;restart&#061;always \\\\<br \/>\n  -p 8080:8080 \\\\<br \/>\n  -v \/opt\/rag-offline\/localai\/models:\/models \\\\ # \u6302\u8f7d\u672c\u5730\u6a21\u578b\u76ee\u5f55<br \/>\n  -e DEBUG&#061;false \\\\<br \/>\n  -e MODELS_PATH&#061;\/models \\\\<br \/>\n  -e THREADS&#061;4 \\\\ # \u6539\u4e3a\u4f60\u7684CPU\u7269\u7406\u6838\u5fc3\u6570&#xff0c;\u6838\u5fc3\u8d8a\u591a\u751f\u6210\u901f\u5ea6\u8d8a\u5feb<br \/>\n  -e CONTEXT_SIZE&#061;2048 \\\\ # \u4e0a\u4e0b\u6587\u7a97\u53e3&#xff0c;\u5e73\u8861\u5185\u5b58\u5360\u7528\u548c\u957f\u6587\u672c\u652f\u6301<br \/>\n  -e PRELOAD_MODELS&#061;dolphin3.0-qwen2.5-0.5b-instruct.Q4_K_M.gguf \\\\ # \u542f\u52a8\u65f6\u9884\u52a0\u8f7d\u6a21\u578b&#xff0c;\u65e0\u9700\u7b49\u5f85\u8c03\u7528\u518d\u52a0\u8f7d<br \/>\n  localai\/localai:latest-cpu<\/p>\n<h5>Windows\u73af\u5883\u9002\u914d<\/h5>\n<p>\u5c06\u76ee\u5f55\u66ff\u6362\u4e3aWindows\u8def\u5f84&#xff0c;\u6bd4\u5982D:\\\\rag-offline\\\\localai\\\\models&#xff0c;\u4fee\u6539\u4e3a\u5bf9\u5e94Windows\u683c\u5f0f\u5373\u53ef\u3002<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<li>\n<p>\u6267\u884cdocker ps&#xff0c;\u770b\u5230LocalAI\u5bb9\u5668STATUS\u4e3aUp&#xff0c;\u8bf4\u660e\u542f\u52a8\u6210\u529f<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff0c;\u9a8c\u8bc1\u6a21\u578b\u662f\u5426\u52a0\u8f7d\u6210\u529f&#xff0c;\u53ef\u6b63\u5e38\u751f\u6210\u5185\u5bb9&#xff1a;<\/p>\n<\/li>\n<p>curl -X POST http:\/\/localhost:8080\/v1\/chat\/completions \\\\<br \/>\n  -H &#034;Content-Type: application\/json&#034; \\\\<br \/>\n  -d &#039;{<br \/>\n    &#034;model&#034;: &#034;dolphin3.0-qwen2.5-0.5b-instruct.Q4_K_M.gguf&#034;,<br \/>\n    &#034;messages&#034;: [{&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: &#034;\u4f60\u597d&#034;}],<br \/>\n    &#034;stream&#034;: false<br \/>\n  }&#039;<\/p>\n<li>\u547d\u4ee4\u8fd4\u56de\u5927\u6a21\u578b\u751f\u6210\u7684\u56de\u590d&#xff0c;\u65e0\u62a5\u9519&#xff0c;\u8bf4\u660eLocalAI\u79bb\u7ebf\u90e8\u7f72\u6210\u529f\u3002<\/li>\n<hr \/>\n<h3>\u516d\u3001\u7b2c\u4e94\u6b65&#xff1a;RAG\u6838\u5fc3\u914d\u7f6e\u4e0e\u79bb\u7ebf\u811a\u672c\u90e8\u7f72<\/h3>\n<h4>6.1 \u539f\u7406\u5927\u767d\u8bdd<\/h4>\n<p>\u8fd9\u4e2a\u811a\u672c\u662f\u6574\u4e2a\u7cfb\u7edf\u7684\u201c\u603b\u6307\u6325\u201d&#xff0c;\u5168\u7a0b\u65e0\u5916\u7f51\u8c03\u7528&#xff0c;\u81ea\u52a8\u5b8c\u6210\u4ee5\u4e0b\u5de5\u4f5c&#xff1a;<\/p>\n<li>\n<p>\u5728ES\u4e2d\u521b\u5efa\u79bb\u7ebf\u63a8\u7406\u7aef\u70b9&#xff0c;\u7528\u4e8e\u751f\u6210\u8bed\u4e49\u5411\u91cf<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efa\u77e5\u8bc6\u5e93\u7d22\u5f15&#xff0c;\u7528\u4e8e\u5b58\u50a8\u6587\u6863\u548c\u8bed\u4e49\u6807\u7b7e<\/p>\n<\/li>\n<li>\n<p>\u6279\u91cf\u5bfc\u5165\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u7684\u6587\u6863\u5230ES\u77e5\u8bc6\u5e93<\/p>\n<\/li>\n<li>\n<p>\u8f93\u5165\u95ee\u9898\u540e&#xff0c;\u81ea\u52a8\u5728ES\u4e2d\u6267\u884c\u8bed\u4e49\u68c0\u7d22&#xff0c;\u5339\u914d\u76f8\u5173\u6587\u6863<\/p>\n<\/li>\n<li>\n<p>\u628a\u68c0\u7d22\u5230\u7684\u5185\u5bb9\u53d1\u9001\u7ed9\u672c\u5730\u5927\u6a21\u578b&#xff0c;\u751f\u6210\u5e26\u5f15\u6587\u7684\u7cbe\u51c6\u7b54\u6848<\/p>\n<\/li>\n<li>\n<p>\u8f93\u51fa\u6700\u7ec8\u7ed3\u679c\u548c\u6027\u80fd\u6570\u636e<\/p>\n<\/li>\n<h4>6.2 \u51c6\u5907\u77e5\u8bc6\u5e93\u6587\u6863<\/h4>\n<p>\u5728\u79bb\u7ebf\u73af\u5883\u4e2d&#xff0c;\u521b\u5efa\/opt\/rag-offline\/dataset\u76ee\u5f55&#xff0c;\u628a\u6240\u6709txt\u683c\u5f0f\u7684\u6587\u6863&#xff08;\u4f1a\u8bae\u7eaa\u8981\u3001\u62a5\u544a\u3001\u5236\u5ea6\u6587\u4ef6\u7b49&#xff09;\u653e\u5165\u8be5\u76ee\u5f55&#xff0c;\u811a\u672c\u4f1a\u81ea\u52a8\u8bfb\u53d6\u6240\u6709txt\u6587\u4ef6\u3002<\/p>\n<h4>6.3 \u5b8c\u6574\u79bb\u7ebfRAG\u811a\u672c<\/h4>\n<p>\u628a\u4ee5\u4e0b\u811a\u672c\u4fdd\u5b58\u4e3a\/opt\/rag-offline\/rag_offline.py&#xff0c;\u4ec5\u9700\u4fee\u6539\u5f00\u5934\u76843\u4e2a\u914d\u7f6e\u9879&#xff08;ES_API_KEY\u3001AI_MODEL_NAME\u3001DATASET_FOLDER&#xff09;&#xff0c;\u5176\u4f59\u5185\u5bb9\u65e0\u9700\u4fee\u6539\u3002<\/p>\n<p>import os<br \/>\nimport time<br \/>\nfrom elasticsearch import Elasticsearch, helpers<br \/>\nfrom openai import OpenAI<\/p>\n<p># &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u3010\u4ec5\u9700\u4fee\u6539\u8fd9\u91cc\u7684\u914d\u7f6e&#xff0c;\u5176\u4ed6\u5185\u5bb9\u65e0\u9700\u6539\u52a8\u3011&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n# \u66ff\u6362\u4e3a\u4e4b\u524d\u751f\u6210\u7684ES API\u5bc6\u94a5<br \/>\nES_API_KEY &#061; &#034;\u4f60\u7684ES API\u5bc6\u94a5&#034;<br \/>\n# \u66ff\u6362\u4e3a\u653e\u5165models\u76ee\u5f55\u7684\u5927\u6a21\u578b\u6587\u4ef6\u540d&#xff0c;\u5fc5\u987b\u548c\u6587\u4ef6\u540d\u5b8c\u5168\u4e00\u81f4<br \/>\nAI_MODEL_NAME &#061; &#034;dolphin3.0-qwen2.5-0.5b-instruct.Q4_K_M.gguf&#034;<br \/>\n# \u77e5\u8bc6\u5e93\u6587\u6863\u5b58\u653e\u76ee\u5f55<br \/>\nDATASET_FOLDER &#061; &#034;\/opt\/rag-offline\/dataset&#034;<br \/>\n# &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/p>\n<p># \u56fa\u5b9a\u914d\u7f6e&#xff0c;\u79bb\u7ebf\u73af\u5883\u65e0\u9700\u4fee\u6539<br \/>\nES_URL &#061; &#034;http:\/\/localhost:9200&#034;<br \/>\nINDEX_NAME &#061; &#034;offline-rag-knowledge-base&#034;<br \/>\nLOCAL_AI_URL &#061; &#034;http:\/\/localhost:8080\/v1&#034;<\/p>\n<p># \u521d\u59cb\u5316\u5ba2\u6237\u7aef&#xff0c;\u5168\u7a0b\u65e0\u5916\u7f51\u8c03\u7528<br \/>\nes_client &#061; Elasticsearch(ES_URL, api_key&#061;ES_API_KEY)<br \/>\nai_client &#061; OpenAI(base_url&#061;LOCAL_AI_URL, api_key&#061;&#034;sk-offline-rag&#034;)  # API key\u586b\u5199\u4efb\u610f\u975e\u7a7a\u5b57\u7b26\u4e32\u5373\u53ef&#xff0c;\u65e0\u9700\u771f\u5b9e\u5bc6\u94a5<\/p>\n<p>def check_es_connect():<br \/>\n    &#034;&#034;&#034;\u68c0\u67e5ES\u8fde\u63a5\u662f\u5426\u6b63\u5e38&#xff0c;\u79bb\u7ebf\u73af\u5883\u7b2c\u4e00\u6b65\u5fc5\u505a&#034;&#034;&#034;<br \/>\n    try:<br \/>\n        if not es_client.ping():<br \/>\n            print(&#034;\u274c \u65e0\u6cd5\u8fde\u63a5\u5230Elasticsearch&#xff0c;\u8bf7\u68c0\u67e5\u670d\u52a1\u662f\u5426\u542f\u52a8\u3001API\u5bc6\u94a5\u662f\u5426\u6b63\u786e&#034;)<br \/>\n            exit(1)<br \/>\n        es_info &#061; es_client.info()<br \/>\n        print(f&#034;\u2705 \u6210\u529f\u8fde\u63a5Elasticsearch&#xff0c;\u7248\u672c&#xff1a;{es_info[&#039;version&#039;][&#039;number&#039;]}&#034;)<br \/>\n        return True<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u274c ES\u8fde\u63a5\u5931\u8d25&#xff0c;\u9519\u8bef\u4fe1\u606f&#xff1a;{str(e)}&#034;)<br \/>\n        exit(1)<\/p>\n<p>def setup_embedding_inference():<br \/>\n    &#034;&#034;&#034;\u521b\u5efa\u79bb\u7ebf\u5d4c\u5165\u63a8\u7406\u7aef\u70b9&#xff0c;\u4f7f\u7528\u63d0\u524d\u5bfc\u5165\u7684e5-small\u6a21\u578b&#xff0c;\u65e0\u5916\u7f51\u8c03\u7528&#034;&#034;&#034;<br \/>\n    inference_id &#061; &#034;offline-e5-small-embedding&#034;<br \/>\n    # \u5148\u68c0\u67e5\u63a8\u7406\u7aef\u70b9\u662f\u5426\u5df2\u5b58\u5728&#xff0c;\u5b58\u5728\u5219\u65e0\u9700\u91cd\u590d\u521b\u5efa<br \/>\n    try:<br \/>\n        es_client.inference.get(inference_id&#061;inference_id)<br \/>\n        print(f&#034;\u2705 \u5d4c\u5165\u63a8\u7406\u7aef\u70b9 {inference_id} \u5df2\u5b58\u5728&#xff0c;\u65e0\u9700\u91cd\u590d\u521b\u5efa&#034;)<br \/>\n        return<br \/>\n    except Exception:<br \/>\n        pass<\/p>\n<p>    # \u521b\u5efa\u63a8\u7406\u7aef\u70b9&#xff0c;\u5b8c\u5168\u9002\u914d\u79bb\u7ebf\u73af\u5883&#xff0c;\u65e0\u5916\u90e8\u8c03\u7528<br \/>\n    try:<br \/>\n        es_client.inference.put(<br \/>\n            inference_id&#061;inference_id,<br \/>\n            task_type&#061;&#034;text_embedding&#034;,<br \/>\n            body&#061;{<br \/>\n                &#034;service&#034;: &#034;elasticsearch&#034;,<br \/>\n                &#034;service_settings&#034;: {<br \/>\n                    &#034;num_allocations&#034;: 1,<br \/>\n                    &#034;num_threads&#034;: 1,<br \/>\n                    &#034;model_id&#034;: &#034;.multilingual-e5-small&#034;,  # \u4f7f\u7528\u63d0\u524d\u79bb\u7ebf\u5bfc\u5165\u7684\u6a21\u578b<br \/>\n                },<br \/>\n                &#034;chunking_settings&#034;: {<br \/>\n                    &#034;strategy&#034;: &#034;sentence&#034;,<br \/>\n                    &#034;max_chunk_size&#034;: 250,<br \/>\n                    &#034;sentence_overlap&#034;: 2<br \/>\n                }<br \/>\n            }<br \/>\n        )<br \/>\n        print(f&#034;\u2705 \u5d4c\u5165\u63a8\u7406\u7aef\u70b9 {inference_id} \u521b\u5efa\u6210\u529f&#034;)<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u274c \u5d4c\u5165\u63a8\u7406\u7aef\u70b9\u521b\u5efa\u5931\u8d25&#xff0c;\u9519\u8bef\u4fe1\u606f&#xff1a;{str(e)}&#034;)<br \/>\n        exit(1)<\/p>\n<p>def setup_knowledge_index():<br \/>\n    &#034;&#034;&#034;\u521b\u5efa\u77e5\u8bc6\u5e93\u7d22\u5f15&#xff0c;\u4f7f\u7528ES9.x\u539f\u751fsemantic_text\u5b57\u6bb5&#xff0c;\u81ea\u52a8\u5904\u7406\u5411\u91cf&#xff0c;\u65e0\u9700\u624b\u52a8\u7f16\u7801&#034;&#034;&#034;<br \/>\n    try:<br \/>\n        if es_client.indices.exists(index&#061;INDEX_NAME):<br \/>\n            print(f&#034;\u2705 \u77e5\u8bc6\u5e93\u7d22\u5f15 {INDEX_NAME} \u5df2\u5b58\u5728&#xff0c;\u65e0\u9700\u91cd\u590d\u521b\u5efa&#034;)<br \/>\n            return False<\/p>\n<p>        print(f&#034;&#x1f4e6; \u6b63\u5728\u521b\u5efa\u77e5\u8bc6\u5e93\u7d22\u5f15 {INDEX_NAME}&#8230;&#034;)<br \/>\n        es_client.indices.create(<br \/>\n            index&#061;INDEX_NAME,<br \/>\n            body&#061;{<br \/>\n                # \u79bb\u7ebf\u5355\u8282\u70b9\u73af\u5883\u4e13\u5c5e\u914d\u7f6e&#xff0c;\u907f\u514d\u7d22\u5f15\u9ec4\u6807&#xff0c;\u63d0\u5347\u6027\u80fd<br \/>\n                &#034;settings&#034;: {<br \/>\n                    &#034;number_of_shards&#034;: 1,<br \/>\n                    &#034;number_of_replicas&#034;: 0,<br \/>\n                    &#034;refresh_interval&#034;: &#034;1s&#034;<br \/>\n                },<br \/>\n                # \u7d22\u5f15\u6620\u5c04&#xff0c;\u6838\u5fc3\u4e3asemantic_text\u8bed\u4e49\u5b57\u6bb5&#xff0c;\u81ea\u52a8\u5904\u7406\u5411\u91cf\u751f\u6210\u548c\u68c0\u7d22<br \/>\n                &#034;mappings&#034;: {<br \/>\n                    &#034;properties&#034;: {<br \/>\n                        &#034;file_name&#034;: {<br \/>\n                            &#034;type&#034;: &#034;text&#034;,<br \/>\n                            &#034;copy_to&#034;: &#034;semantic_content&#034;  # \u628a\u6587\u4ef6\u540d\u590d\u5236\u5230\u8bed\u4e49\u5b57\u6bb5&#xff0c;\u652f\u6301\u6309\u6587\u4ef6\u540d\u68c0\u7d22<br \/>\n                        },<br \/>\n                        &#034;file_content&#034;: {<br \/>\n                            &#034;type&#034;: &#034;text&#034;,<br \/>\n                            &#034;copy_to&#034;: &#034;semantic_content&#034;  # \u628a\u6587\u4ef6\u5185\u5bb9\u590d\u5236\u5230\u8bed\u4e49\u5b57\u6bb5&#xff0c;\u652f\u6301\u6309\u5185\u5bb9\u68c0\u7d22<br \/>\n                        },<br \/>\n                        &#034;semantic_content&#034;: {<br \/>\n                            &#034;type&#034;: &#034;semantic_text&#034;,<br \/>\n                            &#034;inference_id&#034;: &#034;offline-e5-small-embedding&#034;  # \u7ed1\u5b9a\u521b\u5efa\u7684\u79bb\u7ebf\u63a8\u7406\u7aef\u70b9<br \/>\n                        }<br \/>\n                    }<br \/>\n                }<br \/>\n            }<br \/>\n        )<br \/>\n        print(f&#034;\u2705 \u77e5\u8bc6\u5e93\u7d22\u5f15 {INDEX_NAME} \u521b\u5efa\u6210\u529f&#034;)<br \/>\n        return True<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u274c \u77e5\u8bc6\u5e93\u7d22\u5f15\u521b\u5efa\u5931\u8d25&#xff0c;\u9519\u8bef\u4fe1\u606f&#xff1a;{str(e)}&#034;)<br \/>\n        exit(1)<\/p>\n<p>def load_documents_from_folder():<br \/>\n    &#034;&#034;&#034;\u4ece\u672c\u5730\u6587\u4ef6\u5939\u52a0\u8f7d\u6240\u6709txt\u6587\u6863&#xff0c;\u751f\u6210ES\u6279\u91cf\u5199\u5165\u6570\u636e&#xff0c;\u5b8c\u5168\u79bb\u7ebf&#034;&#034;&#034;<br \/>\n    if not os.path.exists(DATASET_FOLDER):<br \/>\n        print(f&#034;\u274c \u77e5\u8bc6\u5e93\u76ee\u5f55 {DATASET_FOLDER} \u4e0d\u5b58\u5728&#xff0c;\u8bf7\u5148\u521b\u5efa\u76ee\u5f55\u5e76\u653e\u5165txt\u6587\u6863&#034;)<br \/>\n        exit(1)<\/p>\n<p>    file_count &#061; 0<br \/>\n    for filename in os.listdir(DATASET_FOLDER):<br \/>\n        if filename.endswith(&#034;.txt&#034;):<br \/>\n            file_path &#061; os.path.join(DATASET_FOLDER, filename)<br \/>\n            # \u7528UTF-8\u7f16\u7801\u8bfb\u53d6&#xff0c;\u907f\u514d\u4e2d\u6587\u4e71\u7801<br \/>\n            with open(file_path, &#034;r&#034;, encoding&#061;&#034;utf-8&#034;) as f:<br \/>\n                file_content &#061; f.read()<\/p>\n<p>            yield {<br \/>\n                &#034;_index&#034;: INDEX_NAME,<br \/>\n                &#034;_source&#034;: {<br \/>\n                    &#034;file_name&#034;: filename,<br \/>\n                    &#034;file_content&#034;: file_content<br \/>\n                }<br \/>\n            }<br \/>\n            file_count &#043;&#061; 1<\/p>\n<p>    if file_count &#061;&#061; 0:<br \/>\n        print(f&#034;\u274c \u77e5\u8bc6\u5e93\u76ee\u5f55 {DATASET_FOLDER} \u4e2d\u6ca1\u6709\u627e\u5230\u4efb\u4f55txt\u6587\u6863&#xff0c;\u8bf7\u5148\u653e\u5165\u6587\u6863&#034;)<br \/>\n        exit(1)<br \/>\n    print(f&#034;&#x1f4c4; \u627e\u5230 {file_count} \u4e2a\u6587\u6863&#xff0c;\u51c6\u5907\u5bfc\u5165ES&#034;)<\/p>\n<p>def bulk_index_documents():<br \/>\n    &#034;&#034;&#034;\u6279\u91cf\u628a\u6587\u6863\u5bfc\u5165ES\u77e5\u8bc6\u5e93&#xff0c;\u4f7f\u7528bulk API\u63d0\u5347\u5bfc\u5165\u901f\u5ea6&#034;&#034;&#034;<br \/>\n    try:<br \/>\n        success_count, failed_count &#061; helpers.bulk(<br \/>\n            es_client,<br \/>\n            load_documents_from_folder()<br \/>\n        )<br \/>\n        if failed_count:<br \/>\n            print(f&#034;\u26a0\ufe0f  {failed_count} \u4e2a\u6587\u6863\u5bfc\u5165\u5931\u8d25&#034;)<br \/>\n        print(f&#034;\u2705 \u6210\u529f\u5bfc\u5165 {success_count} \u4e2a\u6587\u6863\u5230\u77e5\u8bc6\u5e93&#034;)<br \/>\n        return success_count<br \/>\n    except Exception as e:<br \/>\n        print(f&#034;\u274c \u6587\u6863\u5bfc\u5165\u5931\u8d25&#xff0c;\u9519\u8bef\u4fe1\u606f&#xff1a;{str(e)}&#034;)<br \/>\n        exit(1)<\/p>\n<p>def semantic_search(user_query, top_n&#061;3):<br \/>\n    &#034;&#034;&#034;ES\u539f\u751f\u8bed\u4e49\u68c0\u7d22&#xff0c;\u81ea\u52a8\u628a\u7528\u6237\u95ee\u9898\u8f6c\u6210\u5411\u91cf&#xff0c;\u5339\u914d\u6700\u76f8\u5173\u7684\u6587\u6863&#xff0c;\u5168\u7a0b\u79bb\u7ebf&#034;&#034;&#034;<br \/>\n    start_time &#061; time.time()<br \/>\n    # \u8bed\u4e49\u68c0\u7d22\u67e5\u8be2&#xff0c;\u4e00\u884c\u4ee3\u7801\u5b8c\u6210&#xff0c;\u65e0\u9700\u624b\u52a8\u751f\u6210\u5411\u91cf<br \/>\n    search_query &#061; {<br \/>\n        &#034;query&#034;: {<br \/>\n            &#034;semantic&#034;: {<br \/>\n                &#034;field&#034;: &#034;semantic_content&#034;,<br \/>\n                &#034;query&#034;: user_query<br \/>\n            }<br \/>\n        },<br \/>\n        &#034;size&#034;: top_n,<br \/>\n        &#034;_source&#034;: [&#034;file_name&#034;, &#034;file_content&#034;]<br \/>\n    }<\/p>\n<p>    response &#061; es_client.search(index&#061;INDEX_NAME, body&#061;search_query)<br \/>\n    search_latency &#061; (time.time() &#8211; start_time) * 1000  # \u8f6c\u6362\u4e3a\u6beb\u79d2<br \/>\n    return response[&#034;hits&#034;][&#034;hits&#034;], search_latency<\/p>\n<p>def call_local_llm(prompt):<br \/>\n    &#034;&#034;&#034;\u8c03\u7528\u672c\u5730\u79bb\u7ebf\u5927\u6a21\u578b\u751f\u6210\u7b54\u6848&#xff0c;\u5168\u7a0b\u65e0\u5916\u7f51\u8c03\u7528&#034;&#034;&#034;<br \/>\n    start_time &#061; time.time()<br \/>\n    try:<br \/>\n        response &#061; ai_client.chat.completions.create(<br \/>\n            model&#061;AI_MODEL_NAME,<br \/>\n            messages&#061;[{&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: prompt}],<br \/>\n            temperature&#061;0.3,  # RAG\u573a\u666f\u4f7f\u7528\u4f4e\u6e29\u5ea6&#xff0c;\u51cf\u5c11\u5e7b\u89c9&#xff0c;\u786e\u4fdd\u7b54\u6848\u4ec5\u6765\u81ea\u6587\u6863<br \/>\n            stream&#061;False<br \/>\n        )<br \/>\n        # \u8ba1\u7b97\u8017\u65f6\u548c\u751f\u6210\u901f\u5ea6<br \/>\n        llm_latency &#061; (time.time() &#8211; start_time) * 1000<br \/>\n        answer &#061; response.choices[0].message.content<br \/>\n        tokens_per_second &#061; 0<\/p>\n<p>        # \u8ba1\u7b97token\u751f\u6210\u901f\u5ea6<br \/>\n        if hasattr(response, &#034;usage&#034;) and response.usage:<br \/>\n            completion_tokens &#061; response.usage.completion_tokens<br \/>\n            if llm_latency &gt; 0:<br \/>\n                tokens_per_second &#061; (completion_tokens \/ llm_latency) * 1000<\/p>\n<p>        return answer, llm_latency, tokens_per_second<br \/>\n    except Exception as e:<br \/>\n        llm_latency &#061; (time.time() &#8211; start_time) * 1000<br \/>\n        return f&#034;\u5927\u6a21\u578b\u8c03\u7528\u5931\u8d25&#xff0c;\u9519\u8bef\u4fe1\u606f&#xff1a;{str(e)}&#034;, llm_latency, 0<\/p>\n<p>def build_rag_prompt(user_query, search_results):<br \/>\n    &#034;&#034;&#034;\u6784\u5efaRAG\u63d0\u793a\u8bcd&#xff0c;\u5f3a\u5236\u5927\u6a21\u578b\u4ec5\u4f7f\u7528\u68c0\u7d22\u5230\u7684\u6587\u6863\u5185\u5bb9&#xff0c;\u51cf\u5c11\u5e7b\u89c9&#xff0c;\u5e26\u5f15\u6587\u6807\u6ce8&#034;&#034;&#034;<br \/>\n    context &#061; &#034;&#034;<br \/>\n    citations &#061; []<br \/>\n    for idx, hit in enumerate(search_results, 1):<br \/>\n        source &#061; hit[&#034;_source&#034;]<br \/>\n        context &#043;&#061; f&#034;[{idx}] \u6587\u6863\u540d\u79f0&#xff1a;{source[&#039;file_name&#039;]}\\\\n\u6587\u6863\u5185\u5bb9&#xff1a;{source[&#039;file_content&#039;]}\\\\n\\\\n&#034;<br \/>\n        citations.append(f&#034;[{idx}] {source[&#039;file_name&#039;]}&#034;)<\/p>\n<p>    # \u4e2d\u6587\u63d0\u793a\u8bcd&#xff0c;\u9002\u914d\u4e2d\u6587\u5927\u6a21\u578b&#xff0c;\u660e\u786e\u89c4\u5219\u51cf\u5c11\u5e7b\u89c9<br \/>\n    prompt &#061; f&#034;&#034;&#034;<br \/>\n    \u8bf7\u4e25\u683c\u57fa\u4e8e\u4e0b\u9762\u63d0\u4f9b\u7684\u53c2\u8003\u6587\u6863&#xff0c;\u56de\u7b54\u7528\u6237\u7684\u95ee\u9898&#xff0c;\u5fc5\u987b\u9075\u5b88\u4ee5\u4e0b\u89c4\u5219&#xff1a;<br \/>\n    1. \u53ea\u4f7f\u7528\u53c2\u8003\u6587\u6863\u91cc\u7684\u5185\u5bb9\u56de\u7b54\u95ee\u9898&#xff0c;\u7edd\u5bf9\u4e0d\u80fd\u7f16\u9020\u53c2\u8003\u6587\u6863\u91cc\u6ca1\u6709\u7684\u4fe1\u606f<br \/>\n    2. \u6bcf\u5f15\u7528\u4e00\u53e5\u53c2\u8003\u6587\u6863\u7684\u5185\u5bb9&#xff0c;\u5fc5\u987b\u5728\u540e\u9762\u6807\u6ce8\u6765\u6e90&#xff0c;\u683c\u5f0f\u4e3a [1][2] \u8fd9\u6837\u7684\u7f16\u53f7<br \/>\n    3. \u56de\u7b54\u6761\u7406\u6e05\u6670&#xff0c;\u5206\u70b9\u8bf4\u660e\u6838\u5fc3\u5185\u5bb9&#xff0c;\u8bed\u8a00\u7b80\u6d01\u51c6\u786e<br \/>\n    4. \u5982\u679c\u53c2\u8003\u6587\u6863\u91cc\u6ca1\u6709\u548c\u95ee\u9898\u76f8\u5173\u7684\u5185\u5bb9&#xff0c;\u76f4\u63a5\u56de\u7b54\u201c\u672a\u5728\u77e5\u8bc6\u5e93\u4e2d\u627e\u5230\u76f8\u5173\u4fe1\u606f\u201d<\/p>\n<p>    \u53c2\u8003\u6587\u6863&#xff1a;<br \/>\n    {context}<\/p>\n<p>    \u7528\u6237\u95ee\u9898&#xff1a;{user_query}<br \/>\n    &#034;&#034;&#034;<br \/>\n    return prompt, citations<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    print(&#034;&#061;&#034;*60)<br \/>\n    print(&#034;&#x1f680; \u3010\u5b8c\u5168\u79bb\u7ebf\u7248\u3011RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u52a9\u624b \u542f\u52a8&#034;)<br \/>\n    print(&#034;&#061;&#034;*60)<\/p>\n<p>    # 1. \u68c0\u67e5ES\u8fde\u63a5<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; 1. \u68c0\u67e5Elasticsearch\u8fde\u63a5 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\n    check_es_connect()<\/p>\n<p>    # 2. \u521b\u5efa\u79bb\u7ebf\u5d4c\u5165\u63a8\u7406\u7aef\u70b9<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; 2. \u521d\u59cb\u5316\u79bb\u7ebf\u5d4c\u5165\u6a21\u578b &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\n    setup_embedding_inference()<\/p>\n<p>    # 3. \u521b\u5efa\u77e5\u8bc6\u5e93\u7d22\u5f15<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; 3. \u521d\u59cb\u5316\u77e5\u8bc6\u5e93\u7d22\u5f15 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\n    is_new_index &#061; setup_knowledge_index()<\/p>\n<p>    # 4. \u65b0\u521b\u5efa\u7684\u7d22\u5f15\u81ea\u52a8\u5bfc\u5165\u6587\u6863<br \/>\n    if is_new_index:<br \/>\n        print(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; 4. \u5bfc\u5165\u77e5\u8bc6\u5e93\u6587\u6863 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\n        import_count &#061; bulk_index_documents()<br \/>\n        if import_count &#061;&#061; 0:<br \/>\n            exit(1)<br \/>\n        time.sleep(1)  # \u7b49\u5f85\u7d22\u5f15\u5237\u65b0&#xff0c;\u786e\u4fdd\u6587\u6863\u53ef\u88ab\u68c0\u7d22<\/p>\n<p>    # 5. \u6267\u884cRAG\u95ee\u7b54<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061;&#061;&#061; 5. \u6267\u884cRAG\u667a\u80fd\u95ee\u7b54 &#061;&#061;&#061;&#061;&#061;&#034;)<br \/>\n    # \u6b64\u5904\u53ef\u4fee\u6539\u4e3a\u4f60\u8981\u63d0\u95ee\u7684\u95ee\u9898&#xff0c;\u652f\u6301\u4e2d\u6587<br \/>\n    USER_QUESTION &#061; &#034;\u8bf7\u603b\u7ed3API\u5b58\u5728\u7684\u6027\u80fd\u95ee\u9898&#034;<br \/>\n    print(f&#034;&#x1f50d; \u7528\u6237\u95ee\u9898&#xff1a;{USER_QUESTION}&#034;)<\/p>\n<p>    # \u8bed\u4e49\u68c0\u7d22<br \/>\n    search_results, search_latency &#061; semantic_search(USER_QUESTION, top_n&#061;3)<br \/>\n    if not search_results:<br \/>\n        print(&#034;\u274c \u672a\u5728\u77e5\u8bc6\u5e93\u4e2d\u627e\u5230\u76f8\u5173\u6587\u6863&#034;)<br \/>\n        exit(0)<br \/>\n    print(f&#034;\u2705 \u627e\u5230 {len(search_results)} \u4e2a\u76f8\u5173\u6587\u6863&#xff0c;\u68c0\u7d22\u8017\u65f6&#xff1a;{search_latency:.0f}ms&#034;)<\/p>\n<p>    # \u6784\u5efaRAG\u63d0\u793a\u8bcd<br \/>\n    rag_prompt, citations &#061; build_rag_prompt(USER_QUESTION, search_results)<\/p>\n<p>    # \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u7b54\u6848<br \/>\n    print(f&#034;\\\\n&#x1f916; \u6b63\u5728\u8c03\u7528\u672c\u5730\u5927\u6a21\u578b {AI_MODEL_NAME} \u751f\u6210\u7b54\u6848&#8230;&#034;)<br \/>\n    answer, llm_latency, tokens_per_second &#061; call_local_llm(rag_prompt)<\/p>\n<p>    # \u8f93\u51fa\u6700\u7ec8\u7ed3\u679c<br \/>\n    print(&#034;\\\\n&#034; &#043; &#034;&#061;&#034;*60)<br \/>\n    print(f&#034;&#x1f4a1; \u95ee\u9898&#xff1a;{USER_QUESTION}&#034;)<br \/>\n    print(f&#034;&#x1f4dd; \u7b54\u6848&#xff1a;\\\\n{answer}&#034;)<br \/>\n    print(&#034;\\\\n&#x1f4da; \u5f15\u7528\u6765\u6e90&#xff1a;&#034;)<br \/>\n    for cite in citations:<br \/>\n        print(f&#034;  {cite}&#034;)<br \/>\n    print(&#034;\\\\n&#034; &#043; &#034;&#061;&#034;*60)<br \/>\n    print(f&#034;&#x1f50d; \u8bed\u4e49\u68c0\u7d22\u8017\u65f6&#xff1a;{search_latency:.0f}ms&#034;)<br \/>\n    print(f&#034;&#x1f916; \u5927\u6a21\u578b\u751f\u6210\u8017\u65f6&#xff1a;{llm_latency:.0f}ms | \u751f\u6210\u901f\u5ea6&#xff1a;{tokens_per_second:.1f} tokens\/s&#034;)<br \/>\n    print(&#034;\u2705 \u79bb\u7ebfRAG\u95ee\u7b54\u6267\u884c\u5b8c\u6210&#034;)<\/p>\n<h4>6.4 \u8fd0\u884c\u811a\u672c<\/h4>\n<p># \u8fdb\u5165\u811a\u672c\u6240\u5728\u76ee\u5f55<br \/>\ncd \/opt\/rag-offline\/<br \/>\n# \u8fd0\u884c\u811a\u672c<br \/>\npython3 rag_offline.py<\/p>\n<h5>\u3010\u6210\u529f\u6821\u9a8c\u6807\u51c6\u3011<\/h5>\n<p>\u811a\u672c\u6b63\u5e38\u6267\u884c&#xff0c;\u8f93\u51fa\u6700\u7ec8\u7684\u7b54\u6848\u3001\u5f15\u7528\u6765\u6e90\u548c\u6027\u80fd\u6570\u636e&#xff0c;\u65e0\u62a5\u9519&#xff0c;\u8bf4\u660e\u6574\u4e2a\u79bb\u7ebfRAG\u7cfb\u7edf\u90e8\u7f72\u6210\u529f&#xff01;<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u79bb\u7ebf\u73af\u5883\u5e38\u89c1\u62a5\u9519\u4e0e\u7ec8\u6781\u89e3\u51b3\u65b9\u6848<\/h3>\n<table>\n<tr>\u62a5\u9519\u73b0\u8c61\u6839\u56e0\u5206\u6790\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>ES\u5bb9\u5668\u542f\u52a8\u540e&#xff0c;STATUS\u4e00\u76f4\u663e\u793aunhealthy<\/td>\n<td>\u76ee\u5f55\u6743\u9650\u4e0d\u8db3&#xff0c;ES\u5bb9\u5668\u5185\u90e8\u7528\u6237\u65e0\u6cd5\u8bfb\u5199\u5bbf\u4e3b\u673a\u76ee\u5f55<\/td>\n<td>\u6267\u884cchmod -R 777 \/opt\/rag-offline\/es\/&#xff0c;\u91cd\u542f\u5bb9\u5668<\/td>\n<\/tr>\n<tr>\n<td>ES\u6a21\u578b\u52a0\u8f7d\u5931\u8d25&#xff0c;\u62a5\u9519model not found<\/td>\n<td>\u6a21\u578b\u6587\u4ef6\u672a\u653e\u5165\u6b63\u786e\u76ee\u5f55&#xff0c;\u6216\u6743\u9650\u4e0d\u8db3<\/td>\n<td>\u786e\u4fdd\u6a21\u578b\u6587\u4ef6\u89e3\u538b\u5230\/opt\/rag-offline\/es\/models\/\u76ee\u5f55&#xff0c;\u8d4b777\u6743\u9650&#xff0c;\u91cd\u542fES<\/td>\n<\/tr>\n<tr>\n<td>LocalAI\u8c03\u7528\u62a5\u9519model not found<\/td>\n<td>\u5927\u6a21\u578b\u6587\u4ef6\u540d\u548c\u811a\u672c\u91cc\u7684AI_MODEL_NAME\u4e0d\u4e00\u81f4&#xff0c;\u6216\u672a\u653e\u5165\u6b63\u786e\u76ee\u5f55<\/td>\n<td>\u68c0\u67e5\u6587\u4ef6\u540d&#xff0c;\u5fc5\u987b\u5b8c\u5168\u4e00\u81f4&#xff08;\u5305\u62ec.gguf\u540e\u7f00&#xff09;&#xff0c;\u653e\u5165\/opt\/rag-offline\/localai\/models\/\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td>\u811a\u672c\u6267\u884c\u62a5\u9519ES\u8fde\u63a5\u5931\u8d25<\/td>\n<td>API\u5bc6\u94a5\u9519\u8bef\u3001ES\u670d\u52a1\u672a\u542f\u52a8\u3001\u7aef\u53e3\u88ab\u5360\u7528<\/td>\n<td>\u68c0\u67e5ES\u5bb9\u5668\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3001API\u5bc6\u94a5\u662f\u5426\u6b63\u786e\u30019200\u7aef\u53e3\u662f\u5426\u88ab\u5360\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u6587\u6587\u6863\u4e71\u7801<\/td>\n<td>\u6587\u6863\u975eUTF-8\u7f16\u7801&#xff0c;\u6216\u8bfb\u53d6\u65f6\u672a\u6307\u5b9a\u7f16\u7801<\/td>\n<td>\u7528\u8bb0\u4e8b\u672c\u6253\u5f00\u6587\u6863&#xff0c;\u53e6\u5b58\u4e3aUTF-8\u7f16\u7801&#xff0c;\u811a\u672c\u5df2\u6307\u5b9aencoding&#061;\u201cutf-8\u201d<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u6a21\u578b\u751f\u6210\u7684\u7b54\u6848\u4e0e\u6587\u6863\u65e0\u5173\u3001\u51ed\u7a7a\u7f16\u9020<\/td>\n<td>\u6e29\u5ea6\u8bbe\u7f6e\u8fc7\u9ad8&#xff0c;\u6216\u63d0\u793a\u8bcd\u65e0\u6709\u6548\u7ea6\u675f<\/td>\n<td>\u5c06temperature\u6539\u4e3a0.1~0.3&#xff0c;\u786e\u4fdd\u63d0\u793a\u8bcd\u660e\u786e\u8981\u6c42\u4ec5\u4f7f\u7528\u53c2\u8003\u6587\u6863\u5185\u5bb9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516b\u3001\u79bb\u7ebf\u73af\u5883\u8fdb\u9636\u4f18\u5316<\/h3>\n<li>\n<p>\u591a\u683c\u5f0f\u6587\u6863\u652f\u6301&#xff1a;\u6269\u5c55\u811a\u672c&#xff0c;\u652f\u6301PDF\u3001Word\u3001Excel\u7b49\u683c\u5f0f&#xff0c;\u901a\u8fc7PyPDF2\u3001python-docx\u7b49\u5e93\u7684\u79bb\u7ebfwhl\u5305\u5b89\u88c5&#xff0c;\u63d0\u53d6\u6587\u672c\u540e\u5bfc\u5165ES<\/p>\n<\/li>\n<li>\n<p>Web\u53ef\u89c6\u5316\u754c\u9762&#xff1a;\u901a\u8fc7Streamlit\u79bb\u7ebf\u90e8\u7f72\u53ef\u89c6\u5316\u754c\u9762&#xff0c;\u5b9e\u73b0\u6587\u6863\u4e0a\u4f20\u3001\u95ee\u7b54\u4ea4\u4e92\u3001\u68c0\u7d22\u7ed3\u679c\u67e5\u770b&#xff0c;\u5168\u7a0b\u65e0\u5916\u7f51\u4f9d\u8d56<\/p>\n<\/li>\n<li>\n<p>\u589e\u91cf\u6587\u6863\u66f4\u65b0&#xff1a;\u589e\u52a0\u589e\u91cf\u5bfc\u5165\u903b\u8f91&#xff0c;\u4ec5\u5bfc\u5165\u65b0\u589e\/\u4fee\u6539\u7684\u6587\u6863&#xff0c;\u65e0\u9700\u6bcf\u6b21\u5168\u91cf\u91cd\u65b0\u5bfc\u5165<\/p>\n<\/li>\n<li>\n<p>\u591a\u7528\u6237\u6743\u9650\u63a7\u5236&#xff1a;\u57fa\u4e8eES\u7684\u89d2\u8272\u6743\u9650\u4f53\u7cfb&#xff0c;\u7ed9\u4e0d\u540c\u7528\u6237\u5206\u914d\u4e0d\u540c\u7684\u77e5\u8bc6\u5e93\u8bbf\u95ee\u6743\u9650&#xff0c;\u7b26\u5408\u4f01\u4e1a\u5185\u7f51\u5408\u89c4\u8981\u6c42<\/p>\n<\/li>\n<li>\n<p>\u5927\u6a21\u578b\u6027\u80fd\u4f18\u5316&#xff1a;\u5f00\u542fCPU\u52a0\u901f\u5e93&#xff08;OpenBLAS\/MKL&#xff09;&#xff0c;\u53ef\u63d0\u5347\u5927\u6a21\u578b\u751f\u6210\u901f\u5ea630%\u4ee5\u4e0a&#xff0c;\u9002\u914d\u66f4\u9ad8\u914d\u7f6e\u7684\u670d\u52a1\u5668<\/p>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0<br \/>\n\u6838\u5fc3\u539f\u7406&#xff1a;3\u4e2a\u89d2\u8272\u7ec4\u6210\u4f60\u7684\u79bb\u7ebf\u79c1\u4eba\u77e5\u8bc6\u5e93<br \/>\n\u6211\u4eec\u8981\u642d\u7684\u7cfb\u7edf&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u5b8c\u5168\u88c5\u5728\u4f60\u7535\u8111\u91cc\u3001\u4e0d\u8054\u7f51\u7684\u79c1\u4eba\u667a\u5e93&#xff0c;3\u4e2a\u6838\u5fc3\u89d2\u8272\u5206\u5de5\u660e\u786e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u9700\u8981\u8fde\u5916\u7f51&#xff1a; \u300c\u56fe\u4e66\u7ba1\u7406\u5458\u300dElasticsearch 9.x&#xff1a;\u4f60\u7684\u79c1\u4eba\u6587\u6863\u56fe\u4e66\u9986 \u5b58\u50a8\u6240\u6709\u6587\u6863&#xff08;\u4f1a\u8bae\u7eaa\u8981\u3001\u62a5\u544a\u3001\u5236\u5ea6\u6587\u4ef6\u7b49&#xff09;  \u81ea\u52a8\u7ed9\u6bcf\u6bb5\u8bdd\u751f\u6210\u300c\u8bed\u4e49\u6807\u7b7e\u300d&#xff08;\u5411\u91cf&#xff09;&#xff0c;\u4e0d\u662f<\/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":[1299,323,2215],"topic":[],"class_list":["post-78491","post","type-post","status-publish","format-standard","hentry","category-server","tag-elasticsearch","tag-323","tag-2215"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \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\/78491.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u6982\u8ff0 \u6838\u5fc3\u539f\u7406&#xff1a;3\u4e2a\u89d2\u8272\u7ec4\u6210\u4f60\u7684\u79bb\u7ebf\u79c1\u4eba\u77e5\u8bc6\u5e93 \u6211\u4eec\u8981\u642d\u7684\u7cfb\u7edf&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u5b8c\u5168\u88c5\u5728\u4f60\u7535\u8111\u91cc\u3001\u4e0d\u8054\u7f51\u7684\u79c1\u4eba\u667a\u5e93&#xff0c;3\u4e2a\u6838\u5fc3\u89d2\u8272\u5206\u5de5\u660e\u786e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u9700\u8981\u8fde\u5916\u7f51&#xff1a; \u300c\u56fe\u4e66\u7ba1\u7406\u5458\u300dElasticsearch 9.x&#xff1a;\u4f60\u7684\u79c1\u4eba\u6587\u6863\u56fe\u4e66\u9986 \u5b58\u50a8\u6240\u6709\u6587\u6863&#xff08;\u4f1a\u8bae\u7eaa\u8981\u3001\u62a5\u544a\u3001\u5236\u5ea6\u6587\u4ef6\u7b49&#xff09; \u81ea\u52a8\u7ed9\u6bcf\u6bb5\u8bdd\u751f\u6210\u300c\u8bed\u4e49\u6807\u7b7e\u300d&#xff08;\u5411\u91cf&#xff09;&#xff0c;\u4e0d\u662f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78491.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-27T10:05:56+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=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78491.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78491.html\",\"name\":\"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-27T10:05:56+00:00\",\"dateModified\":\"2026-02-27T10:05:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78491.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78491.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78491.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd\"}]},{\"@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":"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \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\/78491.html","og_locale":"zh_CN","og_type":"article","og_title":"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u6982\u8ff0 \u6838\u5fc3\u539f\u7406&#xff1a;3\u4e2a\u89d2\u8272\u7ec4\u6210\u4f60\u7684\u79bb\u7ebf\u79c1\u4eba\u77e5\u8bc6\u5e93 \u6211\u4eec\u8981\u642d\u7684\u7cfb\u7edf&#xff0c;\u5c31\u50cf\u4e00\u4e2a\u5b8c\u5168\u88c5\u5728\u4f60\u7535\u8111\u91cc\u3001\u4e0d\u8054\u7f51\u7684\u79c1\u4eba\u667a\u5e93&#xff0c;3\u4e2a\u6838\u5fc3\u89d2\u8272\u5206\u5de5\u660e\u786e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u73af\u8282\u9700\u8981\u8fde\u5916\u7f51&#xff1a; \u300c\u56fe\u4e66\u7ba1\u7406\u5458\u300dElasticsearch 9.x&#xff1a;\u4f60\u7684\u79c1\u4eba\u6587\u6863\u56fe\u4e66\u9986 \u5b58\u50a8\u6240\u6709\u6587\u6863&#xff08;\u4f1a\u8bae\u7eaa\u8981\u3001\u62a5\u544a\u3001\u5236\u5ea6\u6587\u4ef6\u7b49&#xff09; \u81ea\u52a8\u7ed9\u6bcf\u6bb5\u8bdd\u751f\u6210\u300c\u8bed\u4e49\u6807\u7b7e\u300d&#xff08;\u5411\u91cf&#xff09;&#xff0c;\u4e0d\u662f","og_url":"https:\/\/www.wsisp.com\/helps\/78491.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-27T10:05:56+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78491.html","url":"https:\/\/www.wsisp.com\/helps\/78491.html","name":"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-27T10:05:56+00:00","dateModified":"2026-02-27T10:05:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78491.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78491.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78491.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Elasticsearch 9.x \u672c\u5730RAG\u4e2a\u4eba\u77e5\u8bc6\u5e93\u5b9e\u64cd"}]},{"@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\/78491","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=78491"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78491\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78491"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}