{"id":1792,"date":"2024-04-02T19:40:55","date_gmt":"2024-04-02T11:40:55","guid":{"rendered":"https:\/\/www.tchepai.com\/?p=1792"},"modified":"2024-04-02T19:40:55","modified_gmt":"2024-04-02T11:40:55","slug":"chatollama-ragredis","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/ja\/chatollama-ragredis\/","title":{"rendered":"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><strong>ChatOllama<\/strong>\u00a0\u662f\u4e00\u6b3e\u57fa\u4e8eLLMs\u7684\u5f00\u6e90\u804a\u5929\u673a\u5668\u4eba\u3002\u5bf9ChatOllama\u7684\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>ChatOllama | \u57fa\u4e8eOllama\u7684100%\u672c\u5730RAG\u5e94\u7528<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.kdjingpai.com\/ja\/chatollamajiyun\/\">ChatOllama<\/a> \u6700\u521d\u7684\u76ee\u6807\u662f\u4e3a\u7528\u6237\u63d0\u4f9b\u4e00\u4e2a100%\u672c\u5730RAG\u5e94\u7528\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u968f\u7740\u5176\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7528\u6237\u63d0\u51fa\u6709\u4ef7\u503c\u7684\u9700\u6c42\u3002\u73b0\u5728\uff0c`ChatOllama` \u652f\u6301\u591a\u79cd\u8bed\u8a00\u6a21\u578b\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/www.kdjingpai.com\/ja\/ollama\/\">Ollama<\/a> \u652f\u6301\u7684\u6a21\u578b<\/li>\n<li>OpenAI<\/li>\n<li>Azure OpenAI<\/li>\n<li><a href=\"https:\/\/www.kdjingpai.com\/ja\/claudeanquanfubai\/\">Anthropic<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u4f7f\u7528 ChatOllama, \u7528\u6237\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li>\u7ba1\u7406Ollama\u6a21\u578b\uff08\u62c9\u53d6\/\u5220\u9664\uff09<\/li>\n<li>\u7ba1\u7406\u77e5\u8bc6\u5e93\uff08\u521b\u5efa\/\u5220\u9664\uff09<\/li>\n<li>\u4e0eLLMs\u81ea\u7531\u5bf9\u8bdd<\/li>\n<li>\u7ba1\u7406\u4e2a\u4eba\u77e5\u8bc6\u5e93<\/li>\n<li>\u901a\u8fc7\u4e2a\u4eba\u77e5\u8bc6\u5e93\u4e0eLLMs\u4ea4\u6d41<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u63a2\u8ba8\u5982\u4f55\u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u3002\u6211\u5df2\u7ecf\u5b66\u4e60\u4e86RAG\u7684\u57fa\u672c\u548c\u8fdb\u9636\u6280\u5de7\uff0c\u4f46\u5c06RAG\u6295\u5165\u751f\u4ea7\u4ecd\u7136\u6709\u8bb8\u591a\u9700\u8981\u5904\u7406\u7684\u4e8b\u9879\u3002\u6211\u5c06\u5206\u4eab\u5728ChatOllama\u4e2d\u5df2\u7ecf\u505a\u7684\u5de5\u4f5c\u4ee5\u53ca\u4e3a\u5b9e\u73b0RAG\u7684\u751f\u4ea7\u5316\u6240\u505a\u7684\u51c6\u5907\u3002<\/p>\n<p>&nbsp;<\/p>\n<div style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2961\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/46b718bd35d18cd.png\" width=\"800\" height=\"447\" alt=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-1\" title=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-1\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/46b718bd35d18cd.png 800w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/46b718bd35d18cd-300x168.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/46b718bd35d18cd-768x429.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p class=\"wp-caption-text\">ChatOllama | RAG\u6784\u5efa\u5316\u8fd0\u884c<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>\u5728ChatOllama\u5e73\u53f0\u4e2d\uff0c\u6211\u4eec\u8fd0\u7528\u5230\u4e86<strong>LangChain.js<\/strong>\u6765\u64cd\u63a7RAG\u6d41\u7a0b\u3002\u5728ChatOllama\u7684\u77e5\u8bc6\u5e93\u4e2d\uff0c\u8d85\u8d8a\u4e8e\u539f\u59cbRAG\u7684\u7236\u6587\u6863\u68c0\u7d22\u5668\u5f97\u4ee5\u8fd0\u7528\u3002\u8ba9\u6211\u4eec\u6df1\u5ea6\u63a2\u7a76\u5176\u6784\u67b6\u53ca\u6267\u884c\u7ec6\u8282\u3002\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u542f\u53d1\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h1>\u7236\u6587\u6863\u68c0\u7d22\u5668\u7684\u5b9e\u7528\u5316<\/h1>\n<p>&nbsp;<\/p>\n<p>\u4e3a\u4e86\u8ba9\u7236\u6587\u6863\u68c0\u7d22\u5668\u5728\u4e00\u4e2a\u771f\u5b9e\u4ea7\u54c1\u4e2d\u8fd0\u884c\uff0c\u6211\u4eec\u9700\u7406\u89e3\u5176\u6838\u5fc3\u539f\u7406\uff0c\u5e76\u4e3a\u751f\u4ea7\u76ee\u7684\u9009\u53d6\u5408\u9002\u7684\u5b58\u50a8\u5143\u4ef6\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u7236\u6587\u6863\u68c0\u7d22\u5668\u7684\u6838\u5fc3\u539f\u7406<\/h2>\n<p>\u5728\u4e3a\u68c0\u7d22\u9700\u6c42\u5c06\u6587\u6863\u62c6\u5206\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\u51b2\u7a81\u7684\u9700\u6c42\uff1a<\/p>\n<ul>\n<li>\u4f60\u53ef\u80fd\u5e0c\u671b\u6587\u6863\u8d8a\u5c0f\u8d8a\u597d\uff0c\u8fd9\u6837\u5b83\u4eec\u7684\u5d4c\u5165\u5f0f\u5185\u5bb9\u53ef\u4ee5\u6700\u7cbe\u51c6\u5730\u4f53\u73b0\u5b83\u4eec\u7684\u542b\u4e49\u3002\u5982\u679c\u5185\u5bb9\u8fc7\u957f\uff0c\u5d4c\u5165\u5f0f\u4fe1\u606f\u53ef\u80fd\u4f1a\u5931\u53bb\u5176\u542b\u4e49\u3002<\/li>\n<li>\u4f60\u4e5f\u60f3\u8981\u8db3\u591f\u957f\u7684\u6587\u6863\uff0c\u4ee5\u4fdd\u8bc1\u6bcf\u6bb5\u5185\u5bb9\u5177\u5907\u5b8c\u6574\u7684\u5168\u6587\u73af\u5883\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u7531LangChain.js\u63d0\u4f9b\u7684<code>ParentDocumentRetriever<\/code>\u901a\u8fc7\u5c06\u6587\u6863\u62c6\u5206\u4e3a\u5c0f\u5757\u6765\u53d6\u5f97\u8fd9\u4e2a\u5e73\u8861\u3002\u6bcf\u6b21\u68c0\u7d22\u65f6\uff0c\u5b83\u63d0\u53d6\u5c0f\u5757\uff0c\u7136\u540e\u67e5\u627e\u5404\u4e2a\u5c0f\u5757\u5bf9\u5e94\u7684\u7236\u6587\u6863\uff0c\u8fd4\u56de\u66f4\u5927\u8303\u56f4\u7684\u6587\u6863\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u7236\u6587\u6863\u4f1a\u901a\u8fc7doc id\u4e0e\u5c0f\u5757\u76f8\u8054\u7cfb\u3002\u6211\u4eec\u7a0d\u540e\u4f1a\u8fdb\u4e00\u6b65\u89e3\u91ca\u5176\u8fd0\u884c\u65b9\u5f0f\u3002<\/p>\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684<code>parent document<\/code>\u6307\u7684\u662f\u5c0f\u5757\u7684\u6765\u6e90\u6587\u6863\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u67b6\u6784<\/h2>\n<p>\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u7236\u6587\u6863\u68c0\u7d22\u5668\u7684\u6574\u4f53\u67b6\u6784\u56fe\u3002<\/p>\n<p>\u6bcf\u4e2a\u5c0f\u5757\u4f1a\u7ecf\u8fc7\u5904\u7406\u8f6c\u53d8\u4e3a\u5411\u91cf\u6570\u636e\uff0c\u7136\u540e\u5b58\u50a8\u5728\u5411\u91cf\u6570\u636e\u5e93\u4e2d\u3002 \u68c0\u7d22\u8fd9\u4e9b\u5c0f\u5757\u7684\u8fc7\u7a0b\u5c06\u5982\u540c\u5728\u539f\u59cbRAG\u8bbe\u7f6e\u4e2d\u6240\u505a\u7684\u90a3\u6837\u3002<\/p>\n<p>\u7236\u6587\u6863\uff08\u5757-1\u3001\u5757-2\u3001&#8230;&#8230;\u5757-m\uff09\u88ab\u5206\u5272\u6210\u66f4\u5c0f\u7684\u90e8\u5206\u3002 \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u7528\u5230\u4e86\u4e24\u4e2a\u4e0d\u540c\u7684\u6587\u672c\u5206\u5272\u65b9\u6cd5\uff1a\u4e00\u4e2a\u8f83\u5927\u7684\u7528\u4e8e\u7236\u6587\u6863\uff0c\u53e6\u4e00\u4e2a\u8f83\u5c0f\u7684\u7528\u4e8e\u66f4\u5c0f\u7684\u5757\u3002\u6bcf\u4e2a\u7236\u6587\u6863\u90fd\u88ab\u8d4b\u4e88\u4e00\u4e2a\u6587\u6863ID\uff0c\u7136\u540e\u5c06\u6b64ID\u4f5c\u4e3a\u5143\u6570\u636e\u8bb0\u5f55\u5728\u5176\u5bf9\u5e94\u7684\u5c0f\u5757\u4e2d\u3002 \u8fd9\u786e\u4fdd\u4e86\u6bcf\u4e2a\u5c0f\u5757\u90fd\u80fd\u901a\u8fc7\u5b58\u50a8\u5728\u5143\u6570\u636e\u4e2d\u7684\u6587\u6863ID\u627e\u5230\u5176\u76f8\u5e94\u7684\u7236\u6587\u6863\u3002<\/p>\n<p>\u68c0\u7d22\u7236\u6587\u6863\u7684\u8fc7\u7a0b\u4e0e\u8fd9\u5e76\u4e0d\u76f8\u540c\u3002\u4e0d\u9700\u8981\u76f8\u4f3c\u6027\u641c\u7d22\uff0c\u53ea\u9700\u63d0\u4f9b\u6587\u6863ID\u5c31\u53ef\u4ee5\u627e\u5230\u5176\u5bf9\u5e94\u7684\u7236\u6587\u6863\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e00\u4e2a\u952e-\u503c\u5b58\u50a8\u7cfb\u7edf\u5c31\u8db3\u591f\u80dc\u4efb\u3002<\/p>\n<p>&nbsp;<\/p>\n<div style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3120\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/4388b7e17490a8b.png\" width=\"800\" height=\"448\" alt=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-2\" title=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-2\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/4388b7e17490a8b.png 800w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/4388b7e17490a8b-300x168.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/4388b7e17490a8b-768x430.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p class=\"wp-caption-text\">\u7236\u6587\u6863\u68c0\u7d22\u5668<\/p><\/div>\n<p>&nbsp;<\/p>\n<h2>\u5b58\u50a8\u90e8\u5206<\/h2>\n<p>\u6709\u4e24\u79cd\u6570\u636e\u9700\u8981\u5b58\u50a8\uff1a<\/p>\n<ul>\n<li>\u5c0f\u89c4\u6a21\u7684\u5411\u91cf\u6570\u636e<\/li>\n<li>\u542b\u6709\u5176\u6587\u6863ID\u7684\u7236\u6587\u6863\u7684\u5b57\u7b26\u4e32\u6570\u636e<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u6240\u6709\u4e3b\u6d41\u7684\u5411\u91cf\u6570\u636e\u5e93\u90fd\u662f\u53ef\u4ee5\u4f7f\u7528\u7684\u3002\u5728`ChatOllama`\u4e2d\uff0c\u6211\u9009\u62e9\u4e86Chroma\u3002<\/p>\n<p>\u5bf9\u4e8e\u7236\u6587\u6863\u6570\u636e\uff0c\u6211\u9009\u7528\u4e86\u5f53\u524d\u6700\u6d41\u884c\u5e76\u5177\u6709\u9ad8\u5ea6\u6269\u5c55\u6027\u7684\u952e\u503c\u5b58\u50a8\u7cfb\u7edfRedis\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>LangChain.js\u7f3a\u5c11\u7684\u5185\u5bb9<\/h2>\n<p>LangChain.js\u4e3a\u5b57\u8282\u548c\u6587\u6863\u5b58\u50a8\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u96c6\u6210\u65b9\u5f0f\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/\">\u5b58\u50a8 | \ud83e\udd9c\ufe0f\ud83d\udd17 Langchain<\/a><\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/\">\u4ee5\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u662f\u5feb\u901f\u4e14\u9ad8\u6548\u7684\uff0c\u5bf9\u4e8eLLM\u5e94\u7528\u6765\u8bf4\u662f\u5f3a\u5927\u7684\u5de5\u5177\u3002\u57fa\u7840\u5b58\u50a8\u5e93\u2026<\/a><\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/\">js.langchain.com<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u652f\u6301`IORedis`\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/ioredis_storage\">IORedis | \ud83e\udd9c\ufe0f\ud83d\udd17 Langchain<\/a><\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/ioredis_storage\">\u8fd9\u4e2a\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528RedisByteStore\u57fa\u7840\u5b58\u50a8\u5e93\u96c6\u6210\u6765\u8bbe\u5b9a\u804a\u5929\u5386\u53f2\u8bb0\u5f55\u7684\u5b58\u50a8\u3002<\/a><\/p>\n<p><a href=\"https:\/\/js.langchain.com\/docs\/integrations\/stores\/ioredis_storage\">js.langchain.com<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>RedisByteStore\u4e2d\u7f3a\u5c11\u7684\u4e00\u90e8\u5206\u662f<code>collection<\/code>\u673a\u5236\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5728\u5904\u7406\u4e0d\u540c\u77e5\u8bc6\u5e93\u4e2d\u7684\u6587\u6863\u65f6\uff0c\u5404\u4e2a\u77e5\u8bc6\u5e93\u5c06\u4ee5\u4e00\u4e2a<code>collection<\/code>\u96c6\u5408\u7684\u5f62\u5f0f\u8fdb\u884c\u7ec4\u7ec7\uff0c\u540c\u4e00\u5e93\u4e2d\u7684\u6587\u6863\u5c06\u88ab\u8f6c\u5316\u4e3a\u5411\u91cf\u6570\u636e\u5e76\u5b58\u50a8\u5728\u5411\u91cf\u6570\u636e\u5e93\u5982Chroma\u7684\u67d0\u4e00\u4e2a<code>collection<\/code>\u96c6\u5408\u4e2d\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u60f3\u8981\u5220\u9664\u4e00\u4e2a\u77e5\u8bc6\u5e93\uff1f\u6211\u4eec\u80af\u5b9a\u53ef\u4ee5\u5220\u9664Chroma\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u4e2a`collection`\u96c6\u5408\u3002\u4f46\u662f\u6211\u4eec\u5982\u4f55\u6309\u7167\u77e5\u8bc6\u5e93\u7684\u7ef4\u5ea6\u6765\u6e05\u7406\u6587\u6863\u5b58\u50a8\u5462\uff1f\u56e0\u4e3a\u5982RedisByteStore\u4e4b\u7c7b\u7684\u7ec4\u4ef6\u5e76\u4e0d\u652f\u6301`collection`\u529f\u80fd\uff0c\u56e0\u6b64\u6211\u5fc5\u987b\u81ea\u884c\u5b9e\u73b0\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>ChatOllama RedisDocStore<\/h2>\n<p>\u5728Redis\u4e2d\uff0c\u5e76\u672a\u6709\u540d\u4e3a`collection`\u7684\u5185\u7f6e\u529f\u80fd\u3002\u5f00\u53d1\u8005\u901a\u5e38\u4f1a\u901a\u8fc7\u4f7f\u7528\u524d\u7f00\u952e\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0`collection`\u529f\u80fd\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u524d\u7f00\u6765\u6807\u8bc6\u4e0d\u540c\u7684\u96c6\u5408\uff1a<\/p>\n<p>&nbsp;<\/p>\n<div style=\"width: 810px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3236\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/833a09b60a27cf6.png\" width=\"800\" height=\"297\" alt=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-3\" title=\"ChatOllama \u7b14\u8bb0 | \u5b9e\u73b0\u9ad8\u7ea7RAG\u7684\u751f\u4ea7\u5316\u548c\u57fa\u4e8eRedis\u7684\u6587\u6863\u6570\u636e\u5e93-3\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/833a09b60a27cf6.png 800w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/833a09b60a27cf6-300x111.png 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/04\/833a09b60a27cf6-768x285.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><p class=\"wp-caption-text\">\u5e26\u6709\u524d\u7f00\u7684Redis\u952e\u8868\u793a\u5f62\u5f0f<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u770b\u4e00\u4e0b\uff0c\u662f\u5982\u4f55\u5b9e\u65bd\u4ee5<strong>Redis<\/strong>\u4e3a\u80cc\u666f\u7684\u6587\u6863\u5b58\u50a8\u529f\u80fd\u7684\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5173\u952e\u4fe1\u606f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6bcf\u4e00\u4e2a`RedisDocstore`\u5728\u521d\u59cb\u5316\u65f6\u90fd\u9700\u8f93\u5165\u4e00\u4e2a`namespace`\u53c2\u6570\u3002\uff08\u5f53\u524d\u5728namespace\u548ccollection\u7684\u547d\u540d\u53ef\u80fd\u5e76\u672a\u7edf\u4e00\uff09<\/li>\n<li>\u5728\u8fdb\u884cget\u548cset\u64cd\u4f5c\u65f6\uff0c\u952e\u90fd\u5148\u8fdb\u884c`namespace`\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<blockquote><p>import { Document } from &#8220;@langchain\/core\/documents&#8221;;<br \/>\nimport { BaseStoreInterface } from &#8220;@langchain\/core\/stores&#8221;;<br \/>\nimport { Redis } from &#8220;ioredis&#8221;;<br \/>\nimport { createRedisClient } from &#8220;@\/server\/store\/redis&#8221;;<\/p>\n<p>export class RedisDocstore implements BaseStoreInterface&lt;string, Document&gt;<br \/>\n{<br \/>\n_namespace: string;<br \/>\n_client: Redis;<\/p>\n<p>constructor(namespace: string) {<br \/>\nthis._namespace = namespace;<br \/>\nthis._client = createRedisClient();<br \/>\n}<\/p>\n<p>serializeDocument(doc: Document): string {<br \/>\nreturn JSON.stringify(doc);<br \/>\n}<\/p>\n<p>deserializeDocument(jsonString: string): Document {<br \/>\nconst obj = JSON.parse(jsonString);<br \/>\nreturn new Document(obj);<br \/>\n}<\/p>\n<p>getNamespacedKey(key: string): string {<br \/>\nreturn `${this._namespace}:${key}`;<br \/>\n}<\/p>\n<p>getKeys(): Promise&lt;string[]&gt; {<br \/>\nreturn new Promise((resolve, reject) =&gt; {<br \/>\nconst stream = this._client.scanStream({ match: this._namespace + &#8216;*&#8217; });<\/p>\n<p>const keys: string[] = [];<br \/>\nstream.on(&#8216;data&#8217;, (resultKeys) =&gt; {<br \/>\nkeys.push(&#8230;resultKeys);<br \/>\n});<\/p>\n<p>stream.on(&#8216;end&#8217;, () =&gt; {<br \/>\nresolve(keys);<br \/>\n});<\/p>\n<p>stream.on(&#8216;error&#8217;, (err) =&gt; {<br \/>\nreject(err);<br \/>\n});<br \/>\n});<br \/>\n}<\/p>\n<p>addText(key: string, value: string) {<br \/>\nthis._client.set(this.getNamespacedKey(key), value);<br \/>\n}<\/p>\n<p>async search(search: string): Promise&lt;Document&gt; {<br \/>\nconst result = await this._client.get(this.getNamespacedKey(search));<br \/>\nif (!result) {<br \/>\nthrow new Error(`ID ${search} not found.`);<br \/>\n} else {<br \/>\nconst document = this.deserializeDocument(result);<br \/>\nreturn document;<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Adds new documents to the store.<br \/>\n* @param texts An object where the keys are document IDs and the values are the documents themselves.<br \/>\n* @returns Void<br \/>\n*\/<br \/>\nasync add(texts: Record&lt;string, Document&gt;): Promise&lt;void&gt; {<br \/>\nfor (const [key, value] of Object.entries(texts)) {<br \/>\nconsole.log(`Adding ${key} to the store: ${this.serializeDocument(value)}`);<br \/>\n}<\/p>\n<p>const keys = [&#8230;await this.getKeys()];<br \/>\nconst overlapping = Object.keys(texts).filter((x) =&gt; keys.includes(x));<\/p>\n<p>if (overlapping.length &gt; 0) {<br \/>\nthrow new Error(`Tried to add ids that already exist: ${overlapping}`);<br \/>\n}<\/p>\n<p>for (const [key, value] of Object.entries(texts)) {<br \/>\nthis.addText(key, this.serializeDocument(value));<br \/>\n}<br \/>\n}<\/p>\n<p>async mget(keys: string[]): Promise&lt;Document[]&gt; {<br \/>\nreturn Promise.all(keys.map((key) =&gt; {<br \/>\nconst document = this.search(key);<br \/>\nreturn document;<br \/>\n}));<br \/>\n}<\/p>\n<p>async mset(keyValuePairs: [string, Document][]): Promise&lt;void&gt; {<br \/>\nawait Promise.all(<br \/>\nkeyValuePairs.map(([key, value]) =&gt; this.add({ [key]: value }))<br \/>\n);<br \/>\n}<\/p>\n<p>async mdelete(_keys: string[]): Promise&lt;void&gt; {<br \/>\nthrow new Error(&#8220;Not implemented.&#8221;);<br \/>\n}<\/p>\n<p>\/\/ eslint-disable-next-line require-yield<br \/>\nasync *yieldKeys(_prefix?: string): AsyncGenerator&lt;string&gt; {<br \/>\nthrow new Error(&#8220;Not implemented&#8221;);<br \/>\n}<\/p>\n<p>async deleteAll(): Promise&lt;void&gt; {<br \/>\nreturn new Promise((resolve, reject) =&gt; {<br \/>\nlet <a href=\"https:\/\/www.kdjingpai.com\/ja\/cursoryuaigongtong\/\">cursor<\/a> = &#8216;0&#8217;;<\/p>\n<p>const scanCallback = (err, result) =&gt; {<br \/>\nif (err) {<br \/>\nreject(err);<br \/>\nreturn;<br \/>\n}<\/p>\n<p>const [nextCursor, keys] = result;<\/p>\n<p>\/\/ Delete keys matching the prefix<br \/>\nkeys.forEach((key) =&gt; {<br \/>\nthis._client.del(key);<br \/>\n});<\/p>\n<p>\/\/ If the cursor is &#8216;0&#8217;, we&#8217;ve iterated through all keys<br \/>\nif (nextCursor === &#8216;0&#8217;) {<br \/>\nresolve();<br \/>\n} else {<br \/>\n\/\/ <a href=\"https:\/\/www.kdjingpai.com\/ja\/continue\/\">Continue<\/a> scanning with the next cursor<br \/>\nthis._client.scan(nextCursor, &#8216;MATCH&#8217;, `${this._namespace}:*`, scanCallback);<br \/>\n}<br \/>\n};<\/p>\n<p>\/\/ Start the initial SCAN operation<br \/>\nthis._client.scan(cursor, &#8216;MATCH&#8217;, `${this._namespace}:*`, scanCallback);<br \/>\n});<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>\u60a8\u53ef\u4ee5\u5c06\u6b64\u7ec4\u4ef6\u4e0e ParentDocumentRetriever \u65e0\u7f1d\u7ed3\u5408\u4f7f\u7528\uff1a<\/p>\n<blockquote><p>retriever = new ParentDocumentRetriever({<br \/>\nvectorstore: chromaClient,<br \/>\ndocstore: new RedisDocstore(collectionName),<br \/>\nparentSplitter: new RecursiveCharacterTextSplitter({<br \/>\nchunkOverlap: 200,<br \/>\nchunkSize: 1000,<br \/>\n}),<br \/>\nchildSplitter: new RecursiveCharacterTextSplitter({<br \/>\nchunkOverlap: 50,<br \/>\nchunkSize: 200,<br \/>\n}),<br \/>\nchildK: 20,<br \/>\nparentK: 5,<br \/>\n});<\/p><\/blockquote>\n<p>\u76ee\u524d\uff0c\u6211\u4eec\u5df2\u7ecf\u62e5\u6709\u9ad8\u7ea7RAG\u7684\u53ef\u6269\u5c55\u5b58\u50a8\u89e3\u51b3\u65b9\u6848\u2014\u2014Parent Document Retriever\uff0c\u540c\u65f6\u8fd8\u6709`Chroma`\u548c`Redis`\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; ChatOllama\u00a0\u662f\u4e00\u6b3e\u57fa\u4e8eLLMs\u7684\u5f00\u6e90\u804a\u5929\u673a\u5668\u4eba\u3002\u5bf9ChatOllama\u7684\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u3002 &nbsp; ChatOllama | \u57fa\u4e8eOllama\u7684100%\u672c\u5730RAG\u5e94\u7528 &nbsp; ChatOllama &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-1792","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/1792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/comments?post=1792"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/1792\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/media?parent=1792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/categories?post=1792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/tags?post=1792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}