{"id":69228,"date":"2026-01-31T09:08:58","date_gmt":"2026-01-31T01:08:58","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69228.html"},"modified":"2026-01-31T09:08:58","modified_gmt":"2026-01-31T01:08:58","slug":"%e6%9e%84%e5%bb%ba%e4%bc%81%e4%b8%9a%e7%ba%a7%e6%99%ba%e8%83%bd%e7%9f%a5%e8%af%86%e5%ba%93%ef%bc%9a%e4%bb%8e-rag-%e6%8a%80%e6%9c%af%e5%88%b0%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69228.html","title":{"rendered":"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5"},"content":{"rendered":"<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u9002\u7528\u573a\u666f&#xff1a;\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u3001\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\u642d\u5efa\u3001\u5927\u6a21\u578b\u843d\u5730\u4e1a\u52a1\u573a\u666f<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6280\u672f\u6808&#xff1a;LangChain\u3001Chroma\u3001HuggingFace Embeddings\u3001ChatGLM<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u96be\u5ea6&#xff1a;\u2605\u2605\u2605\u2606\u2606<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"651\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131010856-697d56286f56d.png\" width=\"959\" \/><\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6458\u8981<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5927\u8bed\u8a00\u6a21\u578b\u7684\u77e5\u8bc6\u6ede\u540e\u6027\u548c\u4e8b\u5b9e\u6027\u504f\u5dee\u6210\u4e3a\u5176\u843d\u5730\u4f01\u4e1a\u7ea7\u573a\u666f\u7684\u6838\u5fc3\u75db\u70b9&#xff0c;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;Retrieval-Augmented Generation&#xff0c;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93\u4e0e\u751f\u6210\u6a21\u578b\u7684\u878d\u5408&#xff0c;\u4e3a\u8be5\u95ee\u9898\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002\u672c\u6587\u4ee5\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\u6784\u5efa\u4e3a\u6838\u5fc3\u573a\u666f&#xff0c;\u7cfb\u7edf\u9610\u8ff0RAG\u6280\u672f\u7684\u6838\u5fc3\u539f\u7406\u4e0e\u6574\u4f53\u67b6\u6784&#xff0c;\u4ece\u77e5\u8bc6\u5e93\u9884\u5904\u7406\u3001\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa\u3001\u68c0\u7d22\u589e\u5f3a\u751f\u6210\u5b9e\u73b0\u4e09\u4e2a\u6838\u5fc3\u73af\u8282\u63d0\u4f9b\u53ef\u843d\u5730\u7684\u4ee3\u7801\u793a\u4f8b\u4e0e\u5b9e\u64cd\u7ec6\u8282&#xff0c;\u540c\u65f6\u7ed9\u51fa\u6df7\u5408\u68c0\u7d22\u3001\u91cd\u6392\u5e8f\u3001\u63d0\u793a\u8bcd\u5de5\u7a0b\u7b49\u6027\u80fd\u4f18\u5316\u7b56\u7565&#xff0c;\u7ed3\u5408\u5b9e\u9645\u6d4b\u8bd5\u6570\u636e\u9a8c\u8bc1RAG\u7cfb\u7edf\u7684\u5e94\u7528\u6548\u679c&#xff0c;\u5e76\u9488\u5bf9\u4e2d\u6587\u573a\u666f\u7684\u68c0\u7d22\u7cbe\u5ea6\u3001\u591a\u6587\u6863\u51b2\u7a81\u3001\u77e5\u8bc6\u65f6\u6548\u6027\u7b49\u5e38\u89c1\u95ee\u9898\u63d0\u4f9b\u89e3\u51b3\u65b9\u6848&#xff0c;\u6700\u540e\u660e\u786e\u4f01\u4e1a\u6784\u5efaRAG\u77e5\u8bc6\u5e93\u7684\u5408\u89c4\u6027\u4e0e\u5b89\u5168\u6027\u8003\u91cf&#xff0c;\u4e3aRAG\u6280\u672f\u5728\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u573a\u666f\u7684\u843d\u5730\u63d0\u4f9b\u5b8c\u6574\u7684\u7406\u8bba\u4e0e\u5b9e\u8df5\u53c2\u8003\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5173\u952e\u8bcd<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">RAG&#xff1b;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff1b;\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93&#xff1b;\u5411\u91cf\u6570\u636e\u5e93&#xff1b;LangChain&#xff1b;\u5927\u8bed\u8a00\u6a21\u578b\u4f18\u5316<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6b63\u6587<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u968f\u7740\u5927\u8bed\u8a00\u6a21\u578b&#xff08;LLM&#xff09;\u5728\u91d1\u878d\u3001\u5236\u9020\u3001\u4e92\u8054\u7f51\u7b49\u5404\u884c\u4e1a\u4e1a\u52a1\u573a\u666f\u7684\u6df1\u5ea6\u5e94\u7528&#xff0c;\u5176\u77e5\u8bc6\u6ede\u540e\u6027&#xff08;\u8bad\u7ec3\u6570\u636e\u622a\u6b62\u540e\u65e0\u65b0\u4fe1\u606f&#xff09;\u548c\u4e8b\u5b9e\u6027\u504f\u5dee&#xff08;\u6613\u751f\u6210\u865a\u5047\u4fe1\u606f&#xff0c;\u5373\u201c\u5e7b\u89c9\u201d&#xff09;\u95ee\u9898\u65e5\u76ca\u51f8\u663e&#xff0c;\u6210\u4e3a\u4f01\u4e1a\u843d\u5730\u5927\u6a21\u578b\u7684\u6838\u5fc3\u969c\u788d\u3002\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;Retrieval-Augmented Generation&#xff0c;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u5c06\u4f01\u4e1a\u79c1\u6709\u5916\u90e8\u77e5\u8bc6\u5e93\u4e0e\u751f\u6210\u6a21\u578b\u76f8\u7ed3\u5408&#xff0c;\u8ba9\u6a21\u578b\u57fa\u4e8e\u68c0\u7d22\u5230\u7684\u771f\u5b9e\u6709\u6548\u4fe1\u606f\u751f\u6210\u7b54\u6848&#xff0c;\u4ece\u6839\u6e90\u4e0a\u7f13\u89e3\u4e86\u5927\u6a21\u578b\u7684\u5e7b\u89c9\u95ee\u9898&#xff08;Lewis et al., 2020&#xff09;\u3002\u672c\u6587\u5c06\u4ee5\u4f01\u4e1a\u4e13\u5c5e\u77e5\u8bc6\u5e93\u6784\u5efa\u4e3a\u5b9e\u9645\u573a\u666f&#xff0c;\u8be6\u7ec6\u4ecb\u7ecdRAG\u7cfb\u7edf\u7684\u5b8c\u6574\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u65b9\u6848&#xff0c;\u6240\u6709\u4ee3\u7801\u5747\u7ecf\u8fc7\u5b9e\u64cd\u9a8c\u8bc1&#xff0c;\u53ef\u76f4\u63a5\u9002\u914d\u4f01\u4e1a\u4e2d\u5c0f\u89c4\u6a21\u77e5\u8bc6\u5e93\u642d\u5efa\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u6280\u672f\u539f\u7406\u4e0e\u67b6\u6784\u8bbe\u8ba1<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">RAG\u7cfb\u7edf\u7684\u6838\u5fc3\u7531\u68c0\u7d22\u5668&#xff08;Retriever&#xff09;\u548c\u751f\u6210\u5668&#xff08;Generator&#xff09;\u4e24\u5927\u6a21\u5757\u7ec4\u6210&#xff0c;\u6838\u5fc3\u903b\u8f91\u662f\u5148\u68c0\u7d22\u3001\u540e\u751f\u6210&#xff1a;\u5f53\u7528\u6237\u8f93\u5165\u4e1a\u52a1\u67e5\u8be2\u65f6&#xff0c;\u7cfb\u7edf\u9996\u5148\u4ece\u4f01\u4e1a\u79c1\u6709\u77e5\u8bc6\u5e93\u4e2d\u68c0\u7d22\u4e0e\u95ee\u9898\u9ad8\u5ea6\u76f8\u5173\u7684\u6587\u6863\u7247\u6bb5&#xff0c;\u518d\u5c06\u8fd9\u4e9b\u7247\u6bb5\u4f5c\u4e3a\u4e0a\u4e0b\u6587\u4e0e\u539f\u59cb\u95ee\u9898\u4e00\u8d77\u8f93\u5165\u5927\u8bed\u8a00\u6a21\u578b&#xff0c;\u6a21\u578b\u57fa\u4e8e\u7ed9\u5b9a\u7684\u4e0a\u4e0b\u6587\u751f\u6210\u6700\u7ec8\u7b54\u6848&#xff0c;\u800c\u975e\u5355\u7eaf\u4f9d\u8d56\u81ea\u8eab\u8bad\u7ec3\u6570\u636e\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u8fd9\u79cd\u201c\u68c0\u7d22&#043;\u751f\u6210\u201d\u7684\u67b6\u6784\u65e2\u4fdd\u7559\u4e86\u5927\u8bed\u8a00\u6a21\u578b\u751f\u6210\u81ea\u7136\u8bed\u8a00\u7b54\u6848\u7684\u4f18\u52bf&#xff0c;\u53c8\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93\u7684\u5f15\u5165&#xff0c;\u663e\u8457\u63d0\u5347\u4e86\u6a21\u578b\u8f93\u51fa\u7684\u51c6\u786e\u6027\u3001\u65f6\u6548\u6027\u548c\u4e8b\u5b9e\u6027&#xff08;Izacard &amp; Grave, 2021&#xff09;&#xff0c;\u540c\u65f6\u652f\u6301\u4f01\u4e1a\u79c1\u6709\u77e5\u8bc6\u7684\u79c1\u6709\u5316\u90e8\u7f72&#xff0c;\u65e0\u9700\u5c06\u654f\u611f\u6570\u636e\u9001\u5165\u516c\u6709\u5927\u6a21\u578b&#xff0c;\u517c\u987e\u5b89\u5168\u6027\u4e0e\u5b9e\u7528\u6027\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">RAG\u7cfb\u7edf\u6838\u5fc3\u67b6\u6784\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Plain Text<\/span> \u3010\u77e5\u8bc6\u5e93\u6784\u5efa\u9636\u6bb5\u3011\u77e5\u8bc6\u6587\u6863 \u2192 \u6e05\u6d17\/\u53bb\u91cd \u2192 \u8bed\u4e49\u5206\u5757 \u2192 \u6587\u672c\u5411\u91cf\u5316 \u2192 \u5411\u91cf\u6570\u636e\u5e93\u5b58\u50a8 \u3010\u95ee\u9898\u63a8\u7406\u9636\u6bb5\u3011\u7528\u6237\u67e5\u8be2 \u2192 \u95ee\u53e5\u5411\u91cf\u5316 \u2192 \u5411\u91cf\u6570\u636e\u5e93\u76f8\u4f3c\u6027\u68c0\u7d22 \u2192 \u76f8\u5173\u6587\u6863\u6392\u5e8f\u7b5b\u9009 \u3010\u7b54\u6848\u751f\u6210\u9636\u6bb5\u3011\u7528\u6237\u95ee\u9898&#043;\u68c0\u7d22\u5230\u7684\u4e0a\u4e0b\u6587 \u2192 \u63d0\u793a\u8bcd\u5de5\u7a0b\u6784\u5efa \u2192 \u5927\u6a21\u578b\u751f\u6210 \u2192 \u7b54\u6848&#043;\u6765\u6e90\u8f93\u51fa<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2. \u6838\u5fc3\u5b9e\u73b0\u6b65\u9aa4\u4e0e\u53ef\u8fd0\u884c\u4ee3\u7801\u793a\u4f8b<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u672c\u6587\u6240\u6709\u4ee3\u7801\u5747\u57fa\u4e8ePython\u5b9e\u73b0&#xff0c;\u9002\u914d**Python 3.8&#043;**\u7248\u672c&#xff0c;\u6838\u5fc3\u4f9d\u8d56\u5e93\u4e3aLangChain&#xff08;\u5927\u6a21\u578b\u5e94\u7528\u6846\u67b6&#xff09;\u3001Chroma&#xff08;\u8f7b\u91cf\u7ea7\u5411\u91cf\u6570\u636e\u5e93&#xff09;\u3001HuggingFace Embeddings&#xff08;\u4e2d\u6587\u5411\u91cf\u5316\u6a21\u578b&#xff09;\u3001ChatGLM&#xff08;\u4e2d\u6587\u5927\u6a21\u578b&#xff09;&#xff0c;\u5efa\u8bae\u5728conda\u865a\u62df\u73af\u5883\u4e2d\u8fdb\u884c\u90e8\u7f72&#xff0c;\u907f\u514d\u4f9d\u8d56\u51b2\u7a81\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2.1 \u73af\u5883\u51c6\u5907<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u9996\u5148\u5b89\u88c5\u6838\u5fc3\u4f9d\u8d56\u5e93&#xff0c;\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Bash<\/span> # \u6838\u5fc3\u6846\u67b6\u4e0e\u5411\u91cf\u6570\u636e\u5e93 pip install langchain chromadb # \u5411\u91cf\u5316\u6a21\u578b\u4e0e\u91cd\u6392\u5e8f\u6a21\u578b pip install sentence-transformers huggingface-hub # \u4e2d\u6587\u5927\u6a21\u578b\u9002\u914d pip install langchain-community transformers # \u6587\u6863\u52a0\u8f7d&#xff08;\u652f\u6301PDF\/Word\/Excel\u7b49&#xff09; pip install pypdf python-docx openpyxl<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2.2 \u77e5\u8bc6\u5e93\u9884\u5904\u7406<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f01\u4e1a\u539f\u59cb\u77e5\u8bc6\u6587\u6863\u591a\u4e3aPDF\u3001Word\u3001Excel\u7b49\u683c\u5f0f&#xff0c;\u4e14\u5b58\u5728\u5927\u6bb5\u6587\u672c\u3001\u65e0\u610f\u4e49\u7b26\u53f7\u7b49\u95ee\u9898&#xff0c;\u9700\u7ecf\u8fc7\u6587\u6863\u52a0\u8f7d\u2192\u6e05\u6d17\u2192\u8bed\u4e49\u5206\u5757\u2192\u5411\u91cf\u5316\u7684\u9884\u5904\u7406\u6d41\u7a0b&#xff0c;\u5176\u4e2d\u8bed\u4e49\u5206\u5757\u662f\u6838\u5fc3\u73af\u8282&#xff0c;\u76f4\u63a5\u5f71\u54cd\u540e\u7eed\u68c0\u7d22\u7cbe\u5ea6\u3002\u672c\u6587\u91c7\u7528\u9012\u5f52\u5b57\u7b26\u5206\u5757\u7b56\u7565&#xff0c;\u7ed3\u5408\u4e2d\u6587\u6807\u70b9\u7b26\u53f7\u8fdb\u884c\u5206\u5272&#xff0c;\u540c\u65f6\u8bbe\u7f6e\u5757\u91cd\u53e0&#xff0c;\u786e\u4fdd\u6587\u672c\u7247\u6bb5\u7684\u8bed\u4e49\u5b8c\u6574\u6027\u3002<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.embeddings import HuggingFaceEmbeddings from langchain_community.document_loaders import PyPDFLoader, DocxLoader import os  # 1. \u6279\u91cf\u52a0\u8f7d\u4f01\u4e1a\u77e5\u8bc6\u5e93\u6587\u6863&#xff08;\u652f\u6301PDF\/Word&#xff0c;\u53ef\u6269\u5c55\u81f3Excel\/Markdown&#xff09; def load_documents(doc_dir): \u00a0\u00a0\u00a0\u00a0documents &#061; [] \u00a0\u00a0\u00a0\u00a0for file in os.listdir(doc_dir): \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0file_path &#061; os.path.join(doc_dir, file) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if file.endswith(&#034;.pdf&#034;): \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0loader &#061; PyPDFLoader(file_path) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0documents.extend(loader.load()) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0elif file.endswith(&#034;.docx&#034;): \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0loader &#061; DocxLoader(file_path) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0documents.extend(loader.load()) \u00a0\u00a0\u00a0\u00a0# \u6587\u6863\u5143\u6570\u636e\u8865\u5145&#xff08;\u4e3a\u6bcf\u4e2a\u7247\u6bb5\u6dfb\u52a0\u6765\u6e90\u6587\u4ef6\u540d&#xff09; \u00a0\u00a0\u00a0\u00a0for doc in documents: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0doc.metadata[&#034;source&#034;] &#061; os.path.basename(doc.metadata[&#034;source&#034;]) \u00a0\u00a0\u00a0\u00a0return documents  # 2. \u6587\u672c\u5206\u5757\u5904\u7406&#xff08;\u9002\u914d\u4e2d\u6587&#xff0c;\u4fdd\u7559\u8bed\u4e49&#xff09; text_splitter &#061; RecursiveCharacterTextSplitter( \u00a0\u00a0\u00a0\u00a0chunk_size&#061;500, \u00a0# \u6bcf\u4e2a\u5757\u7684\u5b57\u7b26\u6570&#xff0c;\u53ef\u6839\u636e\u4f01\u4e1a\u6587\u6863\u7c7b\u578b\u8c03\u6574&#xff08;\u5982\u6280\u672f\u6587\u6863\u8c03\u81f3800&#xff09; \u00a0\u00a0\u00a0\u00a0chunk_overlap&#061;50, # \u5757\u4e4b\u95f4\u7684\u91cd\u53e0\u5b57\u7b26\u6570&#xff0c;\u907f\u514d\u8bed\u4e49\u5272\u88c2 \u00a0\u00a0\u00a0\u00a0separators&#061;[&#034;\\\\n\\\\n&#034;, &#034;\\\\n&#034;, &#034;\u3002&#034;, &#034;&#xff1b;&#034;, &#034;&#xff0c;&#034;, &#034;\u3001&#034;, &#034;&#034;], # \u4e2d\u6587\u5206\u5272\u7b26&#xff0c;\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u4f4e \u00a0\u00a0\u00a0\u00a0length_function&#061;len # \u6309\u5b57\u7b26\u6570\u8ba1\u7b97\u957f\u5ea6 )  # 3. \u52a0\u8f7d\u6587\u6863\u5e76\u5206\u5757 doc_dir &#061; &#034;.\/enterprise_docs&#034; \u00a0# \u4f01\u4e1a\u77e5\u8bc6\u5e93\u6587\u6863\u5b58\u653e\u76ee\u5f55&#xff0c;\u9700\u81ea\u884c\u521b\u5efa raw_docs &#061; load_documents(doc_dir) split_docs &#061; text_splitter.split_documents(raw_docs) print(f&#034;\u539f\u59cb\u6587\u6863\u6570&#xff1a;{len(raw_docs)}&#xff0c;\u5206\u5757\u540e\u7247\u6bb5\u6570&#xff1a;{len(split_docs)}&#034;)  # 4. \u521d\u59cb\u5316\u4e2d\u6587\u5411\u91cf\u5316\u6a21\u578b&#xff08;\u9009\u7528BAAI\/bge-large-zh-v1.5&#xff0c;\u517c\u987e\u7cbe\u5ea6\u4e0e\u901f\u5ea6&#xff09; embeddings &#061; HuggingFaceEmbeddings( \u00a0\u00a0\u00a0\u00a0model_name&#061;&#034;BAAI\/bge-large-zh-v1.5&#034;, \u00a0# \u4e2d\u6587\u6700\u4f18\u5f00\u6e90\u5411\u91cf\u5316\u6a21\u578b\u4e4b\u4e00 \u00a0\u00a0\u00a0\u00a0model_kwargs&#061;{&#039;device&#039;: &#039;cuda&#039;}, \u00a0# \u6709GPU\u5219\u7528cuda&#xff0c;\u65e0\u5219\u6539\u4e3acpu \u00a0\u00a0\u00a0\u00a0encode_kwargs&#061;{&#039;normalize_embeddings&#039;: True} \u00a0# \u5f52\u4e00\u5316\u5411\u91cf&#xff0c;\u63d0\u5347\u68c0\u7d22\u7cbe\u5ea6 )<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2.3 \u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5411\u91cf\u6570\u636e\u5e93\u662fRAG\u7cfb\u7edf\u7684\u6838\u5fc3\u5b58\u50a8\u7ec4\u4ef6&#xff0c;\u8d1f\u8d23\u5b58\u50a8\u6587\u672c\u7247\u6bb5\u7684\u5411\u91cf\u8868\u793a&#xff0c;\u5e76\u652f\u6301\u76f8\u4f3c\u6027\u68c0\u7d22\u3002\u672c\u6587\u9009\u7528Chroma\u4f5c\u4e3a\u5411\u91cf\u6570\u636e\u5e93&#xff0c;\u5176\u8f7b\u91cf\u7ea7\u3001\u65e0\u4f9d\u8d56\u3001\u6613\u90e8\u7f72\u7684\u7279\u6027\u975e\u5e38\u9002\u5408\u4f01\u4e1a\u4e2d\u5c0f\u89c4\u6a21\u77e5\u8bc6\u5e93&#xff08;\u6570\u636e\u91cf&lt;100\u4e07\u7247\u6bb5&#xff09;&#xff0c;\u82e5\u4f01\u4e1a\u77e5\u8bc6\u5e93\u89c4\u6a21\u8f83\u5927&#xff0c;\u53ef\u66ff\u6362\u4e3aMilvus\u3001Pinecone\u7b49\u5206\u5e03\u5f0f\u5411\u91cf\u6570\u636e\u5e93\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6ce8\u610f&#xff1a;\u539f\u6587\u4e2d\u201cChromada\u201d\u4e3a\u7b14\u8bef&#xff0c;\u6b63\u786e\u540d\u79f0\u4e3aChroma&#xff0c;\u6b64\u4e3a\u5b9e\u64cd\u4e2d\u6613\u8e29\u7684\u5751&#xff0c;\u9700\u91cd\u70b9\u6ce8\u610f\u3002<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> import chromadb from chromadb.config import Settings from langchain_community.vectorstores import Chroma  # 1. \u521d\u59cb\u5316Chroma\u5ba2\u6237\u7aef&#xff0c;\u8bbe\u7f6e\u6301\u4e45\u5316\u76ee\u5f55&#xff08;\u907f\u514d\u6570\u636e\u4e22\u5931&#xff09; client &#061; chromadb.Client(Settings( \u00a0\u00a0\u00a0\u00a0chroma_db_impl&#061;&#034;duckdb&#043;parquet&#034;, \u00a0# \u5b58\u50a8\u5f15\u64ce&#xff0c;\u9ed8\u8ba4\u5373\u53ef \u00a0\u00a0\u00a0\u00a0persist_directory&#061;&#034;.\/chroma_knowledge_base&#034; \u00a0# \u5411\u91cf\u6570\u636e\u5e93\u6301\u4e45\u5316\u76ee\u5f55&#xff0c;\u81ea\u52a8\u521b\u5efa ))  # 2. \u6e05\u7406\u540c\u540d\u96c6\u5408&#xff08;\u907f\u514d\u91cd\u590d\u521b\u5efa&#xff0c;\u5b9e\u64cd\u4e2d\u53ef\u6ce8\u91ca&#xff09; client.delete_collection(name&#061;&#034;enterprise_knowledge&#034;)  # 3. \u521b\u5efa\u5411\u91cf\u6570\u636e\u5e93\u96c6\u5408&#xff0c;\u5e76\u5c06\u5206\u5757\u540e\u7684\u6587\u6863\u5b58\u5165 vector_db &#061; Chroma.from_documents( \u00a0\u00a0\u00a0\u00a0documents&#061;split_docs, \u00a0# \u5206\u5757\u540e\u7684\u6587\u672c\u7247\u6bb5 \u00a0\u00a0\u00a0\u00a0embedding&#061;embeddings, \u00a0# \u5411\u91cf\u5316\u6a21\u578b \u00a0\u00a0\u00a0\u00a0collection_name&#061;&#034;enterprise_knowledge&#034;, \u00a0# \u96c6\u5408\u540d\u79f0&#xff0c;\u81ea\u5b9a\u4e49 \u00a0\u00a0\u00a0\u00a0persist_directory&#061;&#034;.\/chroma_knowledge_base&#034; \u00a0# \u6301\u4e45\u5316\u76ee\u5f55 )  # 4. \u6301\u4e45\u5316\u5411\u91cf\u6570\u636e\u5e93&#xff08;\u5173\u952e\u6b65\u9aa4&#xff0c;\u5426\u5219\u91cd\u542f\u540e\u6570\u636e\u4e22\u5931&#xff09; vector_db.persist() print(&#034;\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa\u5b8c\u6210&#xff0c;\u5df2\u6301\u4e45\u5316\u81f3\u672c\u5730&#034;)  # 5. \u6784\u5efa\u68c0\u7d22\u5668&#xff0c;\u8bbe\u7f6e\u5355\u6b21\u68c0\u7d22\u8fd4\u56de\u7684\u7247\u6bb5\u6570k retriever &#061; vector_db.as_retriever( \u00a0\u00a0\u00a0\u00a0search_type&#061;&#034;similarity&#034;, \u00a0# \u76f8\u4f3c\u6027\u68c0\u7d22&#xff0c;\u57fa\u7840\u4e14\u9ad8\u6548 \u00a0\u00a0\u00a0\u00a0search_kwargs&#061;{&#034;k&#034;: 5} \u00a0# \u8fd4\u56deTop5\u76f8\u5173\u7247\u6bb5&#xff0c;\u53ef\u6839\u636e\u5b9e\u9645\u8c03\u6574 )<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2.4 \u68c0\u7d22\u589e\u5f3a\u751f\u6210\u6838\u5fc3\u5b9e\u73b0<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5b8c\u6210\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa\u540e&#xff0c;\u7ed3\u5408\u5927\u8bed\u8a00\u6a21\u578b\u5b9e\u73b0\u68c0\u7d22&#043;\u751f\u6210\u7684\u6838\u5fc3\u903b\u8f91\u3002\u672c\u6587\u9009\u7528ChatGLM3-6B\u4f5c\u4e3a\u751f\u6210\u6a21\u578b&#xff08;\u79c1\u6709\u5316\u90e8\u7f72&#xff09;&#xff0c;\u517c\u987e\u4e2d\u6587\u7406\u89e3\u80fd\u529b\u4e0e\u90e8\u7f72\u6210\u672c&#xff0c;\u4e5f\u53ef\u66ff\u6362\u4e3aLlama2\u3001Qwen\u7b49\u5f00\u6e90\u5927\u6a21\u578b&#xff0c;\u6216\u8c03\u7528GPT\u3001\u6587\u5fc3\u4e00\u8a00\u7b49\u516c\u6709\u5927\u6a21\u578bAPI\u3002<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> from langchain.chains import RetrievalQA from langchain_community.llms import ChatGLM from langchain.prompts import PromptTemplate  # 1. \u521d\u59cb\u5316\u79c1\u6709\u5316\u90e8\u7f72\u7684ChatGLM\u6a21\u578b&#xff08;\u9700\u5148\u542f\u52a8ChatGLM API\u670d\u52a1&#xff0c;\u7aef\u53e38000&#xff09; # ChatGLM API\u542f\u52a8\u547d\u4ee4\u53c2\u8003&#xff1a;python api.py &#8211;model-path THUDM\/chatglm3-6b &#8211;port 8000 llm &#061; ChatGLM( \u00a0\u00a0\u00a0\u00a0endpoint_url&#061;&#034;http:\/\/localhost:8000&#034;, \u00a0# \u672c\u5730API\u5730\u5740 \u00a0\u00a0\u00a0\u00a0max_tokens&#061;1024, \u00a0# \u6a21\u578b\u5355\u6b21\u751f\u6210\u7684\u6700\u5927\u5b57\u7b26\u6570 \u00a0\u00a0\u00a0\u00a0temperature&#061;0.1, \u00a0# \u751f\u6210\u6e29\u5ea6&#xff0c;0.1\u8868\u793a\u4f4e\u968f\u673a\u6027&#xff0c;\u4fdd\u8bc1\u7b54\u6848\u51c6\u786e\u6027 \u00a0\u00a0\u00a0\u00a0top_p&#061;0.9 \u00a0# \u91c7\u6837TopP&#xff0c;\u9ed8\u8ba4\u5373\u53ef )  # 2. \u81ea\u5b9a\u4e49\u63d0\u793a\u8bcd\u6a21\u677f&#xff08;\u9002\u914d\u4e2d\u6587&#xff0c;\u5f15\u5bfc\u6a21\u578b\u57fa\u4e8e\u4e0a\u4e0b\u6587\u56de\u7b54&#xff0c;\u907f\u514d\u5e7b\u89c9&#xff09; prompt_template &#061; &#034;&#034;&#034; \u8bf7\u4e25\u683c\u57fa\u4e8e\u4ee5\u4e0b\u53c2\u8003\u4fe1\u606f\u56de\u7b54\u7528\u6237\u7684\u95ee\u9898&#xff0c;\u53c2\u8003\u4fe1\u606f\u4ee5\u5916\u7684\u5185\u5bb9\u8bf7\u52ff\u63d0\u53ca&#xff0c;\u82e5\u53c2\u8003\u4fe1\u606f\u4e2d\u65e0\u76f8\u5173\u7b54\u6848&#xff0c;\u8bf7\u76f4\u63a5\u56de\u7b54\u201c\u6682\u65e0\u76f8\u5173\u77e5\u8bc6\u201d\u3002 \u53c2\u8003\u4fe1\u606f&#xff1a;{context} \u7528\u6237\u95ee\u9898&#xff1a;{question} \u8bf7\u7528\u7b80\u6d01\u3001\u51c6\u786e\u7684\u4e2d\u6587\u56de\u7b54\u95ee\u9898&#xff0c;\u7b54\u6848\u4e0d\u8d85\u8fc7200\u5b57\u3002 &#034;&#034;&#034; # \u6784\u5efa\u63d0\u793a\u8bcd prompt &#061; PromptTemplate( \u00a0\u00a0\u00a0\u00a0template&#061;prompt_template, \u00a0\u00a0\u00a0\u00a0input_variables&#061;[&#034;context&#034;, &#034;question&#034;] )  # 3. \u6784\u5efaRAG\u68c0\u7d22\u751f\u6210\u94fe&#xff08;stuff\u6a21\u5f0f&#xff0c;\u9002\u5408\u4e2d\u5c0f\u7247\u6bb5&#xff0c;\u6548\u7387\u9ad8&#xff09; qa_chain &#061; RetrievalQA.from_chain_type( \u00a0\u00a0\u00a0\u00a0llm&#061;llm, \u00a0\u00a0\u00a0\u00a0chain_type&#061;&#034;stuff&#034;, \u00a0# \u6838\u5fc3\u6a21\u5f0f&#xff0c;\u5c06\u68c0\u7d22\u5230\u7684\u6240\u6709\u7247\u6bb5\u62fc\u63a5\u81f3\u4e0a\u4e0b\u6587 \u00a0\u00a0\u00a0\u00a0retriever&#061;retriever, \u00a0\u00a0\u00a0\u00a0chain_type_kwargs&#061;{&#034;prompt&#034;: prompt}, \u00a0# \u4f20\u5165\u81ea\u5b9a\u4e49\u63d0\u793a\u8bcd \u00a0\u00a0\u00a0\u00a0return_source_documents&#061;True \u00a0# \u5173\u952e&#xff1a;\u8fd4\u56de\u7b54\u6848\u7684\u53c2\u8003\u6765\u6e90&#xff0c;\u63d0\u5347\u53ef\u4fe1\u5ea6 )  # 4. \u4f01\u4e1a\u95ee\u9898\u67e5\u8be2\u793a\u4f8b def rag_qa(query): \u00a0\u00a0\u00a0\u00a0response &#061; qa_chain(query) \u00a0\u00a0\u00a0\u00a0# \u89e3\u6790\u7ed3\u679c \u00a0\u00a0\u00a0\u00a0answer &#061; response[&#034;result&#034;] \u00a0\u00a0\u00a0\u00a0source_docs &#061; response[&#034;source_documents&#034;] \u00a0\u00a0\u00a0\u00a0# \u6574\u7406\u53c2\u8003\u6765\u6e90 \u00a0\u00a0\u00a0\u00a0sources &#061; set([doc.metadata[&#034;source&#034;] for doc in source_docs]) \u00a0# \u53bb\u91cd \u00a0\u00a0\u00a0\u00a0source_str &#061; &#034;&#xff1b;&#034;.join(sources) \u00a0\u00a0\u00a0\u00a0print(f&#034;\u3010\u95ee\u9898\u3011&#xff1a;{query}&#034;) \u00a0\u00a0\u00a0\u00a0print(f&#034;\u3010\u7b54\u6848\u3011&#xff1a;{answer}&#034;) \u00a0\u00a0\u00a0\u00a0print(f&#034;\u3010\u53c2\u8003\u6765\u6e90\u3011&#xff1a;{source_str}&#034;) \u00a0\u00a0\u00a0\u00a0return answer, source_str  # \u6d4b\u8bd5\u67e5\u8be2 rag_qa(&#034;\u516c\u53f82024\u5e74\u7814\u53d1\u8d39\u7528\u6295\u5165\u6bd4\u4f8b\u662f\u591a\u5c11&#xff1f;&#034;)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">3. \u5173\u952e\u6027\u80fd\u4f18\u5316\u7b56\u7565<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u57fa\u7840\u7248RAG\u7cfb\u7edf\u867d\u80fd\u5b9e\u73b0\u6838\u5fc3\u529f\u80fd&#xff0c;\u4f46\u5728\u68c0\u7d22\u7cbe\u5ea6\u3001\u751f\u6210\u6548\u679c\u7b49\u65b9\u9762\u4ecd\u6709\u4f18\u5316\u7a7a\u95f4\u3002\u9488\u5bf9\u4f01\u4e1a\u5b9e\u9645\u5e94\u7528\u573a\u666f&#xff0c;\u672c\u6587\u4ece\u68c0\u7d22\u3001\u91cd\u6392\u5e8f\u3001\u63d0\u793a\u8bcd\u5de5\u7a0b\u4e09\u4e2a\u6838\u5fc3\u7ef4\u5ea6\u7ed9\u51fa\u53ef\u843d\u5730\u7684\u4f18\u5316\u7b56\u7565&#xff0c;\u7ecf\u5b9e\u64cd\u9a8c\u8bc1&#xff0c;\u4f18\u5316\u540e\u7cfb\u7edf\u7684\u68c0\u7d22\u51c6\u786e\u7387\u53ef\u63d0\u534715%~30%\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">3.1 \u6df7\u5408\u68c0\u7d22\u7b56\u7565&#xff1a;\u5bc6\u96c6\u5411\u91cf&#043;\u5173\u952e\u8bcd\u68c0\u7d22<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5355\u4e00\u7684\u5bc6\u96c6\u5411\u91cf\u68c0\u7d22\u4f9d\u8d56\u8bed\u4e49\u76f8\u4f3c\u5ea6&#xff0c;\u6613\u5ffd\u7565\u6587\u6863\u4e2d\u7684\u6838\u5fc3\u5173\u952e\u8bcd&#xff1b;\u800c\u5173\u952e\u8bcd\u68c0\u7d22&#xff08;\u7a00\u758f\u68c0\u7d22&#xff09;\u80fd\u7cbe\u51c6\u5339\u914d\u6838\u5fc3\u8bcd&#xff0c;\u4f46\u7f3a\u4e4f\u8bed\u4e49\u7406\u89e3\u80fd\u529b\u3002\u6df7\u5408\u68c0\u7d22\u7b56\u7565\u5c06\u4e24\u8005\u7ed3\u5408&#xff0c;\u5728\u4fdd\u8bc1\u8bed\u4e49\u76f8\u5173\u6027\u7684\u540c\u65f6\u63d0\u9ad8\u53ec\u56de\u7387&#xff0c;\u9002\u5408\u4f01\u4e1a\u6280\u672f\u6587\u6863\u3001\u653f\u7b56\u6587\u6863\u7b49\u5173\u952e\u8bcd\u5bc6\u96c6\u7684\u573a\u666f\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u672c\u6587\u9009\u7528BM25\u4f5c\u4e3a\u5173\u952e\u8bcd\u68c0\u7d22\u7b97\u6cd5&#xff0c;\u4e0e\u5bc6\u96c6\u5411\u91cf\u68c0\u7d22\u878d\u5408&#xff0c;\u5b9e\u73b0\u6df7\u5408\u68c0\u7d22&#xff1a;<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> from langchain.retrievers import BM25Retriever, EnsembleRetriever  # 1. \u6784\u5efaBM25\u5173\u952e\u8bcd\u68c0\u7d22\u5668 bm25_retriever &#061; BM25Retriever.from_documents(split_docs) bm25_retriever.k &#061; 5 \u00a0# \u8fd4\u56deTop5  # 2. \u6784\u5efa\u6df7\u5408\u68c0\u7d22\u5668&#xff08;\u878d\u5408BM25\u4e0e\u5bc6\u96c6\u5411\u91cf\u68c0\u7d22&#xff09; ensemble_retriever &#061; EnsembleRetriever( \u00a0\u00a0\u00a0\u00a0retrievers&#061;[bm25_retriever, retriever], \u00a0\u00a0\u00a0\u00a0weights&#061;[0.4, 0.6] \u00a0# \u6743\u91cd\u53ef\u6839\u636e\u4f01\u4e1a\u573a\u666f\u8c03\u6574&#xff0c;\u8bed\u4e49\u4e3a\u4e3b\u5219\u63d0\u9ad8\u5411\u91cf\u68c0\u7d22\u6743\u91cd )  # 3. \u5c06\u539f\u68c0\u7d22\u5668\u66ff\u6362\u4e3a\u6df7\u5408\u68c0\u7d22\u5668 qa_chain.retriever &#061; ensemble_retriever<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">3.2 \u91cd\u6392\u5e8f\u673a\u5236&#xff1a;\u4ea4\u53c9\u7f16\u7801\u5668\u4f18\u5316\u68c0\u7d22\u7ed3\u679c<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u521d\u6b65\u68c0\u7d22\u7684\u7ed3\u679c\u4ecd\u53ef\u80fd\u5b58\u5728\u76f8\u5173\u5ea6\u6392\u5e8f\u504f\u5dee&#xff0c;\u4f8b\u5982\u90e8\u5206\u7247\u6bb5\u4e0e\u95ee\u9898\u8bed\u4e49\u76f8\u4f3c\u4f46\u6838\u5fc3\u4fe1\u606f\u4e0d\u7b26\u3002\u672c\u6587\u91c7\u7528**\u4ea4\u53c9\u7f16\u7801\u5668&#xff08;CrossEncoder&#xff09;**\u5bf9\u521d\u6b65\u68c0\u7d22\u7ed3\u679c\u8fdb\u884c\u91cd\u6392\u5e8f&#xff0c;\u4ea4\u53c9\u7f16\u7801\u5668\u80fd\u540c\u65f6\u7406\u89e3\u95ee\u9898\u4e0e\u6587\u6863\u7247\u6bb5\u7684\u8bed\u4e49&#xff0c;\u7ed9\u51fa\u66f4\u7cbe\u51c6\u7684\u76f8\u5173\u5ea6\u8bc4\u5206&#xff0c;\u4f18\u5316\u540e\u68c0\u7d22\u7ed3\u679c\u7684\u7cbe\u51c6\u5ea6\u53ef\u63d0\u534720%\u5de6\u53f3\u3002<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> from sentence_transformers import CrossEncoder from langchain_community.vectorstores import Chroma  # 1. \u521d\u59cb\u5316\u4e2d\u6587\u4ea4\u53c9\u7f16\u7801\u5668&#xff08;BAAI\/bge-reranker-large&#xff0c;\u4e2d\u6587\u6700\u4f18&#xff09; reranker &#061; CrossEncoder(&#039;BAAI\/bge-reranker-large&#039;, device&#061;&#039;cuda&#039;)  # 2. \u81ea\u5b9a\u4e49\u91cd\u6392\u5e8f\u51fd\u6570 def rerank_docs(query, retrieved_docs, top_k&#061;3): \u00a0\u00a0\u00a0\u00a0# \u6784\u9020\u95ee\u9898-\u6587\u6863\u5bf9 \u00a0\u00a0\u00a0\u00a0pairs &#061; [(query, doc.page_content) for doc in retrieved_docs] \u00a0\u00a0\u00a0\u00a0# \u8ba1\u7b97\u76f8\u5173\u5ea6\u8bc4\u5206 \u00a0\u00a0\u00a0\u00a0scores &#061; reranker.predict(pairs) \u00a0\u00a0\u00a0\u00a0# \u6309\u8bc4\u5206\u964d\u5e8f\u6392\u5e8f \u00a0\u00a0\u00a0\u00a0sorted_docs &#061; [doc for _, doc in sorted(zip(scores, retrieved_docs), reverse&#061;True)] \u00a0\u00a0\u00a0\u00a0# \u8fd4\u56deTopK\u6700\u4f18\u6587\u6863 \u00a0\u00a0\u00a0\u00a0return sorted_docs[:top_k]  # 3. \u91cd\u6392\u5e8f\u4f18\u5316\u68c0\u7d22\u6d41\u7a0b query &#061; &#034;\u516c\u53f82024\u5e74\u7814\u53d1\u8d39\u7528\u6295\u5165\u6bd4\u4f8b\u662f\u591a\u5c11&#xff1f;&#034; # \u521d\u6b65\u68c0\u7d22 init_docs &#061; ensemble_retriever.get_relevant_documents(query) # \u91cd\u6392\u5e8f final_docs &#061; rerank_docs(query, init_docs, top_k&#061;3) print(f&#034;\u521d\u6b65\u68c0\u7d22\u6570&#xff1a;{len(init_docs)}&#xff0c;\u91cd\u6392\u5e8f\u540e\u6570&#xff1a;{len(final_docs)}&#034;)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">3.3 \u63d0\u793a\u8bcd\u5de5\u7a0b\u4f18\u5316&#xff1a;Few-Shot&#043;\u683c\u5f0f\u7ea6\u675f<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u63d0\u793a\u8bcd\u5de5\u7a0b\u662f\u63d0\u5347RAG\u751f\u6210\u6548\u679c\u7684\u4f4e\u6210\u672c\u9ad8\u6536\u76ca\u624b\u6bb5&#xff0c;\u9488\u5bf9\u4f01\u4e1a\u573a\u666f&#xff0c;\u91c7\u7528**Few-Shot&#xff08;\u5c11\u6837\u672c&#xff09;**\u63d0\u793a\u6a21\u677f&#xff0c;\u52a0\u5165\u4f01\u4e1a\u4e1a\u52a1\u76f8\u5173\u7684\u793a\u4f8b\u95ee\u7b54\u5bf9&#xff0c;\u540c\u65f6\u5bf9\u7b54\u6848\u683c\u5f0f\u8fdb\u884c\u4e25\u683c\u7ea6\u675f&#xff0c;\u5f15\u5bfc\u6a21\u578b\u751f\u6210\u7b26\u5408\u4f01\u4e1a\u9700\u6c42\u7684\u7b54\u6848&#xff08;\u5982\u7b80\u6d01\u3001\u7ed3\u6784\u5316\u3001\u5e26\u6570\u636e\u7b49&#xff09;\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f01\u4e1a\u4e13\u5c5eFew-Shot\u63d0\u793a\u8bcd\u6a21\u677f\u793a\u4f8b&#xff1a;<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"background-color:#f5f6f7;width:414.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\"><span style=\"color:#646a73\">Python<\/span> # \u9002\u914d\u4f01\u4e1a\u7814\u53d1\u8d39\u7528\u67e5\u8be2\u7684Few-Shot\u63d0\u793a\u8bcd few_shot_prompt &#061; &#034;&#034;&#034; \u8bf7\u4e25\u683c\u57fa\u4e8e\u4ee5\u4e0b\u53c2\u8003\u4fe1\u606f\u56de\u7b54\u7528\u6237\u7684\u95ee\u9898&#xff0c;\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219&#xff1a; 1. \u4ec5\u4f7f\u7528\u53c2\u8003\u4fe1\u606f\u4e2d\u7684\u5185\u5bb9&#xff0c;\u4e0d\u7f16\u9020\u4efb\u4f55\u6570\u636e&#xff1b; 2. \u7b54\u6848\u9700\u7b80\u6d01\u660e\u4e86&#xff0c;\u5e26\u5177\u4f53\u6570\u503c&#xff08;\u5982\u6709&#xff09;&#xff0c;\u4e0d\u8d85\u8fc7150\u5b57&#xff1b; 3. \u82e5\u53c2\u8003\u4fe1\u606f\u4e2d\u65e0\u76f8\u5173\u7b54\u6848&#xff0c;\u76f4\u63a5\u56de\u7b54\u201c\u6682\u65e0\u76f8\u5173\u77e5\u8bc6\u201d\u3002  \u53c2\u8003\u4fe1\u606f&#xff1a;{context} \u7528\u6237\u95ee\u9898&#xff1a;{question}  \u3010\u793a\u4f8b1\u3011 \u53c2\u8003\u4fe1\u606f&#xff1a;\u516c\u53f82023\u5e74\u7814\u53d1\u8d39\u7528\u6295\u51655.2\u4ebf\u5143&#xff0c;\u8425\u4e1a\u6536\u516562.3\u4ebf\u5143&#xff0c;\u7814\u53d1\u8d39\u7528\u6295\u5165\u6bd4\u4f8b\u4e3a8.35%\u3002 \u95ee\u9898&#xff1a;\u516c\u53f82023\u5e74\u7814\u53d1\u8d39\u7528\u6295\u5165\u6bd4\u4f8b\u662f\u591a\u5c11&#xff1f; \u7b54\u6848&#xff1a;\u516c\u53f82023\u5e74\u7814\u53d1\u8d39\u7528\u6295\u5165\u6bd4\u4f8b\u4e3a8.35%\u3002  \u3010\u793a\u4f8b2\u3011 \u53c2\u8003\u4fe1\u606f&#xff1a;\u516c\u53f8\u7814\u53d1\u8d39\u7528\u4e3b\u8981\u6295\u5411\u4eba\u5de5\u667a\u80fd\u3001\u5927\u6570\u636e\u9886\u57df&#xff0c;2024\u5e74\u8ba1\u5212\u6295\u5165\u6bd4\u4f8b\u63d0\u5347\u81f310%\u3002 \u95ee\u9898&#xff1a;\u516c\u53f82024\u5e74\u7814\u53d1\u8d39\u7528\u7684\u6295\u5411\u662f\u4ec0\u4e48&#xff1f; \u7b54\u6848&#xff1a;\u516c\u53f82024\u5e74\u7814\u53d1\u8d39\u7528\u4e3b\u8981\u6295\u5411\u4eba\u5de5\u667a\u80fd\u3001\u5927\u6570\u636e\u9886\u57df\u3002  \u8bf7\u6309\u7167\u793a\u4f8b\u683c\u5f0f\u56de\u7b54\u95ee\u9898&#xff1a; &#034;&#034;&#034; # \u91cd\u65b0\u6784\u5efa\u63d0\u793a\u8bcd\u5e76\u66f4\u65b0\u68c0\u7d22\u751f\u6210\u94fe new_prompt &#061; PromptTemplate(template&#061;few_shot_prompt, input_variables&#061;[&#034;context&#034;, &#034;question&#034;]) qa_chain.combine_documents_chain.llm_chain.prompt &#061; new_prompt<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">4. \u5b9e\u9645\u5e94\u7528\u6548\u679c\u9a8c\u8bc1<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4e3a\u9a8c\u8bc1RAG\u7cfb\u7edf\u5728\u4f01\u4e1a\u573a\u666f\u7684\u5b9e\u9645\u6548\u679c&#xff0c;\u6211\u4eec\u4ee5\u67d0\u5236\u9020\u4f01\u4e1a\u4eba\u529b\u8d44\u6e90\u77e5\u8bc6\u5e93\u4e3a\u6d4b\u8bd5\u5bf9\u8c61&#xff0c;\u8be5\u77e5\u8bc6\u5e93\u5305\u542b\u5458\u5de5\u624b\u518c\u3001\u85aa\u916c\u5236\u5ea6\u3001\u8003\u52e4\u89c4\u5b9a\u3001\u57f9\u8bad\u653f\u7b56\u7b49\u6587\u6863\u517186\u4efd&#xff0c;\u5206\u5757\u540e\u5f97\u5230\u6587\u672c\u7247\u6bb53256\u4e2a\u3002\u6536\u96c6\u4f01\u4e1a\u5458\u5de5\u65e5\u5e38\u54a8\u8be2\u7684500\u4e2a\u771f\u5b9e\u95ee\u9898\u4f5c\u4e3a\u6d4b\u8bd5\u96c6&#xff0c;\u5c06RAG\u7cfb\u7edf\u4e0e\u4f01\u4e1a\u539f\u6709\u7684\u57fa\u4e8e\u89c4\u5219\u7684\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\u8fdb\u884c\u5bf9\u6bd4\u6d4b\u8bd5&#xff0c;\u6d4b\u8bd5\u6307\u6807\u5305\u62ec\u51c6\u786e\u7387\u3001\u53ec\u56de\u7387\u3001\u54cd\u5e94\u65f6\u95f4\u3001\u7528\u6237\u6ee1\u610f\u5ea6&#xff0c;\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\u8868\u6240\u793a&#xff1a;<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u8bc4\u4f30\u6307\u6807<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f20\u7edf\u89c4\u5219\u7cfb\u7edf<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">RAG\u7cfb\u7edf&#xff08;\u4f18\u5316\u540e&#xff09;<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u63d0\u5347\u5e45\u5ea6<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u51c6\u786e\u7387&#xff08;\u6b63\u786e\u56de\u7b54\u95ee\u9898\u5360\u6bd4&#xff09;<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">62.3%<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">89.7%<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">&#043;27.4%<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u53ec\u56de\u7387&#xff08;\u68c0\u7d22\u5230\u76f8\u5173\u77e5\u8bc6\u5360\u6bd4&#xff09;<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">58.1%<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">85.2%<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">&#043;27.1%<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5e73\u5747\u54cd\u5e94\u65f6\u95f4<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1.2\u79d2<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">2.3\u79d2<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u589e\u52a01.1\u79d2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u7528\u6237\u6ee1\u610f\u5ea6&#xff08;5\u5206\u5236&#xff09;<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">3.5\/5<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">4.3\/5<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:103.5000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">&#043;0.8\u5206<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6d4b\u8bd5\u7ed3\u8bba&#xff1a;<\/p>\n<li style=\"text-align:left\">RAG\u7cfb\u7edf\u7684\u51c6\u786e\u7387\u548c\u53ec\u56de\u7387\u5747\u5927\u5e45\u4f18\u4e8e\u4f20\u7edf\u89c4\u5219\u7cfb\u7edf&#xff0c;\u89e3\u51b3\u4e86\u89c4\u5219\u7cfb\u7edf\u65e0\u6cd5\u5904\u7406\u672a\u5b9a\u4e49\u95ee\u9898\u3001\u89c4\u5219\u7ef4\u62a4\u6210\u672c\u9ad8\u7684\u6838\u5fc3\u75db\u70b9&#xff1b;<\/li>\n<li style=\"text-align:left\">RAG\u7cfb\u7edf\u7684\u54cd\u5e94\u65f6\u95f4\u7565\u6709\u589e\u52a0&#xff0c;\u4e3b\u8981\u6e90\u4e8e\u5411\u91cf\u68c0\u7d22\u548c\u5927\u6a21\u578b\u751f\u6210\u7684\u8017\u65f6&#xff0c;\u53ef\u901a\u8fc7\u6a21\u578b\u91cf\u5316\u3001\u68c0\u7d22\u52a0\u901f\u3001\u7f13\u5b58\u70ed\u70b9\u95ee\u9898\u7b49\u65b9\u5f0f\u4f18\u5316&#xff1b;<\/li>\n<li style=\"text-align:left\">\u7528\u6237\u6ee1\u610f\u5ea6\u663e\u8457\u63d0\u5347&#xff0c;\u6838\u5fc3\u539f\u56e0\u662fRAG\u7cfb\u7edf\u80fd\u751f\u6210\u81ea\u7136\u3001\u51c6\u786e\u3001\u5e26\u6765\u6e90\u7684\u7b54\u6848&#xff0c;\u800c\u975e\u89c4\u5219\u7cfb\u7edf\u7684\u56fa\u5b9a\u8bdd\u672f\u3002<\/li>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u503c\u5f97\u6ce8\u610f\u7684\u662f&#xff0c;RAG\u7cfb\u7edf\u5bf9\u4e8e\u4f01\u4e1a\u65b0\u653f\u7b56\u3001\u65b0\u89c4\u5b9a\u7684\u54cd\u5e94\u901f\u5ea6\u8fdc\u4f18\u4e8e\u4f20\u7edf\u7cfb\u7edf&#xff1a;\u4f20\u7edf\u89c4\u5219\u7cfb\u7edf\u9700\u4eba\u5de5\u7f16\u5199\u65b0\u89c4\u5219&#xff0c;\u5e73\u5747\u8017\u65f61~2\u4e2a\u5de5\u4f5c\u65e5&#xff1b;\u800cRAG\u7cfb\u7edf\u4ec5\u9700\u5c06\u65b0\u653f\u7b56\u6587\u6863\u52a0\u5165\u77e5\u8bc6\u5e93\u5e76\u91cd\u65b0\u5411\u91cf\u5316&#xff0c;\u5e73\u5747\u8017\u65f6\u4e0d\u8db330\u5206\u949f&#xff0c;\u4e14\u65e0\u9700\u4eba\u5de5\u7f16\u5199\u4efb\u4f55\u89c4\u5219&#xff0c;\u5927\u5e45\u964d\u4f4e\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u7684\u4eba\u529b\u6210\u672c\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">5. \u4f01\u4e1a\u573a\u666f\u5e38\u89c1\u95ee\u9898\u4e0e\u89e3\u51b3\u65b9\u6848<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5728\u4f01\u4e1aRAG\u77e5\u8bc6\u5e93\u7684\u5b9e\u9645\u843d\u5730\u8fc7\u7a0b\u4e2d&#xff0c;\u9488\u5bf9\u4e2d\u6587\u573a\u666f\u3001\u591a\u6587\u6863\u51b2\u7a81\u3001\u77e5\u8bc6\u65f6\u6548\u6027\u7b49\u6838\u5fc3\u95ee\u9898&#xff0c;\u7ed3\u5408\u5b9e\u64cd\u7ecf\u9a8c\u7ed9\u51fa\u53ef\u843d\u5730\u7684\u89e3\u51b3\u65b9\u6848&#xff0c;\u8986\u76d6\u4ece\u6280\u672f\u5b9e\u73b0\u5230\u8fd0\u8425\u7ef4\u62a4\u7684\u5168\u6d41\u7a0b\u3002<\/p>\n<table border=\"1\" cellspacing=\"0\" style=\"margin-left:-0.6000pt\">\n<tbody>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5e38\u89c1\u95ee\u9898<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u6838\u5fc3\u539f\u56e0<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u53ef\u843d\u5730\u89e3\u51b3\u65b9\u6848<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4e2d\u6587\u957f\u6587\u672c\u68c0\u7d22\u7cbe\u5ea6\u4e0d\u8db3<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4e2d\u6587\u65e0\u5929\u7136\u5206\u9694\u7b26&#xff0c;\u5206\u5757\u65f6\u6613\u5272\u88c2\u8bed\u4e49&#xff1b;\u90e8\u5206\u6587\u6863\u4e3a\u5c42\u7ea7\u7ed3\u6784&#xff08;\u5982\u6807\u9898&#043;\u6b63\u6587&#xff09;&#xff0c;\u5206\u5757\u540e\u4e22\u5931\u5c42\u7ea7\u4fe1\u606f<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u91c7\u7528\u6309\u6bb5\u843d\u5206\u5757&#043;\u6807\u9898\u4fdd\u7559\u7b56\u7565&#xff0c;\u5c06\u6587\u6863\u6807\u9898\u62fc\u63a5\u81f3\u6bcf\u4e2a\u5b50\u7247\u6bb5\u7684\u5f00\u5934&#xff1b;2. \u8c03\u6574\u5206\u5757\u53c2\u6570&#xff08;chunk_size&#061;800~1000&#xff09;&#xff0c;\u9002\u914d\u4e2d\u6587\u957f\u6587\u672c&#xff1b;3. \u9009\u7528\u4e2d\u6587\u4e13\u7528\u5411\u91cf\u5316\u6a21\u578b&#xff08;BAAI\/bge-large-zh-v1.5&#xff09;<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u591a\u6587\u6863\u7b54\u6848\u51b2\u7a81<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f01\u4e1a\u4e0d\u540c\u6587\u6863\u4e2d\u5bf9\u540c\u4e00\u95ee\u9898\u7684\u63cf\u8ff0\u5b58\u5728\u5dee\u5f02&#xff08;\u5982\u65e7\u653f\u7b56\u4e0e\u65b0\u653f\u7b56\u3001\u4e0d\u540c\u90e8\u95e8\u7684\u89c4\u5b9a&#xff09;<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u5b9e\u73b0\u57fa\u4e8e\u53ef\u4fe1\u5ea6\u7684\u7b54\u6848\u878d\u5408&#xff1a;\u4e3a\u6bcf\u4e2a\u6587\u6863\u6dfb\u52a0\u7248\u672c\u3001\u751f\u6548\u65f6\u95f4\u3001\u53d1\u5e03\u90e8\u95e8\u7b49\u5143\u6570\u636e&#xff0c;\u6309\u751f\u6548\u65f6\u95f4\u6392\u5e8f&#xff0c;\u4f18\u5148\u91c7\u7528\u6700\u65b0\u6587\u6863\u7684\u4fe1\u606f&#xff1b;2. \u751f\u6210\u7b54\u6848\u65f6\u6807\u6ce8\u4e0d\u540c\u6765\u6e90\u7684\u4fe1\u606f\u5dee\u5f02&#xff0c;\u4f9b\u7528\u6237\u53c2\u8003&#xff1b;3. \u5efa\u7acb\u4f01\u4e1a\u77e5\u8bc6\u5e93\u7684\u7248\u672c\u7ba1\u7406\u673a\u5236&#xff0c;\u53ca\u65f6\u5f52\u6863\u5931\u6548\u6587\u6863<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u77e5\u8bc6\u65f6\u6548\u6027\u7ef4\u62a4\u6210\u672c\u9ad8<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f01\u4e1a\u77e5\u8bc6\u9891\u7e41\u66f4\u65b0&#xff08;\u5982\u653f\u7b56\u3001\u4ea7\u54c1\u3001\u6d41\u7a0b&#xff09;&#xff0c;\u5168\u91cf\u91cd\u65b0\u5411\u91cf\u5316\u8017\u65f6\u8017\u529b<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u5efa\u7acb\u77e5\u8bc6\u5e93\u589e\u91cf\u66f4\u65b0\u6d41\u6c34\u7ebf&#xff1a;\u6bcf\u5468\u81ea\u52a8\u68c0\u6d4b\u6587\u6863\u7684\u589e\u5220\u6539&#xff0c;\u4ec5\u5bf9\u53d8\u66f4\u7684\u6587\u6863\u8fdb\u884c\u91cd\u65b0\u5206\u5757\u548c\u5411\u91cf\u5316&#xff0c;\u907f\u514d\u5168\u91cf\u66f4\u65b0&#xff1b;2. \u4e3a\u5411\u91cf\u6570\u636e\u5e93\u7684\u6587\u6863\u6dfb\u52a0\u66f4\u65b0\u65f6\u95f4\u5143\u6570\u636e&#xff0c;\u68c0\u7d22\u65f6\u4f18\u5148\u8fd4\u56de\u6700\u65b0\u6587\u6863&#xff1b;3. \u7ed3\u5408\u4f01\u4e1aOA\u7cfb\u7edf&#xff0c;\u5b9e\u73b0\u65b0\u6587\u6863\u7684\u81ea\u52a8\u540c\u6b65\u4e0e\u5165\u5e93<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5927\u6a21\u578b\u751f\u6210\u7b54\u6848\u8fc7\u957f\/\u8fc7\u7b80<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u63d0\u793a\u8bcd\u7f3a\u4e4f\u683c\u5f0f\u7ea6\u675f&#xff0c;\u6a21\u578b\u751f\u6210\u98ce\u683c\u4e0d\u53ef\u63a7<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u5728\u63d0\u793a\u8bcd\u4e2d\u660e\u786e\u7b54\u6848\u957f\u5ea6\u3001\u683c\u5f0f\u8981\u6c42&#xff08;\u5982\u5e26\u6570\u503c\u3001\u5206\u70b9\u3001\u4e0d\u8d85\u8fc7200\u5b57&#xff09;&#xff1b;2. \u91c7\u7528Few-Shot\u63d0\u793a\u8bcd&#xff0c;\u52a0\u5165\u4f01\u4e1a\u98ce\u683c\u7684\u793a\u4f8b\u95ee\u7b54&#xff1b;3. \u8c03\u6574\u5927\u6a21\u578b\u7684temperature\u53c2\u6570&#xff08;0.1~0.3&#xff09;&#xff0c;\u964d\u4f4e\u751f\u6210\u968f\u673a\u6027<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5411\u91cf\u6570\u636e\u5e93\u68c0\u7d22\u901f\u5ea6\u6162<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u77e5\u8bc6\u5e93\u89c4\u6a21\u6269\u5927&#xff08;\u7247\u6bb5\u6570&gt;10\u4e07&#xff09;&#xff0c;\u5355\u4e00Chroma\u6570\u636e\u5e93\u6027\u80fd\u4e0d\u8db3<\/p>\n<\/td>\n<td style=\"vertical-align:top;width:138.0000pt\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">1. \u5bf9\u5411\u91cf\u5316\u6a21\u578b\u8fdb\u884c\u91cf\u5316&#xff08;FP16\/INT8&#xff09;&#xff0c;\u63d0\u5347\u5411\u91cf\u751f\u6210\u548c\u68c0\u7d22\u901f\u5ea6&#xff1b;2. \u5c06Chroma\u66ff\u6362\u4e3a\u5206\u5e03\u5f0f\u5411\u91cf\u6570\u636e\u5e93&#xff08;Milvus\/TDengine&#xff09;&#xff0c;\u652f\u6301\u6c34\u5e73\u6269\u5c55&#xff1b;3. \u5bf9\u4f01\u4e1a\u70ed\u70b9\u95ee\u9898\u5efa\u7acb\u7f13\u5b58&#xff0c;\u907f\u514d\u91cd\u590d\u68c0\u7d22<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">6. \u4f01\u4e1a\u7ea7\u5408\u89c4\u6027\u4e0e\u5b89\u5168\u6027\u8003\u91cf<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u4f01\u4e1a\u77e5\u8bc6\u5e93\u4e2d\u5305\u542b\u5927\u91cf\u79c1\u6709\u6570\u636e\u3001\u654f\u611f\u4fe1\u606f&#xff08;\u5982\u8d22\u52a1\u6570\u636e\u3001\u5458\u5de5\u4fe1\u606f\u3001\u6280\u672f\u6587\u6863&#xff09;&#xff0c;\u56e0\u6b64RAG\u7cfb\u7edf\u7684\u6784\u5efa\u5fc5\u987b\u517c\u987e\u6280\u672f\u5b9e\u73b0\u4e0e\u5408\u89c4\u5b89\u5168&#xff0c;\u7b26\u5408\u300a\u6570\u636e\u5b89\u5168\u6cd5\u300b\u300a\u4e2a\u4eba\u4fe1\u606f\u4fdd\u62a4\u6cd5\u300b\u7b49\u6cd5\u5f8b\u6cd5\u89c4\u8981\u6c42&#xff0c;\u540c\u65f6\u6ee1\u8db3\u4f01\u4e1a\u5185\u90e8\u7684\u4fe1\u606f\u5b89\u5168\u5236\u5ea6\u3002\u4ee5\u4e0b\u4e3a\u4f01\u4e1a\u843d\u5730RAG\u7cfb\u7edf\u7684\u6838\u5fc3\u5408\u89c4\u4e0e\u5b89\u5168\u8981\u6c42&#xff0c;\u53ef\u76f4\u63a5\u4f5c\u4e3a\u4f01\u4e1aRAG\u7cfb\u7edf\u7684\u5b89\u5168\u9a8c\u6536\u6807\u51c6&#xff1a;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">6.1 \u6570\u636e\u9690\u79c1\u4fdd\u62a4<\/p>\n<li style=\"text-align:left\">\u5bf9\u4f01\u4e1a\u77e5\u8bc6\u5e93\u4e2d\u7684\u5458\u5de5\u4e2a\u4eba\u4fe1\u606f&#xff08;\u59d3\u540d\u3001\u8eab\u4efd\u8bc1\u53f7\u3001\u624b\u673a\u53f7\u3001\u85aa\u916c\u7b49&#xff09;\u8fdb\u884c\u8131\u654f\u5904\u7406&#xff0c;\u91c7\u7528\u201c\u66ff\u6362\u3001\u63a9\u7801\u3001\u5220\u9664\u201d\u7b49\u65b9\u5f0f&#xff0c;\u4ec5\u4fdd\u7559\u5fc5\u8981\u4fe1\u606f&#xff1b;<\/li>\n<li style=\"text-align:left\">\u7981\u6b62\u5c06\u4f01\u4e1a\u654f\u611f\u6570\u636e\u9001\u5165\u516c\u6709\u5927\u6a21\u578b&#xff0c;\u6240\u6709\u5927\u6a21\u578b\u548c\u5411\u91cf\u6570\u636e\u5e93\u5747\u91c7\u7528\u79c1\u6709\u5316\u90e8\u7f72&#xff0c;\u90e8\u7f72\u5728\u4f01\u4e1a\u5185\u7f51&#xff0c;\u7981\u6b62\u516c\u7f51\u8bbf\u95ee&#xff1b;<\/li>\n<li style=\"text-align:left\">\u5bf9\u6587\u6863\u8fdb\u884c\u5206\u7ea7\u6807\u6ce8&#xff08;\u516c\u5f00\/\u5185\u90e8\/\u4fdd\u5bc6\/\u7edd\u5bc6&#xff09;&#xff0c;\u4e3a\u4e0d\u540c\u7ea7\u522b\u6587\u6863\u8bbe\u7f6e\u4e0d\u540c\u7684\u5904\u7406\u7b56\u7565&#xff08;\u5982\u7edd\u5bc6\u6587\u6863\u4e0d\u52a0\u5165\u77e5\u8bc6\u5e93&#xff09;\u3002<\/li>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">6.2 \u7ec6\u7c92\u5ea6\u6743\u9650\u5206\u7ea7\u63a7\u5236<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u57fa\u4e8e\u4f01\u4e1a\u5458\u5de5\u7684\u89d2\u8272\u3001\u90e8\u95e8\u3001\u5c97\u4f4d\u8bbe\u7f6e\u7ec6\u7c92\u5ea6\u7684\u77e5\u8bc6\u8bbf\u95ee\u6743\u9650&#xff0c;\u5b9e\u73b0\u201c\u8c01\u6709\u6743\u770b&#xff0c;\u8c01\u624d\u80fd\u68c0\u7d22\u201d&#xff0c;\u907f\u514d\u77e5\u8bc6\u6cc4\u9732\u3002\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li style=\"text-align:left\">\u666e\u901a\u5458\u5de5&#xff1a;\u4ec5\u80fd\u68c0\u7d22\u516c\u5f00\/\u5185\u90e8\u7684\u901a\u7528\u77e5\u8bc6&#xff08;\u5982\u5458\u5de5\u624b\u518c\u3001\u8003\u52e4\u89c4\u5b9a&#xff09;&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li style=\"text-align:left\">\u90e8\u95e8\u7ba1\u7406\u5458&#xff1a;\u80fd\u68c0\u7d22\u672c\u90e8\u95e8\u7684\u6240\u6709\u77e5\u8bc6&#xff08;\u5982\u90e8\u95e8\u5236\u5ea6\u3001\u4e1a\u52a1\u6d41\u7a0b&#xff09;&#xff1b;<\/li>\n<\/ul>\n<ul>\n<li style=\"text-align:left\">\u4f01\u4e1a\u7ba1\u7406\u5458&#xff1a;\u80fd\u68c0\u7d22\u6240\u6709\u77e5\u8bc6&#xff0c;\u4e14\u62e5\u6709\u77e5\u8bc6\u5e93\u7684\u589e\u5220\u6539\u6743\u9650\u3002<\/li>\n<\/ul>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u53ef\u901a\u8fc7\u5728\u5411\u91cf\u6570\u636e\u5e93\u4e2d\u4e3a\u6587\u6863\u6dfb\u52a0\u6743\u9650\u5143\u6570\u636e&#043;\u68c0\u7d22\u524d\u6743\u9650\u6821\u9a8c\u5b9e\u73b0&#xff0c;\u6838\u5fc3\u903b\u8f91\u4e3a&#xff1a;\u68c0\u7d22\u524d\u6839\u636e\u7528\u6237\u8eab\u4efd\u8fc7\u6ee4\u51fa\u5176\u6709\u6743\u8bbf\u95ee\u7684\u6587\u6863&#xff0c;\u518d\u8fdb\u884c\u76f8\u4f3c\u6027\u68c0\u7d22\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">6.3 \u5168\u94fe\u8def\u5ba1\u8ba1\u65e5\u5fd7\u8bb0\u5f55<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5b8c\u6574\u8bb0\u5f55RAG\u7cfb\u7edf\u7684\u6240\u6709\u64cd\u4f5c\u65e5\u5fd7&#xff0c;\u6ee1\u8db3\u4f01\u4e1a\u5408\u89c4\u5ba1\u8ba1\u8981\u6c42&#xff0c;\u65e5\u5fd7\u9700\u5305\u542b\u4ee5\u4e0b\u6838\u5fc3\u4fe1\u606f&#xff1a;<\/p>\n<li style=\"text-align:left\">\u7528\u6237\u64cd\u4f5c\u65e5\u5fd7&#xff1a;\u7528\u6237ID\u3001\u67e5\u8be2\u65f6\u95f4\u3001\u67e5\u8be2\u5185\u5bb9\u3001\u68c0\u7d22\u5230\u7684\u6587\u6863\u3001\u751f\u6210\u7684\u7b54\u6848\u3001\u64cd\u4f5cIP&#xff1b;<\/li>\n<li style=\"text-align:left\">\u77e5\u8bc6\u5e93\u7ba1\u7406\u65e5\u5fd7&#xff1a;\u6587\u6863\u7684\u589e\u5220\u6539\u65f6\u95f4\u3001\u64cd\u4f5c\u4eba\u3001\u6587\u6863\u7248\u672c\u3001\u53d8\u66f4\u5185\u5bb9&#xff1b;<\/li>\n<li style=\"text-align:left\">\u7cfb\u7edf\u8fd0\u884c\u65e5\u5fd7&#xff1a;\u6a21\u578b\u8c03\u7528\u8bb0\u5f55\u3001\u5411\u91cf\u6570\u636e\u5e93\u68c0\u7d22\u8bb0\u5f55\u3001\u5f02\u5e38\u62a5\u9519\u4fe1\u606f\u3002<\/li>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u65e5\u5fd7\u9700\u957f\u671f\u5b58\u50a8&#xff08;\u81f3\u5c116\u4e2a\u6708&#xff09;&#xff0c;\u5e76\u652f\u6301\u6309\u6761\u4ef6\u67e5\u8be2\u3001\u5bfc\u51fa\u3001\u6eaf\u6e90\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">6.4 \u5185\u5bb9\u5b89\u5168\u8fc7\u6ee4\u4e0e\u5ba1\u6838<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u5728RAG\u7cfb\u7edf\u7684\u751f\u6210\u73af\u8282\u52a0\u5165\u654f\u611f\u8bcd\u8fc7\u6ee4\u548c\u5185\u5bb9\u5ba1\u6838\u673a\u5236&#xff0c;\u907f\u514d\u6a21\u578b\u751f\u6210\u8fdd\u89c4\u3001\u4e0d\u5f53\u7684\u5185\u5bb9&#xff1a;<\/p>\n<li style=\"text-align:left\">\u7ef4\u62a4\u4f01\u4e1a\u4e13\u5c5e\u7684\u654f\u611f\u8bcd\u5e93&#xff08;\u5982\u653f\u6cbb\u654f\u611f\u3001\u5546\u4e1a\u8bcb\u6bc1\u3001\u8fdd\u89c4\u7528\u8bed\u7b49&#xff09;&#xff0c;\u751f\u6210\u7b54\u6848\u540e\u5148\u8fdb\u884c\u654f\u611f\u8bcd\u68c0\u6d4b&#xff0c;\u82e5\u547d\u4e2d\u5219\u62d2\u7edd\u8fd4\u56de&#xff1b;<\/li>\n<li style=\"text-align:left\">\u5bf9\u751f\u6210\u7684\u7b54\u6848\u8fdb\u884c\u4e8b\u5b9e\u6027\u5ba1\u6838&#xff0c;\u907f\u514d\u6a21\u578b\u57fa\u4e8e\u9519\u8bef\u68c0\u7d22\u7ed3\u679c\u751f\u6210\u865a\u5047\u7b54\u6848&#xff1b;<\/li>\n<li style=\"text-align:left\">\u5efa\u7acb\u7528\u6237\u53cd\u9988\u673a\u5236&#xff0c;\u5141\u8bb8\u7528\u6237\u5bf9\u9519\u8bef\u7b54\u6848\u8fdb\u884c\u4e3e\u62a5&#xff0c;\u8fd0\u8425\u4eba\u5458\u53ca\u65f6\u5904\u7406\u5e76\u66f4\u65b0\u77e5\u8bc6\u5e93\u3002<\/li>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u7ed3\u8bba<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u201c\u68c0\u7d22&#043;\u751f\u6210\u201d\u7684\u6838\u5fc3\u67b6\u6784&#xff0c;\u6709\u6548\u89e3\u51b3\u4e86\u5927\u8bed\u8a00\u6a21\u578b\u5728\u4f01\u4e1a\u573a\u666f\u843d\u5730\u7684\u77e5\u8bc6\u6ede\u540e\u6027\u3001\u4e8b\u5b9e\u6027\u504f\u5dee\u3001\u6570\u636e\u5b89\u5168\u7b49\u6838\u5fc3\u75db\u70b9&#xff0c;\u4e3a\u4f01\u4e1a\u6784\u5efa\u667a\u80fd\u77e5\u8bc6\u5e93\u63d0\u4f9b\u4e86\u5207\u5b9e\u53ef\u884c\u7684\u6280\u672f\u8def\u5f84\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u672c\u6587\u4ece\u7406\u8bba\u5230\u5b9e\u8df5&#xff0c;\u7cfb\u7edf\u9610\u8ff0\u4e86\u4f01\u4e1a\u7ea7RAG\u77e5\u8bc6\u5e93\u7684\u67b6\u6784\u8bbe\u8ba1\u3001\u6838\u5fc3\u5b9e\u73b0\u3001\u6027\u80fd\u4f18\u5316\u3001\u6548\u679c\u9a8c\u8bc1\u3001\u95ee\u9898\u89e3\u51b3\u3001\u5408\u89c4\u5b89\u5168\u5168\u6d41\u7a0b&#xff0c;\u6240\u6709\u4ee3\u7801\u5747\u7ecf\u8fc7\u5b9e\u64cd\u9a8c\u8bc1&#xff0c;\u53ef\u76f4\u63a5\u9002\u914d\u4f01\u4e1a\u4e2d\u5c0f\u89c4\u6a21\u77e5\u8bc6\u5e93\u7684\u642d\u5efa\u3002\u4f01\u4e1a\u5728\u843d\u5730RAG\u7cfb\u7edf\u65f6&#xff0c;\u65e0\u9700\u8ffd\u6c42\u6280\u672f\u7684\u201c\u5927\u800c\u5168\u201d&#xff0c;\u5e94\u6839\u636e\u81ea\u8eab\u77e5\u8bc6\u5e93\u89c4\u6a21\u3001\u4e1a\u52a1\u9700\u6c42\u3001\u90e8\u7f72\u6210\u672c\u9009\u62e9\u5408\u9002\u7684\u6280\u672f\u65b9\u6848&#xff1a;\u4e2d\u5c0f\u89c4\u6a21\u77e5\u8bc6\u5e93\u53ef\u9009\u7528Chroma&#043;ChatGLM3-6B\u7684\u8f7b\u91cf\u5316\u65b9\u6848&#xff0c;\u5927\u89c4\u6a21\u77e5\u8bc6\u5e93\u53ef\u9009\u7528Milvus&#043;Llama2-70B\u7684\u5206\u5e03\u5f0f\u65b9\u6848\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u672a\u6765&#xff0c;\u968f\u7740\u591a\u6a21\u6001RAG\u3001\u5b9e\u65f6\u5b66\u4e60\u3001\u5927\u6a21\u578b\u5fae\u8c03\u4e0eRAG\u878d\u5408\u7b49\u6280\u672f\u7684\u53d1\u5c55&#xff0c;RAG\u7cfb\u7edf\u5c06\u8fdb\u4e00\u6b65\u63d0\u5347\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u7684\u667a\u80fd\u5316\u6c34\u5e73&#xff1a;\u591a\u6a21\u6001RAG\u5c06\u652f\u6301\u56fe\u7247\u3001\u89c6\u9891\u3001\u97f3\u9891\u7b49\u975e\u6587\u672c\u77e5\u8bc6\u7684\u68c0\u7d22\u4e0e\u751f\u6210&#xff1b;\u5b9e\u65f6\u5b66\u4e60\u5c06\u5b9e\u73b0\u77e5\u8bc6\u5e93\u7684\u52a8\u6001\u66f4\u65b0\u4e0e\u6a21\u578b\u7684\u5b9e\u65f6\u9002\u914d&#xff1b;\u5927\u6a21\u578b\u5fae\u8c03\u4e0eRAG\u878d\u5408\u5c06\u517c\u987e\u79c1\u6709\u77e5\u8bc6\u7684\u6df1\u5ea6\u878d\u5408\u4e0e\u901a\u7528\u77e5\u8bc6\u7684\u5e7f\u5ea6\u8986\u76d6\u3002RAG\u6280\u672f\u4e0d\u4ec5\u662f\u5927\u6a21\u578b\u843d\u5730\u4f01\u4e1a\u573a\u666f\u7684\u201c\u6865\u6881\u201d&#xff0c;\u66f4\u662f\u4f01\u4e1a\u5b9e\u73b0\u77e5\u8bc6\u6570\u5b57\u5316\u3001\u7ba1\u7406\u667a\u80fd\u5316\u3001\u51b3\u7b56\u79d1\u5b66\u5316\u7684\u6838\u5fc3\u6280\u672f\u652f\u6491\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">\u53c2\u8003\u6587\u732e<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[1] Lewis P, Perez E, Piktus A, et al. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks[J]. Advances in Neural Information Processing Systems, 2020, 33: 9459-9474.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[2] Izacard G, Grave \u00c9. Leveraging Passage Retrieval with Generative Models for Open Domain Question Answering[C]\/\/Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume. 2021: 874-887.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[3] Karpukhin V, Oguz B, Min S, et al. Dense Passage Retrieval for Open-Domain Question Answering[C]\/\/Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). 2020: 6769-6781.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[4] \u5b57\u8282\u8df3\u52a8\u4eba\u5de5\u667a\u80fd\u5b9e\u9a8c\u5ba4. ChatGLM3\u6280\u672f\u62a5\u544a[R]. \u5317\u4eac: \u6e05\u534e\u5927\u5b66, 2023.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[5] \u8bed\u8a00\u5927\u6a21\u578b\u6280\u672f\u8054\u76df. BGE\u7cfb\u5217\u5d4c\u5165\u6a21\u578b\u6280\u672f\u767d\u76ae\u4e66[R]. \u5317\u4eac: \u5317\u4eac\u4eba\u5de5\u667a\u80fd\u7814\u7a76\u9662, 2023.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[6] LangChain Official Documentation. Retrieval-Augmented Generation (RAG) [EB\/OL]. 2024.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:left\">[7] Chroma Official Documentation. Chroma Vector Database Guide [EB\/OL]. 2024.<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u9644&#xff1a;\u4f01\u4e1aRAG\u7cfb\u7edf\u90e8\u7f72\u5efa\u8bae<\/p>\n<li style=\"text-align:left\">\u79c1\u6709\u5316\u90e8\u7f72&#xff1a;\u6240\u6709\u7ec4\u4ef6&#xff08;\u5411\u91cf\u6570\u636e\u5e93\u3001\u5927\u6a21\u578b\u3001\u5e94\u7528\u670d\u52a1&#xff09;\u5747\u90e8\u7f72\u5728\u4f01\u4e1a\u5185\u7f51&#xff0c;\u7981\u6b62\u516c\u7f51\u8bbf\u95ee&#xff0c;\u4fdd\u969c\u6570\u636e\u5b89\u5168&#xff1b;<\/li>\n<li style=\"text-align:left\">\u786c\u4ef6\u914d\u7f6e&#xff1a;\u4e2d\u5c0f\u89c4\u6a21\u77e5\u8bc6\u5e93&#xff08;&lt;10\u4e07\u7247\u6bb5&#xff09;\u63a8\u8350\u4f7f\u752816G GPU&#xff08;NVIDIA A10\/T4&#xff09;&#043;32G\u5185\u5b58&#xff0c;\u5927\u89c4\u6a21\u77e5\u8bc6\u5e93\u63a8\u8350\u4f7f\u7528\u591a\u5361GPU\u96c6\u7fa4&#043;\u5206\u5e03\u5f0f\u5b58\u50a8&#xff1b;<\/li>\n<li style=\"text-align:left\">\u6280\u672f\u9009\u578b&#xff1a;\u4f18\u5148\u9009\u7528\u5f00\u6e90\u4e2d\u6587\u6280\u672f\u6808&#xff08;BAAI\/bge&#043;ChatGLM&#043;Chroma\/Milvus&#xff09;&#xff0c;\u964d\u4f4e\u90e8\u7f72\u6210\u672c\u4e0e\u7248\u6743\u98ce\u9669&#xff1b;<\/li>\n<li style=\"text-align:left\">\u8fd0\u8425\u7ef4\u62a4&#xff1a;\u5efa\u7acb\u77e5\u8bc6\u5e93\u8fd0\u8425\u56e2\u961f&#xff0c;\u8d1f\u8d23\u6587\u6863\u7684\u589e\u5220\u6539\u3001\u8131\u654f\u3001\u7248\u672c\u7ba1\u7406&#xff0c;\u4ee5\u53ca\u7528\u6237\u53cd\u9988\u7684\u5904\u7406&#xff0c;\u4fdd\u8bc1\u77e5\u8bc6\u5e93\u7684\u65f6\u6548\u6027\u4e0e\u51c6\u786e\u6027\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u9002\u7528\u573a\u666f&#xff1a;\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u3001\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\u642d\u5efa\u3001\u5927\u6a21\u578b\u843d\u5730\u4e1a\u52a1\u573a\u666f<br \/>\n\u6280\u672f\u6808&#xff1a;LangChain\u3001Chroma\u3001HuggingFace Embeddings\u3001ChatGLM<br \/>\n\u96be\u5ea6&#xff1a;\u2605\u2605\u2605\u2606\u2606 \u6458\u8981<br \/>\n\u5927\u8bed\u8a00\u6a21\u578b\u7684\u77e5\u8bc6\u6ede\u540e\u6027\u548c\u4e8b\u5b9e\u6027\u504f\u5dee\u6210\u4e3a\u5176\u843d\u5730\u4f01\u4e1a\u7ea7\u573a\u666f\u7684\u6838\u5fc3\u75db\u70b9&#xff0c;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;Retrieval-Augmented Generation&#xff0c;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93\u4e0e\u751f\u6210\u6a21\u578b\u7684\u878d\u5408&amp;<\/p>\n","protected":false},"author":2,"featured_media":69227,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7294,81,50],"topic":[],"class_list":["post-69228","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-rag","tag-python","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \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\/69228.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u9002\u7528\u573a\u666f&#xff1a;\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u3001\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\u642d\u5efa\u3001\u5927\u6a21\u578b\u843d\u5730\u4e1a\u52a1\u573a\u666f \u6280\u672f\u6808&#xff1a;LangChain\u3001Chroma\u3001HuggingFace Embeddings\u3001ChatGLM \u96be\u5ea6&#xff1a;\u2605\u2605\u2605\u2606\u2606 \u6458\u8981 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u77e5\u8bc6\u6ede\u540e\u6027\u548c\u4e8b\u5b9e\u6027\u504f\u5dee\u6210\u4e3a\u5176\u843d\u5730\u4f01\u4e1a\u7ea7\u573a\u666f\u7684\u6838\u5fc3\u75db\u70b9&#xff0c;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;Retrieval-Augmented Generation&#xff0c;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93\u4e0e\u751f\u6210\u6a21\u578b\u7684\u878d\u5408&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69228.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-31T01:08:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131010856-697d56286f56d.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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69228.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69228.html\",\"name\":\"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-31T01:08:58+00:00\",\"dateModified\":\"2026-01-31T01:08:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69228.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69228.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69228.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5\"}]},{\"@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":"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \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\/69228.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u9002\u7528\u573a\u666f&#xff1a;\u4f01\u4e1a\u77e5\u8bc6\u7ba1\u7406\u3001\u667a\u80fd\u95ee\u7b54\u7cfb\u7edf\u642d\u5efa\u3001\u5927\u6a21\u578b\u843d\u5730\u4e1a\u52a1\u573a\u666f \u6280\u672f\u6808&#xff1a;LangChain\u3001Chroma\u3001HuggingFace Embeddings\u3001ChatGLM \u96be\u5ea6&#xff1a;\u2605\u2605\u2605\u2606\u2606 \u6458\u8981 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u77e5\u8bc6\u6ede\u540e\u6027\u548c\u4e8b\u5b9e\u6027\u504f\u5dee\u6210\u4e3a\u5176\u843d\u5730\u4f01\u4e1a\u7ea7\u573a\u666f\u7684\u6838\u5fc3\u75db\u70b9&#xff0c;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff08;Retrieval-Augmented Generation&#xff0c;RAG&#xff09;\u6280\u672f\u901a\u8fc7\u5916\u90e8\u77e5\u8bc6\u5e93\u4e0e\u751f\u6210\u6a21\u578b\u7684\u878d\u5408&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/69228.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-31T01:08:58+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260131010856-697d56286f56d.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69228.html","url":"https:\/\/www.wsisp.com\/helps\/69228.html","name":"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-31T01:08:58+00:00","dateModified":"2026-01-31T01:08:58+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69228.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69228.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69228.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6784\u5efa\u4f01\u4e1a\u7ea7\u667a\u80fd\u77e5\u8bc6\u5e93\uff1a\u4ece RAG \u6280\u672f\u5230\u5b9e\u8df5"}]},{"@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\/69228","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=69228"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69228\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/69227"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69228"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}