{"id":38402,"date":"2025-05-20T09:18:47","date_gmt":"2025-05-20T01:18:47","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38402.html"},"modified":"2025-05-20T09:18:47","modified_gmt":"2025-05-20T01:18:47","slug":"2025-5-18","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38402.html","title":{"rendered":"2025\/5\/18"},"content":{"rendered":"<p>\u7ee7\u7eed\u7814\u7a76\u4e00\u4e0b\u5927\u4f6c\u7684RAG\u9879\u76ee\u3002\u5f00\u59cb\u6211\u7684\u788e\u788e\u5ff5\u3002<\/p>\n<p>RAG\u53ef\u4ee5\u5206\u6210\u4e24\u90e8\u5206&#xff1a;\u4e00\u4e2a\u662f\u95ee\u7b54&#xff0c;\u4e00\u4e2a\u662f\u6570\u636e\u5904\u7406\u3002<\/p>\n<p>\u95ee\u7b54\u662f\u4eba\u63d0\u95ee&#xff0c;\u7136\u540e\u67e5\u6570\u636e\u5e93&#xff0c;\u628a\u67e5\u7684\u4e1c\u897f\u7528\u5927\u6a21\u578b\u7ec4\u7ec7\u6210\u4eba\u8bdd&#xff0c;\u56de\u7b54\u4eba\u7684\u63d0\u95ee\u3002<\/p>\n<p>\u6570\u636e\u5904\u7406\u662f\u628a\u5f53\u4e0b\u77e5\u8bc6\u5e93\u91cc\u7684\u4e1c\u897f&#xff08;\u4e0d\u7ba1\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e&#xff09;&#xff0c;\u5168\u5f04\u6210\u8ba1\u7b97\u673a\u8bdd&#xff08;\u4ee3\u7801\u80fd\u660e\u767d\u7684\u683c\u5f0f&#xff09;\u5b58\u5230\u6570\u636e\u5e93&#xff0c;\u7136\u540e\u65b9\u4fbf\u4eba\u63d0\u95ee\u7684\u65f6\u5019&#xff08;\u4e5f\u5c31\u662f\u95ee\u7b54&#xff09;\u7ed9\u51fa\u53ef\u4ee5\u56de\u7b54\u7684\u77e5\u8bc6\u3002<\/p>\n<p>\u5982\u679c\u60f3\u8ba9\u9879\u76ee\u8dd1\u8d77\u6765&#xff0c;\u5fc5\u987b\u628aES\u670d\u52a1\u542f\u52a8\u8d77\u6765&#xff0c;\u8be5\u9879\u76ee\u662f\u7528ES\u5b58\u7684\u6570\u636e\u3002<\/p>\n<p>\u9879\u76ee\u542f\u52a8\u65f6&#xff0c;\u4f1a\u5148\u8fd0\u884cLoadStartup&#xff08;\u5728Springboot\u5e94\u7528\u542f\u52a8\u65f6&#xff09;&#xff0c;\u521d\u59cb\u5316\u5411\u91cf\u5b58\u50a8&#xff08;\u5177\u4f53\u521d\u59cb\u5316\u5411\u91cf\u5b58\u50a8\u7528vectorstorage\u7684initCollection()\u65b9\u6cd5&#xff0c;\u6307\u5b9a\u540d\u79f0\u548c\u7ef4\u5ea6&#xff0c;\u5411\u91cf\u7ef4\u5ea6\u662f1024\u4e3a\u4e86\u9002\u914d\u667a\u8c31AI&#xff09;\u3002\u603b\u4e4b\u5c31\u662f\u81ea\u52a8\u521d\u59cb\u5316\u4e00\u4e2a\u5411\u91cf\u6570\u636e\u5e93\u7684\u96c6\u5408&#xff08;Collection&#xff09;&#xff0c;\u7528\u4e8e\u5b58\u50a8\u540e\u7eed\u7684\u5411\u91cf\u6570\u636e&#xff08;\u5982\u6587\u672c\u5d4c\u5165\u5411\u91cf&#xff09;\u3002<\/p>\n<p>\u6211\u4eec\u770b\u5230LoadStartup\u7c7b\u6709\u4e00\u4e2a\u6ce8\u89e3&#064;Component<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"926\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011834-682bd86a757af.png\" width=\"1744\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"327\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011835-682bd86b19aaf.png\" width=\"1610\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"876\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011835-682bd86b5454e.png\" width=\"1847\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"657\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011835-682bd86be1bd5.png\" width=\"1923\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"785\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011836-682bd86c5d49b.png\" width=\"1841\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"663\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011836-682bd86cdae6e.png\" width=\"1676\" \/><\/p>\n<p>\u6240\u4ee5&#064;Service\u3001&#064;Repository\u7b49\u7b49\u8fd9\u4e9b\u6ce8\u89e3&#xff0c;\u672c\u8d28\u4e0a\u90fd\u662f&#064;Component\u3002\u53ea\u662f\u6839\u636e\u5c42\u6b21\u6709\u4e0d\u540c\u53eb\u6cd5\u3002<\/p>\n<p>\u8fd9\u4e2acollection\u662f\u68ee\u9a6c\u6837\u5b50&#xff1f;\u56de\u5934\u518d\u5199\u5427\u3002<\/p>\n<hr \/>\n<p>\u9996\u5148&#xff0c;\u5c31\u662f\u8f93\u5165\u7684\u95ee\u9898\u3002\u6211\u4eec\u8981\u5b58\u7684\u77e5\u8bc6\u4e0d\u4e00\u5b9a\u662f\u4ec0\u4e48\u7c7b\u578b&#xff0c;\u53ef\u80fd\u4f7ftxt&#xff0c;\u53ef\u80fd\u662fword&#xff0c;\u751a\u81f3\u662fpdf\u3002\u90a3\u6211\u4eec\u5c31\u9700\u8981\u628a\u8f93\u5165\u7684\u4e1c\u897f\u5148\u53d8\u6210\u6587\u672c\u3002<\/p>\n<p>\u9879\u76ee\u8fd0\u884c\u8d77\u6765\u4e4b\u524d&#xff0c;\u70b9\u51fb\u8fd0\u884c\u4e0b\u8f7d\u597d\u7684es\u7684bin\u6587\u4ef6\u5939\u4e0belasticsearch.bat&#xff0c;\u542f\u52a8\u670d\u52a1\u3002<\/p>\n<p>\u6b64\u65f6\u53ef\u4ee5\u518d\u7ec8\u7aef\u770b\u5230\u53ef\u4ea4\u4e92\u7684shell\u547d\u4ee4\u884c\u3002\u8fd9\u4e2a\u5e94\u8be5\u662f\u901a\u8fc7spring shell\u5de5\u5177\u5305\u5b9e\u73b0\u7684&#xff0c;\u9879\u76ee\u7684pom.xml\u6587\u4ef6\u91cc\u53ef\u4ee5\u770b\u5230\u5df2\u7ecf\u914d\u7f6e\u4e86shell\u7684\u8d77\u6b65\u4f9d\u8d56\u3002\u600e\u4e48\u7528\u8fd9\u4e2ashell\u5305\u5462&#xff1f;\u53ef\u4ee5\u901a\u8fc7\u81ea\u5df1\u7f16\u5199java\u7c7b&#xff0c;\u81ea\u5df1\u505a\u547d\u4ee4\u3002\u524d\u9762\u8bf4\u8fc7\u628aRAG\u5206\u6210\u4e24\u90e8\u5206&#xff1a;\u95ee\u7b54&#xff0c;\u6570\u636e\u5904\u7406\u3002\u4f7f\u7528add\u547d\u4ee4\u5b8c\u6210\u6570\u636e\u5904\u7406\u90e8\u5206\u7684\u5de5\u4f5c&#xff0c;\u4f7f\u7528chat\u547d\u4ee4\u5b8c\u6210\u95ee\u7b54\u90e8\u5206\u7684\u5de5\u4f5c\u3002\u65b0\u5efacommand\u6587\u4ef6\u5939\u6765\u5b58\u653e\u8fd9\u4e24\u4e2a\u7c7b&#xff1a;add\u547d\u4ee4\u7c7b&#xff0c;chat\u547d\u4ee4\u7c7b\u3002<\/p>\n<p>\u901a\u8fc7 &#064;ShellMethod \u6ce8\u89e3\u5c06 Java \u65b9\u6cd5\u66b4\u9732\u4e3a Shell \u547d\u4ee4\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"612\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011837-682bd86d5d68b.png\" width=\"1329\" \/><\/p>\n<p>&#064;ShellMethod(value &#061; &#034;add local txt data&#034;)  \/\/ \u58f0\u660e\u8fd9\u662f\u4e00\u4e2aShell\u547d\u4ee4&#xff0c;\u63cf\u8ff0\u4e3a&#034;add local txt data&#034;<br \/>\npublic String add(String doc) {            \/\/ \u5b9a\u4e49\u547d\u4ee4\u65b9\u6cd5&#xff0c;\u63a5\u6536\u4e00\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570doc&#xff08;\u6587\u4ef6\u8def\u5f84\u6216\u6587\u672c\u5185\u5bb9&#xff09;<br \/>\n    log.info(&#034;start add doc.&#034;);            \/\/ \u6253\u5370\u65e5\u5fd7&#xff1a;\u5f00\u59cb\u5904\u7406\u6587\u6863<\/p>\n<p>    \/\/ 1. \u6587\u672c\u5206\u5757&#xff08;Chunking&#xff09;<br \/>\n    List&lt;ChunkResult&gt; chunkResults &#061; txtChunk.chunk(doc);  \/\/ \u8c03\u7528\u5206\u5757\u5de5\u5177&#xff0c;\u5c06\u6587\u6863\u62c6\u5206\u4e3a\u591a\u4e2a\u6587\u672c\u5757<\/p>\n<p>    \/\/ 2. \u5411\u91cf\u5316&#xff08;Embedding&#xff09;<br \/>\n    List&lt;EmbeddingResult&gt; embeddingResults &#061; zhipuAI.embedding(chunkResults);  \/\/ \u4f7f\u7528\u667a\u8c31AI&#xff08;\u6216\u5176\u4ed6\u6a21\u578b&#xff09;\u5c06\u6587\u672c\u5757\u8f6c\u4e3a\u5411\u91cf<\/p>\n<p>    \/\/ 3. \u5411\u91cf\u5b58\u50a8<br \/>\n    String collection &#061; vectorStorage.getCollectionName();  \/\/ \u83b7\u53d6\u5411\u91cf\u6570\u636e\u5e93\u7684\u96c6\u5408\u540d&#xff08;\u7c7b\u4f3c\u8868\u540d&#xff09;<br \/>\n    vectorStorage.store(collection, embeddingResults);     \/\/ \u5c06\u5411\u91cf\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d<\/p>\n<p>    log.info(&#034;finished&#034;);                  \/\/ \u6253\u5370\u65e5\u5fd7&#xff1a;\u5904\u7406\u5b8c\u6210<br \/>\n    return &#034;finished docId:{}&#034; &#043; doc;      \/\/ \u8fd4\u56de\u5904\u7406\u7ed3\u679c&#xff08;\u683c\u5f0f\u6709\u8bef&#xff0c;\u5e94\u4e3aString.format&#xff09;<br \/>\n} <\/p>\n<p>\u6570\u636e\u5904\u7406\u7684\u4e09\u6b65&#xff1a;\u6587\u672c\u5206\u5757\u3001\u5411\u91cf\u5316\u3001\u5411\u91cf\u5b58\u50a8\u3002\u6700\u540e\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<p>\u8fd9\u51e0\u6b65\u5168\u8c03\u7528\u65b9\u6cd5&#xff0c;\u73b0\u5728\u770b\u662f\u4e00\u4e2a\u9ed1\u76d2&#xff0c;\u77e5\u9053\u8f93\u5165\u8f93\u51fa\u548c\u529f\u80fd\u5c31\u884c&#xff0c;\u540e\u9762\u518d\u5177\u4f53\u770b\u9ed1\u76d2\u91cc\u9762\u7684\u4ee3\u7801\u3002<\/p>\n<p>doc\u53c2\u6570\u662f\u6587\u4ef6\u5185\u5bb9\u8fd8\u662f\u6587\u4ef6\u8def\u5f84\u641e\u4e0d\u61c2&#xff1f;\u8bd5\u7740\u8f93\u51fa\u4e86doc&#xff0c;\u53d1\u73b0\u662f\u6587\u4ef6\u540d\u3002\u4f46\u662f&#xff0c;\u6839\u636e\u6587\u4ef6\u540d\u5c31\u80fd\u627e\u7740&#xff1f;&#xff1f;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"48\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011837-682bd86da012a.png\" width=\"2165\" \/><\/p>\n<p>\u53d1\u73b0\u6709\u4e00\u4e2a\u9ed8\u8ba4\u8def\u5f84\/data&#xff0c;\u7136\u540e\u518d\u9ed8\u8ba4\u8def\u5f84\/data\u4e0b\u627edoc\u6587\u4ef6\u540d\u3002\u627e\u4e00\u4e0b\u54ea\u91cc\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u8def\u5f84\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"268\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011837-682bd86db8fcf.png\" width=\"1270\" \/><\/p>\n<p>\/data\u5728chunk\u8fd9\u91cc\u3002<\/p>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u610f\u601d\u662f&#xff0c;add \u6587\u4ef6\u540d\u3002add\u8fd9\u4e2a\u65b9\u6cd5\u5c31\u6536\u5230\u4e86\u53c2\u6570doc\u6587\u4ef6\u540d\u3002\u7136\u540e\u8fdb\u884c\u6587\u672c\u5206\u5757&#xff08;\u6570\u636e\u5904\u7406\u7684\u5177\u4f53\u4ee3\u7801\u653e\u5728\/compoents\u6587\u4ef6\u5939&#xff09;&#xff0c;\u8c03\u7528\u4e86chunk\u65b9\u6cd5&#xff0c;\u7136\u540e\u6839\u636e\u9ed8\u8ba4\u8def\u5f84&#043;\u6587\u4ef6\u540d&#043;.txt&#xff0c;\u5c31\u5f97\u5230\u4e00\u6761\u5b8c\u6574\u7684\u8def\u5f84&#xff08;\u76f8\u5bf9\u8def\u5f84&#xff09;\u3002<\/p>\n<p>\u8bfb\u53d6\u6587\u4ef6\u6d41classpathresource(path)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1041\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011837-682bd86ddc80f.png\" width=\"1847\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"799\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011838-682bd86e8f46e.png\" width=\"1718\" \/><\/p>\n<p>\u6765\u56de\u6d41\u8f6c\u7684\u6570\u636e&#xff0c;\u5c01\u88c5\u5728\u5bf9\u8c61\u4e2d&#xff0c;\u800c\u8fd9\u4e9b\u5bf9\u8c61\u7684\u4ee3\u7801\u90fd\u653e\u5728\/domain\u6587\u4ef6\u5939\u91cc\u3002<\/p>\n<p>\u660e\u5929\u518d\u5199\u3002<\/p>\n<hr \/>\n<p>\u7ee7\u7eed\u8fd9\u4e2achunk\u3002<\/p>\n<p>\u7136\u540e\u4e3a\u4ec0\u4e48\u8981chunk?\u5c0f\u5757\u6587\u672c\u6bd4\u957f\u6587\u672c\u66f4\u9ad8\u6548&#xff0c;\u8282\u7701\u8ba1\u7b97\u8d44\u6e90\u3002\u6309\u7167256\u4e2a\u5b57\u7b26\u5206\u5272\u5b57\u7b26\u4e32\u3002<\/p>\n<p>AtomicInteger \u662f Java \u4e2d\u4e00\u4e2a\u7ebf\u7a0b\u5b89\u5168\u7684\u539f\u5b50\u6574\u6570\u7c7b&#xff0c;\u5c5e\u4e8e java.util.concurrent.atomic \u5305\u3002\u5b83\u7684\u6838\u5fc3\u4f5c\u7528\u662f\u63d0\u4f9b\u539f\u5b50\u64cd\u4f5c&#xff08;\u4e0d\u53ef\u4e2d\u65ad\u7684\u5355\u4e00\u64cd\u4f5c&#xff09;&#xff0c;\u786e\u4fdd\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u5bf9\u6574\u6570\u7684\u64cd\u4f5c&#xff08;\u5982\u9012\u589e\u3001\u9012\u51cf\u3001\u8d4b\u503c\u7b49&#xff09;\u4e0d\u4f1a\u51fa\u73b0\u7ade\u6001\u6761\u4ef6&#xff08;Race Condition&#xff09;\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"804\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011839-682bd86f1c371.png\" width=\"1716\" \/><\/p>\n<p>\u5f88\u660e\u663e&#xff0c;\u628a\u6bcf\u4e2achunk\u540e\u7684\u5c0f\u5757\u6587\u672c\u5c01\u88c5\u6210\u4e00\u4e2achunkresult\u5bf9\u8c61&#xff0c;\u7136\u540e\u8fd4\u56de\u8fd9\u4e9b\u5bf9\u8c61\u6784\u6210\u7684\u96c6\u5408\u3002<\/p>\n<p>\u7136\u540e\u8c03\u7528\u667a\u8c31AI\u7684embedding\u65b9\u6cd5\u3002\u53ef\u4ee5\u770b\u5230\u4f20\u8fdb\u53bb\u7684\u53c2\u6570\u662fchunkresult\u5bf9\u8c61\u7684\u96c6\u5408&#xff0c;\u8fd4\u56de\u7684\u662fembeddingresult\u7684\u96c6\u5408\u3002\u5177\u4f53\u770bembedding\u65b9\u6cd5\u91cc\u7684\u4ee3\u7801&#xff1a;\u89c2\u5bdf\u96c6\u5408\u662f\u5426\u4e3a\u7a7a&#xff0c;\u7a7a\u7684\u8bdd\u8fd4\u56de\u7a7a\u96c6\u5408&#xff1b;\u975e\u7a7a\u8fd4\u56deembedding\u540e\u7684\u96c6\u5408&#xff08;\u8fd9\u91cc\u5c31\u6709\u4e00\u4e2aembedding\u65b9\u6cd5\u4e86&#xff09;\u3002\u6211\u4eec\u5177\u4f53\u770b\u8fd9\u4e2aembedding\u65b9\u6cd5&#xff0c;\u4e0a\u4e00\u4e2aembedding\u8fd4\u56de\u7684\u662f\u96c6\u5408&#xff0c;\u8fd9\u4e2a\u91cc\u9762embedding\u65b9\u6cd5\u8fd4\u56de\u7684\u5355\u4e2a\u5411\u91cf\u5316\u540e\u7684\u7ed3\u679c\u3002\u65b9\u6cd5\u7684\u91cd\u8f7d&#xff0c;\u53c2\u6570\u4e0d\u540c\u3002\u8bf4\u4e0d\u660e\u767d&#xff0c;\u5177\u4f53\u770b\u4ee3\u7801\u5c31\u61c2\u4e86\u3002<\/p>\n<p>    \/**<br \/>\n     * \u6279\u91cf<br \/>\n     * &#064;param chunkResults \u6279\u91cf\u6587\u672c<br \/>\n     * &#064;return \u5411\u91cf<br \/>\n     *\/<br \/>\n    public List&lt;EmbeddingResult&gt; embedding(List&lt;ChunkResult&gt; chunkResults){<br \/>\n        log.info(&#034;start embedding,size:{}&#034;,CollectionUtil.size(chunkResults));<br \/>\n        if (CollectionUtil.isEmpty(chunkResults)){<br \/>\n            return new ArrayList&lt;&gt;();<br \/>\n        }<br \/>\n        List&lt;EmbeddingResult&gt; embeddingResults&#061;new ArrayList&lt;&gt;();<br \/>\n        for (ChunkResult chunkResult:chunkResults){<br \/>\n            embeddingResults.add(this.embedding(chunkResult));<br \/>\n        }<br \/>\n        return embeddingResults;<br \/>\n    }<\/p>\n<p>    public EmbeddingResult embedding(ChunkResult chunkResult){<br \/>\n        String apiKey&#061; this.getApiKey();<br \/>\n        \/\/log.info(&#034;zp-key:{}&#034;,apiKey);<br \/>\n        OkHttpClient.Builder builder &#061; new OkHttpClient.Builder()<br \/>\n                .connectTimeout(20000, TimeUnit.MILLISECONDS)<br \/>\n                .readTimeout(20000, TimeUnit.MILLISECONDS)<br \/>\n                .writeTimeout(20000, TimeUnit.MILLISECONDS)<br \/>\n                .addInterceptor(new ZhipuHeaderInterceptor(apiKey));<br \/>\n        OkHttpClient okHttpClient &#061; builder.build();<br \/>\n        EmbeddingResult embedRequest&#061;new EmbeddingResult();<br \/>\n        embedRequest.setPrompt(chunkResult.getContent());<br \/>\n        embedRequest.setRequestId(Objects.toString(chunkResult.getChunkId()));<br \/>\n        \/\/ \u667a\u8c31embedding<br \/>\n        Request request &#061; new Request.Builder()<br \/>\n                .url(&#034;https:\/\/open.bigmodel.cn\/api\/paas\/v3\/model-api\/text_embedding\/invoke&#034;)<br \/>\n                .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), GSON.toJson(embedRequest)))<br \/>\n                .build();<br \/>\n        try {<br \/>\n            Response response&#061; okHttpClient.newCall(request).execute();<br \/>\n            String result&#061;response.body().string();<br \/>\n            ZhipuResult zhipuResult&#061; GSON.fromJson(result, ZhipuResult.class);<br \/>\n            EmbeddingResult ret&#061; zhipuResult.getData();<br \/>\n            ret.setPrompt(embedRequest.getPrompt());<br \/>\n            ret.setRequestId(embedRequest.getRequestId());<br \/>\n            return  ret;<br \/>\n        } catch (IOException e) {<br \/>\n            throw new RuntimeException(e);<br \/>\n        }<\/p>\n<p>    } <\/p>\n<p>\u524d\u9762embedding\u65b9\u6cd5\u53ea\u662f\u5c01\u88c5\u6210\u96c6\u5408&#xff0c;\u5c31\u4e0d\u770b\u4e86\u3002\u540e\u9762\u7684embedding\u624d\u662f\u771f\u6b63\u7684\u5411\u91cf\u5316&#xff0c;\u91cd\u5934\u620f\u3002&#xff08;\u4f46\u662f\u4eba\u5bb6\u7684API\u54b1\u76f4\u63a5\u7528\u5c31\u884c&#xff0c;embedding\u5177\u4f53\u56de\u5934\u518d\u770b\u5427&#xff09;<\/p>\n<p>\u76f4\u63a5\u7528\u7684\u667a\u8c31\u7684API&#xff0c;\u6211\u4eec\u76f4\u63a5\u7ed9\u53c2\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u5148\u83b7\u53d6\u5bc6\u94a5\u3002\/\/\u54b1\u4eec\u5199\u597d\u7684getapikey\u65b9\u6cd5&#xff0c;\u800c\u5b83\u91cc\u9762\u662f\u8c03\u7528\u4e86LLmProperties\u91cc\u9762\u7684\u4e1c\u897f\u3002&#xff08;\u56de\u5934\u518d\u770b\u5427&#xff0c;\u53cd\u6b63\u80af\u5b9a\u8fd9\u4e2a\u6ce8\u89e3\u6307\u5b9a\u6709\u70b9\u4e1c\u897f\/\/\u7ed1\u5b9a\u524d\u7f00\u201cllm\u201d\u5f00\u5934\u7684\u914d\u7f6e&#xff0c;\u7136\u540e\u518dyaml\u914d\u7f6e\u6587\u4ef6\u91cc\u5b9a\u4e49\u5c5e\u6027&#xff09;&#x1f447;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"916\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011839-682bd86f9c1a0.png\" width=\"1461\" \/><\/p>\n<p>\u4f7f\u7528 OkHttpClient.Builder \u6784\u5efa\u4e00\u4e2a HTTP \u5ba2\u6237\u7aef&#xff0c;\u914d\u7f6e\u4e86\u8fde\u63a5\u3001\u8bfb\u53d6\u548c\u5199\u5165\u7684\u8d85\u65f6\u65f6\u95f4&#xff08;\u5747\u4e3a 20 \u79d2&#xff09;\u3002<\/p>\n<p>\u6dfb\u52a0\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u62e6\u622a\u5668 ZhipuHeaderInterceptor&#xff0c;\u7528\u4e8e\u5728\u8bf7\u6c42\u5934\u4e2d\u6dfb\u52a0 API \u5bc6\u94a5\u7b49\u8ba4\u8bc1\u4fe1\u606f\u3002<\/p>\n<hr \/>\n<ul>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2a\u00a0EmbeddingResult\u00a0\u5bf9\u8c61\u4f5c\u4e3a\u8bf7\u6c42\u4f53\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u00a0prompt\u00a0\u4e3a\u8f93\u5165\u6587\u672c\u5757\u7684\u5185\u5bb9&#xff08;chunkResult.getContent()&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u00a0requestId\u00a0\u4e3a\u6587\u672c\u5757\u7684 ID&#xff08;chunkResult.getChunkId()&#xff09;&#xff0c;\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<\/li>\n<\/ul>\n<p> EmbeddingResult embedRequest&#061;new EmbeddingResult();<br \/>\nembedRequest.setPrompt(chunkResult.getContent());<br \/>\nembedRequest.setRequestId(Objects.toString(chunkResult.getChunkId())); <\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"731\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011840-682bd870053b1.png\" width=\"1689\" \/><\/p>\n<hr \/>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1180\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011840-682bd8707c3b7.png\" width=\"1718\" \/><\/p>\n<p>\u6211\u4eec\u5728\u8fd9\u91cc\u7528\u5230\u4e86\u4e00\u4e2a\u62e6\u622a\u5668\u3002\u56de\u5934\u518d\u4ed4\u7ec6\u770b\u3002<\/p>\n<p>Lombok \u6ce8\u89e3&#xff1a;\u7b80\u5316\u4ee3\u7801\u3002\u6bd4\u5982&#064;AllArgsConstructor\u6ce8\u89e3&#xff0c;\u5c31\u662f\u9ed8\u8ba4\u5168\u53c2\u6784\u9020\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1056\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011841-682bd87146c3c.png\" width=\"1671\" \/><\/p>\n<p>\u5177\u4f53\u89c1&#xff1a;Lombok-CSDN\u535a\u5ba2<\/p>\n<p>\u5411\u91cf\u5316\u8fd4\u56de\u7684\u7ed3\u679c&#x1f447;\u662f\u5730\u5740\u3002\u3002\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"637\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011841-682bd871ea178.png\" width=\"1552\" \/><\/p>\n<p>\u6570\u7ec4\u53d8\u6210\u5b57\u7b26\u4e32\u6253\u5370\u51fa\u6765&#x1f447;\u53d8\u6210\u8fd9\u6837\u7684\u5411\u91cf\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1449\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011842-682bd8726326c.png\" width=\"2786\" \/><\/p>\n<p>\u7406\u8bba\u4e0a\u6bcf\u4e2a\u6570\u7ec4\u5927\u5c0f\u4e3a1024&#xff0c;\u4e8b\u5b9e\u4e0a\u4e5f\u662f\u3002\u5177\u4f53\u5411\u91cf\u600e\u4e48\u7b97\u7684&#xff0c;\u56de\u5934\u770b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1203\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011844-682bd8747a4ee.png\" width=\"2816\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\u628a\u8fd9\u4e9b\u5411\u91cf\u5b58\u8d77\u6765\u3002\u5b58\u5728\u54ea&#xff1f;\u600e\u4e48\u5b58&#xff1f;\u53ef\u4ee5\u770b\u5230\u8fd9\u56de\u7528\u5230\u4e86vectorStorage&#xff0c;\u8c03\u7528\u4e86\u5b83\u7684store&#xff0c;\u53c2\u6570\u662fcollectionName&#xff08;\u4e0b\u9762\u8bb2\/\/\u53ef\u4ee5get\u5f97\u5230&#xff09;\u548cembedding\u540e\u7684\u5411\u91cf\u3002&#xff08;\u6700\u5f00\u59cb\u6211\u4eec\u8bf4\u8be5\u9879\u76ee\u662f\u7528ES\u5b58\u7684&#xff09;<\/p>\n<p>\u53ef\u4ee5\u770b\u5230initCollection\u65b9\u6cd5\u7684\u4e24\u4e2a\u53c2\u6570&#xff0c;\u4e00\u4e2a\u662f\u540d\u5b57&#xff08;\u56fa\u5b9a\u524d\u7f00&#043;\u65f6\u95f4&#xff09;&#xff0c;\u53e6\u4e00\u4e2a\u662f\u7ef4\u5ea6\u3002\u4f20\u8fdb\u53bb\u8fd9\u4fe9\u53c2\u6570&#xff0c;\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c&#xff08;T or F&#xff09;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e0d\u8fdb\u53bb\uff0c\u987a\u4fbf\u5199\u7bc7\u6d41\u6c34\u8d26\u3002<\/p>\n","protected":false},"author":2,"featured_media":38383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[305],"topic":[],"class_list":["post-38402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>2025\/5\/18 - \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\/38402.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"2025\/5\/18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e0d\u8fdb\u53bb\uff0c\u987a\u4fbf\u5199\u7bc7\u6d41\u6c34\u8d26\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38402.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T01:18:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011834-682bd86a757af.png\" \/>\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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38402.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38402.html\",\"name\":\"2025\/5\/18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T01:18:47+00:00\",\"dateModified\":\"2025-05-20T01:18:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38402.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38402.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38402.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"2025\/5\/18\"}]},{\"@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":"2025\/5\/18 - \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\/38402.html","og_locale":"zh_CN","og_type":"article","og_title":"2025\/5\/18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e0d\u8fdb\u53bb\uff0c\u987a\u4fbf\u5199\u7bc7\u6d41\u6c34\u8d26\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38402.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T01:18:47+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520011834-682bd86a757af.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38402.html","url":"https:\/\/www.wsisp.com\/helps\/38402.html","name":"2025\/5\/18 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T01:18:47+00:00","dateModified":"2025-05-20T01:18:47+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38402.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38402.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38402.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"2025\/5\/18"}]},{"@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\/38402","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=38402"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38402\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38383"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38402"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}