{"id":2604,"date":"2025-02-26T17:23:54","date_gmt":"2025-02-26T09:23:54","guid":{"rendered":"https:\/\/www.ruianding.com\/blog\/?p=2604"},"modified":"2025-10-10T20:18:12","modified_gmt":"2025-10-10T12:18:12","slug":"mini-rag-experiment","status":"publish","type":"post","link":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/","title":{"rendered":"LLM\u5c0f\u5b9e\u9a8c &#8211; \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba"},"content":{"rendered":"\n<p>\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5c06\u5206\u4eab\u5982\u4f55\u5229\u7528\u4f60\u5728 WordPress \u4e0a\u53d1\u5e03\u7684\u5206\u4eab\u5185\u5bb9\uff0c\u6784\u5efa\u4e00\u4e2a\u4e13\u5c5e\u77e5\u8bc6\u5e93\uff0c\u5e76\u7ed3\u5408\u672c\u5730\u79bb\u7ebf\u5927\u6a21\u578b\uff08\u901a\u8fc7 Ollama \u90e8\u7f72\uff09\u5b9e\u73b0\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08Retrieval Augmented Generation\uff0cRAG\uff09\uff0c\u6253\u9020\u4e13\u5c5e AI \u54a8\u8be2\u673a\u5668\u4eba\u3002\u4e0b\u9762\u662f\u6574\u4e2a\u5b9e\u9a8c\u7684\u914d\u7f6e\u6b65\u9aa4\u548c\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"898\" height=\"532\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\" alt=\"\" class=\"wp-image-2620\" style=\"width:754px;height:auto\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png 898w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25-300x178.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25-768x455.png 768w\" sizes=\"auto, (max-width: 898px) 100vw, 898px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u9a8c\u80cc\u666f<\/h2>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u5c0f\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5229\u7528\u5df2\u6709\u7684 WordPress \u5185\u5bb9\u4f5c\u4e3a\u77e5\u8bc6\u5e93\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6d41\u7a0b\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u91c7\u96c6<\/strong>\uff1a\u4ece WordPress \u83b7\u53d6\u6587\u7ae0\u5185\u5bb9\uff08\u5229\u7528 REST API\uff09\uff0c\u5e76\u4fdd\u5b58\u4e3a JSON \u6587\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u9884\u5904\u7406\u4e0e\u6e05\u6d17<\/strong>\uff1a\u5bf9\u83b7\u53d6\u7684 JSON \u6570\u636e\u8fdb\u884c HTML \u6e05\u6d17\u3001\u6587\u672c\u5206\u6bb5\uff0c\u5e76\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\uff08\u53ef\u6839\u636e\u9700\u6c42\u9009\u62e9\u5206\u79bb\u5b58\u50a8\u6216\u63d2\u5165\u5360\u4f4d\u7b26\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6587\u672c\u5d4c\u5165\u4e0e\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa<\/strong>\uff1a\u5229\u7528 SentenceTransformer \u5c06\u6bcf\u4e2a\u6587\u672c\u6bb5\u843d\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\uff0c\u5e76\u4f7f\u7528 FAISS \u6784\u5efa\u5411\u91cf\u68c0\u7d22\u7d22\u5f15\u3002<\/li>\n\n\n\n<li><strong>\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u4e0e\u56de\u7b54\u751f\u6210<\/strong>\uff1a\u5f53\u7528\u6237\u63d0\u51fa\u95ee\u9898\u65f6\uff0c\u6839\u636e\u7528\u6237\u95ee\u9898\u751f\u6210\u67e5\u8be2\u5411\u91cf\uff0c\u901a\u8fc7 FAISS \u7d22\u5f15\u68c0\u7d22\u6700\u76f8\u5173\u7684\u6587\u672c\u6bb5\u843d\uff0c\u518d\u6784\u9020\u4e00\u4e2a\u5305\u542b\u4e0a\u4e0b\u6587\u7684 prompt\uff0c\u6700\u7ec8\u8c03\u7528\u672c\u5730 Ollama \u90e8\u7f72\u7684\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u9a8c\u6b65\u9aa4\u8be6\u89e3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b65\u9aa4 1\uff1a\u6570\u636e\u91c7\u96c6<\/h3>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u4ece WordPress \u4e2d\u63d0\u53d6\u6587\u7ae0\u3001\u9875\u9762\u7b49\u5185\u5bb9\uff0c\u5e76\u4fdd\u5b58\u4e3a JSON \u683c\u5f0f\uff0c\u4f5c\u4e3a\u540e\u7eed\u77e5\u8bc6\u5e93\u7684\u539f\u59cb\u6570\u636e\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5173\u952e\u64cd\u4f5c<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u786e\u5b9a\u9700\u8981\u91c7\u96c6\u7684\u5185\u5bb9\uff08\u4f8b\u5982\uff1a\u6587\u7ae0\uff09\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 WordPress \u5185\u7f6e\u7684 REST API\uff08\u5982 <code>https:\/\/yourdomain.com\/wp-json\/wp\/v2\/posts<\/code>\uff09\u83b7\u53d6\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u811a\u672c\u91c7\u96c6\u6570\u636e\uff0c\u5e76\u5c06\u6570\u636e\u4fdd\u5b58\u4e3a JSON \u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import requests\nimport json\n\n# \u8bbe\u7f6e\u4f60\u7684 WordPress \u7ad9\u70b9\u5730\u5740\nwp_site = \"https:\/\/yourdomain.com\"\napi_endpoint = f\"{wp_site}\/wp-json\/wp\/v2\/posts\"\n\n# \u8bf7\u6c42\u6570\u636e\uff08\u53ef\u4ee5\u8bbe\u7f6e\u53c2\u6570\uff0c\u5982 per_page\u3001page \u7b49\uff09\nresponse = requests.get(api_endpoint, params={'per_page': 100})\nif response.status_code == 200:\n    posts = response.json()\n    # \u5c06\u6570\u636e\u4fdd\u5b58\u5230\u672c\u5730\u6587\u4ef6\n    with open(\"wp_posts.json\", \"w\", encoding=\"utf-8\") as f:\n        json.dump(posts, f, ensure_ascii=False, indent=2)\n    print(\"\u6570\u636e\u91c7\u96c6\u6210\u529f\uff0c\u5171\u91c7\u96c6\u5230\", len(posts), \"\u7bc7\u6587\u7ae0\")\nelse:\n    print(\"\u6570\u636e\u91c7\u96c6\u5931\u8d25\uff0c\u72b6\u6001\u7801\uff1a\", response.status_code)<\/pre>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"32\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-1024x32.png\" alt=\"\" class=\"wp-image-2617\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-1024x32.png 1024w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-300x9.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-768x24.png 768w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-1536x48.png 1536w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-24-2048x64.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b65\u9aa4 2\uff1a\u6570\u636e\u9884\u5904\u7406\u4e0e\u6e05\u6d17<\/h3>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u5bf9\u91c7\u96c6\u5230\u7684 JSON \u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u5305\u62ec\u53bb\u9664 HTML \u6807\u7b7e\u3001\u5206\u6bb5\u5904\u7406\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5173\u952e\u64cd\u4f5c<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u8bfb\u53d6 JSON \u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 BeautifulSoup \u53bb\u9664 HTML \u6807\u7b7e\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\uff08\u53ef\u4ee5\u9009\u62e9\u5c06 <code>&lt;img&gt;<\/code> \u6807\u7b7e\u66ff\u6362\u4e3a\u5360\u4f4d\u7b26\uff09\u3002<\/li>\n\n\n\n<li>\u6309\u7167\u81ea\u7136\u6bb5\u6216\u8005\u7a7a\u884c\u5bf9\u6587\u672c\u8fdb\u884c\u5206\u6bb5\u3002<\/li>\n\n\n\n<li>\u5c06\u5904\u7406\u540e\u7684\u6570\u636e\uff08\u6587\u7ae0 ID\u3001\u6807\u9898\u3001\u5404\u6bb5\u843d\u53ca\u56fe\u7247\u94fe\u63a5\uff09\u4fdd\u5b58\u4e3a\u65b0\u7684 JSON \u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import json\nfrom bs4 import BeautifulSoup\n\ndef extract_images(html_content):\n    \"\"\"\n    \u63d0\u53d6 HTML \u5185\u5bb9\u4e2d\u7684\u6240\u6709\u56fe\u7247\u94fe\u63a5\uff0c\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\n    \"\"\"\n    soup = BeautifulSoup(html_content, \"html.parser\")\n    images = []\n    for img in soup.find_all(\"img\"):\n        src = img.get(\"src\")\n        if src:\n            images.append(src)\n    return images\n\ndef clean_html_keep_images(html_content):\n    \"\"\"\n    \u6e05\u6d17 HTML \u6807\u7b7e\uff0c\u4f46\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\uff1a\n    - \u66ff\u6362 img \u6807\u7b7e\u4e3a\u5360\u4f4d\u7b26 [\u56fe\u7247: \u56fe\u7247\u94fe\u63a5]\n    - \u540c\u65f6\u8fd4\u56de\u4e00\u4e2a\u56fe\u7247\u94fe\u63a5\u5217\u8868\n    \"\"\"\n    soup = BeautifulSoup(html_content, \"html.parser\")\n    \n    # \u63d0\u53d6\u6240\u6709\u56fe\u7247\u94fe\u63a5\n    image_links = extract_images(html_content)\n    \n    # \u7528\u5360\u4f4d\u7b26\u66ff\u6362 img \u6807\u7b7e\n    for img in soup.find_all(\"img\"):\n        src = img.get(\"src\")\n        placeholder = f\"[\u56fe\u7247: {src}]\"\n        img.replace_with(placeholder)\n        \n    # \u83b7\u53d6\u6e05\u6d17\u540e\u7684\u7eaf\u6587\u672c\n    text = soup.get_text(separator=\"\\n\")\n    return text, image_links\n\ndef split_into_paragraphs(text):\n    \"\"\"\n    \u6839\u636e\u7a7a\u884c\u5207\u5206\u6587\u672c\u4e3a\u591a\u4e2a\u6bb5\u843d\n    \"\"\"\n    paragraphs = [p.strip() for p in text.split(\"\\n\\n\") if p.strip()]\n    return paragraphs\n\ndef process_wp_posts(json_file, output_file):\n    \"\"\"\n    \u8bfb\u53d6 WordPress API \u5bfc\u51fa\u7684 JSON \u6570\u636e\uff0c\u5904\u7406\u6bcf\u7bc7\u6587\u7ae0\u7684\u5185\u5bb9\uff0c\n    \u6e05\u6d17 HTML\uff0c\u5206\u6bb5\uff0c\u5e76\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\uff0c\u6700\u7ec8\u4fdd\u5b58\u5230 output_file \u4e2d\u3002\n    \"\"\"\n    with open(json_file, \"r\", encoding=\"utf-8\") as f:\n        posts = json.load(f)\n    \n    processed_posts = []\n    for post in posts:\n        # \u63d0\u53d6\u539f\u59cb HTML \u5185\u5bb9\n        raw_html = post.get(\"content\", {}).get(\"rendered\", \"\")\n        # \u6e05\u6d17 HTML \u6807\u7b7e\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u4fe1\u606f\n        clean_text, image_links = clean_html_keep_images(raw_html)\n        # \u5c06\u6e05\u6d17\u540e\u7684\u6587\u672c\u6309\u7167\u7a7a\u884c\u5207\u5206\u6210\u6bb5\u843d\n        paragraphs = split_into_paragraphs(clean_text)\n        \n        processed_posts.append({\n            \"id\": post.get(\"id\"),\n            \"title\": post.get(\"title\", {}).get(\"rendered\", \"\"),\n            \"paragraphs\": paragraphs,\n            \"images\": image_links  # \u5355\u72ec\u5b58\u50a8\u56fe\u7247\u94fe\u63a5\n        })\n    \n    with open(output_file, \"w\", encoding=\"utf-8\") as f:\n        json.dump(processed_posts, f, ensure_ascii=False, indent=2)\n    print(f\"\u5904\u7406\u5b8c\u6210\uff0c\u7ed3\u679c\u4fdd\u5b58\u5728 {output_file}\")\n\nif __name__ == \"__main__\":\n    # \u5047\u8bbe\u4f60\u5df2\u7ecf\u6709\u4e00\u4e2a\u4fdd\u5b58\u4e86 WordPress JSON \u6570\u636e\u7684\u6587\u4ef6 wp_posts.json\n    process_wp_posts(\"wp_posts.json\", \"processed_posts_with_img.json\")<\/pre>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"64\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-1024x64.png\" alt=\"\" class=\"wp-image-2616\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-1024x64.png 1024w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-300x19.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-768x48.png 768w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-1536x96.png 1536w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-23-2048x128.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b65\u9aa4 3\uff1a\u6587\u672c\u5d4c\u5165\u4e0e\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa<\/h3>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u5c06\u9884\u5904\u7406\u597d\u7684\u6587\u672c\uff08\u6bb5\u843d\uff09\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\uff0c\u5e76\u6784\u5efa <a href=\"https:\/\/github.com\/facebookresearch\/faiss?tab=readme-ov-file\" target=\"_blank\" rel=\"noreferrer noopener\">FAISS<\/a> \u5411\u91cf\u68c0\u7d22\u7d22\u5f15\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.1 \u73af\u5883\u51c6\u5907<\/h4>\n\n\n\n<p>\u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bat\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install sentence-transformers faiss-cpu numpy<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3.2 \u52a0\u8f7d\u6570\u636e<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bfb\u53d6\u9884\u5904\u7406\u540e\u7684 JSON \u6587\u4ef6\uff0c\u62bd\u53d6\u6240\u6709\u6587\u672c\u6bb5\u843d\uff0c\u5e76\u6784\u5efa\u6620\u5c04\u4fe1\u606f\uff08\u8bb0\u5f55\u6bcf\u4e2a\u6bb5\u843d\u6240\u5c5e\u7684\u6587\u7ae0\u4fe1\u606f\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3.3 \u751f\u6210\u6587\u672c\u5d4c\u5165<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 SentenceTransformer \u6a21\u578b\uff08\u5982 <code>'all-MiniLM-L6-v2'<\/code>\uff09\u4e3a\u6bcf\u4e2a\u6bb5\u843d\u751f\u6210\u5411\u91cf\u8868\u793a\u3002<\/li>\n\n\n\n<li>\u8fd9\u4e9b\u5411\u91cf\u80fd\u6355\u83b7\u6587\u672c\u7684\u8bed\u4e49\u4fe1\u606f\uff0c\u76f8\u4f3c\u8bed\u4e49\u7684\u6587\u672c\u5728\u5411\u91cf\u7a7a\u95f4\u4e2d\u7684\u8ddd\u79bb\u8f83\u8fd1\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3.4 \u6784\u5efa FAISS \u5411\u91cf\u6570\u636e\u5e93<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06\u751f\u6210\u7684\u5d4c\u5165\u8f6c\u6362\u4e3a numpy \u6570\u7ec4\uff0c\u6784\u5efa\u57fa\u4e8e L2 \u8ddd\u79bb\u7684 FAISS \u7d22\u5f15\u3002<\/li>\n\n\n\n<li>\u5c06\u7d22\u5f15\u4fdd\u5b58\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u540c\u65f6\u4fdd\u5b58\u6620\u5c04\u4fe1\u606f\u5230 JSON \u6587\u4ef6\uff0c\u4fbf\u4e8e\u540e\u7eed\u67e5\u8be2\u65f6\u8fd8\u539f\u539f\u59cb\u6587\u672c\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import json\nimport numpy as np\nimport faiss\nfrom sentence_transformers import SentenceTransformer\n\ndef load_processed_data(file_path):\n    \"\"\"\n    \u8bfb\u53d6\u9884\u5904\u7406\u540e\u7684 JSON \u6570\u636e\uff0c\u5c06\u6240\u6709\u6587\u7ae0\u6bb5\u843d\u62bd\u53d6\u6210\u4e00\u4e2a\u5217\u8868\uff0c\u540c\u65f6\u6784\u5efa\u4e00\u4e2a\u6620\u5c04\u5217\u8868\u3002\n    \u6620\u5c04\u5217\u8868\u8bb0\u5f55\u4e86\u6bcf\u4e2a\u6bb5\u843d\u6240\u5c5e\u7684\u6587\u7ae0ID\u3001\u6807\u9898\u3001\u6bb5\u843d\u7d22\u5f15\u548c\u6587\u672c\u5185\u5bb9\u3002\n    \"\"\"\n    with open(file_path, \"r\", encoding=\"utf-8\") as f:\n        data = json.load(f)\n    \n    texts = []      # \u5b58\u653e\u6240\u6709\u6bb5\u843d\u6587\u672c\n    mapping = []    # \u5b58\u653e\u6bcf\u4e2a\u6bb5\u843d\u5bf9\u5e94\u7684\u5143\u6570\u636e\n    for post in data:\n        post_id = post.get(\"id\")\n        title = post.get(\"title\", \"\")\n        paragraphs = post.get(\"paragraphs\", [])\n        for idx, para in enumerate(paragraphs):\n            texts.append(para)\n            mapping.append({\n                \"post_id\": post_id,\n                \"title\": title,\n                \"paragraph_index\": idx,\n                \"text\": para\n            })\n    return texts, mapping\n\ndef generate_embeddings(texts, model_name='all-MiniLM-L6-v2'):\n    \"\"\"\n    \u52a0\u8f7d SentenceTransformer \u6a21\u578b\uff0c\u5e76\u4e3a\u6bcf\u4e2a\u6587\u672c\u6bb5\u843d\u751f\u6210\u5411\u91cf\u5d4c\u5165\u3002\n    \u8fd4\u56de\u7684 embeddings \u662f\u4e00\u4e2a\u5217\u8868\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\u6570\u7ec4\uff08\u5411\u91cf\uff09\u3002\n    \"\"\"\n    model = SentenceTransformer(model_name)\n    embeddings = model.encode(texts, show_progress_bar=True)\n    return embeddings\n\ndef build_faiss_index(embeddings):\n    \"\"\"\n    \u5229\u7528 FAISS \u6784\u5efa\u5411\u91cf\u6570\u636e\u5e93\uff08\u7d22\u5f15\uff09\u3002\n    \u8fd9\u91cc\u6211\u4eec\u4f7f\u7528 L2 \u8ddd\u79bb\u4f5c\u4e3a\u5ea6\u91cf\u6807\u51c6\u3002\n    \u8fd4\u56de\u6784\u5efa\u597d\u7684 FAISS \u7d22\u5f15\u3002\n    \"\"\"\n    # \u5c06\u5d4c\u5165\u8f6c\u6362\u4e3a numpy \u6570\u7ec4\uff0c\u5e76\u4fdd\u8bc1\u6570\u636e\u7c7b\u578b\u4e3a float32\n    embeddings_np = np.array(embeddings).astype('float32')\n    dimension = embeddings_np.shape[1]\n    # \u521b\u5efa\u57fa\u4e8e L2 \u8ddd\u79bb\u7684\u7d22\u5f15\n    index = faiss.IndexFlatL2(dimension)\n    index.add(embeddings_np)\n    return index\n\ndef save_index_and_mapping(index, mapping, index_file=\"faiss_index.index\", mapping_file=\"mapping.json\"):\n    \"\"\"\n    \u5c06 FAISS \u7d22\u5f15\u4fdd\u5b58\u5230\u78c1\u76d8\uff0c\u540c\u65f6\u4fdd\u5b58\u6620\u5c04\u5217\u8868\u4e3a JSON \u6587\u4ef6\u3002\n    \"\"\"\n    faiss.write_index(index, index_file)\n    with open(mapping_file, \"w\", encoding=\"utf-8\") as f:\n        json.dump(mapping, f, ensure_ascii=False, indent=2)\n    print(f\"\u7d22\u5f15\u5df2\u4fdd\u5b58\u5230 {index_file}\")\n    print(f\"\u6620\u5c04\u4fe1\u606f\u5df2\u4fdd\u5b58\u5230 {mapping_file}\")\n\nif __name__ == \"__main__\":\n    # \u5047\u8bbe\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u540d\u4e3a processed_posts.json\n    processed_file = \"processed_posts_with_img.json\"\n    \n    # 1. \u52a0\u8f7d\u6570\u636e\uff0c\u5f97\u5230\u6240\u6709\u6587\u672c\u6bb5\u843d\u548c\u5bf9\u5e94\u6620\u5c04\u4fe1\u606f\n    texts, mapping = load_processed_data(processed_file)\n    print(f\"\u5171\u52a0\u8f7d {len(texts)} \u4e2a\u6587\u672c\u6bb5\u843d\u3002\")\n    \n    # 2. \u751f\u6210\u6587\u672c\u5d4c\u5165\n    embeddings = generate_embeddings(texts)\n    print(\"\u6587\u672c\u5d4c\u5165\u751f\u6210\u5b8c\u6bd5\u3002\")\n    \n    # 3. \u6784\u5efa FAISS \u7d22\u5f15\n    index = build_faiss_index(embeddings)\n    print(\"FAISS \u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa\u5b8c\u6210\uff0c\u5411\u91cf\u603b\u6570\uff1a\", index.ntotal)\n    \n    # 4. \u4fdd\u5b58\u7d22\u5f15\u548c\u6620\u5c04\u4fe1\u606f\n    save_index_and_mapping(index, mapping)<\/pre>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"111\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22-1024x111.png\" alt=\"\" class=\"wp-image-2615\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22-1024x111.png 1024w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22-300x33.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22-768x83.png 768w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22-1536x167.png 1536w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-22.png 2046w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u5411\u91cf\u6982\u5ff5\u89e3\u91ca<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5411\u91cf<\/strong>\uff1a\u5728\u673a\u5668\u5b66\u4e60\u4e2d\uff0c\u5411\u91cf\u662f\u4e00\u4e32\u6570\u5b57\uff0c\u7528\u4e8e\u8868\u793a\u6587\u672c\u3001\u56fe\u50cf\u7b49\u6570\u636e\u7684\u7279\u5f81\u3002<\/li>\n\n\n\n<li><strong>\u6587\u672c\u5411\u91cf<\/strong>\uff1a\u901a\u8fc7\u9884\u8bad\u7ec3\u7684\u6a21\u578b\u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u56fa\u5b9a\u7ef4\u5ea6\u7684\u6570\u5b57\u6570\u7ec4\uff0c\u8fd9\u4e2a\u6570\u7ec4\u5305\u542b\u4e86\u6587\u672c\u7684\u8bed\u4e49\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><strong>\u76f8\u4f3c\u5ea6\u8ba1\u7b97<\/strong>\uff1a\u5f53\u4e24\u4e2a\u6587\u672c\u7684\u5411\u91cf\u8ddd\u79bb\u8f83\u8fd1\u65f6\uff0c\u8868\u793a\u5b83\u4eec\u7684\u8bed\u4e49\u76f8\u4f3c\u3002\u5728\u672c\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5229\u7528\u8fd9\u4e00\u7279\u6027\u4ece\u77e5\u8bc6\u5e93\u4e2d\u68c0\u7d22\u4e0e\u7528\u6237\u95ee\u9898\u6700\u76f8\u5173\u7684\u6587\u672c\u6bb5\u843d\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u6b65\u9aa4 4\uff1a\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u4e0e\u56de\u7b54\u751f\u6210<\/h3>\n\n\n\n<p><strong>\u76ee\u6807<\/strong>\uff1a\u7ed3\u5408\u5df2\u6784\u5efa\u7684\u5411\u91cf\u6570\u636e\u5e93\uff0c\u5f53\u7528\u6237\u63d0\u51fa\u95ee\u9898\u65f6\uff0c\u5148\u68c0\u7d22\u6700\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\uff0c\u518d\u901a\u8fc7\u672c\u5730\u90e8\u7f72\u7684\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.1 \u68c0\u7d22\u76f8\u5173\u4e0a\u4e0b\u6587<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u4e0e\u9884\u5904\u7406\u65f6\u76f8\u540c\u7684 SentenceTransformer \u6a21\u578b\u751f\u6210\u7528\u6237\u95ee\u9898\u7684\u5411\u91cf\u3002<\/li>\n\n\n\n<li>\u5728 FAISS \u7d22\u5f15\u4e2d\u641c\u7d22\u4e0e\u8be5\u5411\u91cf\u6700\u76f8\u4f3c\u7684\u6587\u672c\u6bb5\u843d\uff0c\u5e76\u4ece\u6620\u5c04\u4fe1\u606f\u4e2d\u63d0\u53d6\u8be6\u7ec6\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u5c06\u68c0\u7d22\u5230\u7684\u6bb5\u843d\u62fc\u63a5\u6210\u4e00\u4e2a\u4e0a\u4e0b\u6587\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.2 \u6784\u9020 Prompt<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06\u68c0\u7d22\u5230\u7684\u4e0a\u4e0b\u6587\u4e0e\u7528\u6237\u95ee\u9898\u7ec4\u5408\u6784\u6210\u4e00\u4e2a prompt\uff0c\u7528\u4e8e\u6307\u5bfc\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.3 \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u8fc7 HTTP POST \u8bf7\u6c42\u8c03\u7528\u4f60\u672c\u5730 Ollama \u90e8\u7f72\u7684\u5927\u6a21\u578b\u670d\u52a1\uff0c\u4f20\u5165\u6784\u9020\u597d\u7684 prompt\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e Ollama \u91c7\u7528\u6d41\u5f0f\u8fd4\u56de\uff0c\u4ee3\u7801\u4e2d\u4f1a\u9010\u884c\u89e3\u6790\u8fd4\u56de\u7684 JSON \u6570\u636e\uff0c\u5e76\u5c06\u5404\u90e8\u5206 response \u5b57\u6bb5\u62fc\u63a5\u6210\u6700\u7ec8\u56de\u7b54\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import json\nimport numpy as np\nimport faiss\nimport requests\nfrom sentence_transformers import SentenceTransformer\n\n# --------------------------\n# 1. \u52a0\u8f7d\u6620\u5c04\u548c FAISS \u7d22\u5f15\n# --------------------------\n\ndef load_mapping(mapping_file=\"mapping.json\"):\n    with open(mapping_file, \"r\", encoding=\"utf-8\") as f:\n        mapping = json.load(f)\n    return mapping\n\ndef load_faiss_index(index_file=\"faiss_index.index\"):\n    index = faiss.read_index(index_file)\n    return index\n\n# --------------------------\n# 2. \u52a0\u8f7d\u9884\u8bad\u7ec3\u5d4c\u5165\u6a21\u578b\n# --------------------------\n\n# \u786e\u4fdd\u6a21\u578b\u4e0e\u751f\u6210\u5411\u91cf\u65f6\u4f7f\u7528\u7684\u4e00\u81f4\nmodel = SentenceTransformer('all-MiniLM-L6-v2')\n\n# --------------------------\n# 3. \u5b9a\u4e49\u68c0\u7d22\u51fd\u6570\uff1a\u7ed9\u5b9a\u67e5\u8be2\u751f\u6210\u5d4c\u5165\uff0c\u4ece\u7d22\u5f15\u4e2d\u68c0\u7d22\u76f8\u5173\u6bb5\u843d\n# --------------------------\n\ndef retrieve_relevant_context(query, model, index, mapping, top_k=5):\n    # \u751f\u6210\u67e5\u8be2\u7684\u5411\u91cf\u5d4c\u5165\n    query_embedding = model.encode([query])\n    query_np = np.array(query_embedding).astype('float32')\n    # \u5728 FAISS \u7d22\u5f15\u4e2d\u8fdb\u884c\u641c\u7d22\n    distances, indices = index.search(query_np, top_k)\n    \n    # \u4ece\u6620\u5c04\u4fe1\u606f\u4e2d\u83b7\u53d6\u5bf9\u5e94\u7684\u6bb5\u843d\u4fe1\u606f\n    results = []\n    for idx in indices[0]:\n        if idx &lt; len(mapping):\n            results.append(mapping[idx])\n    # \u5c06\u68c0\u7d22\u5230\u7684\u6bb5\u843d\u6587\u672c\u5408\u5e76\u6210\u4e0a\u4e0b\u6587\n    context = \"\\n\\n\".join([item['text'] for item in results])\n    return context\n\n# --------------------------\n# 4. \u6784\u9020 Prompt\n# --------------------------\n\ndef construct_prompt(query, context):\n    prompt = (\n        f\"\u8bf7\u6839\u636e\u4ee5\u4e0b\u77e5\u8bc6\u5e93\u5185\u5bb9\u56de\u7b54\u95ee\u9898\uff1a\\n\\n\"\n        f\"\u3010\u77e5\u8bc6\u5e93\u3011\uff1a\\n{context}\\n\\n\"\n        f\"\u3010\u95ee\u9898\u3011\uff1a{query}\\n\\n\"\n        f\"\u3010\u7b54\u6848\u3011\uff1a\"\n    )\n    return prompt\n\n# --------------------------\n# 5. \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\uff08Ollama\uff09\u751f\u6210\u56de\u7b54\n# --------------------------\n\n# \u6b64\u5904\u793a\u4f8b\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a Ollama API \u670d\u52a1\u5728\u672c\u5730\u8fd0\u884c\uff0c\n# \u4f60\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574 URL\u3001\u6a21\u578b\u540d\u79f0\u548c\u5176\u4ed6\u53c2\u6570\u3002\n\ndef call_ollama(prompt):\n    import json\n    import requests\n\n    url = \"http:\/\/localhost:11434\/api\/generate\"  # \u8bf7\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574\u5730\u5740\n    headers = {\"Content-Type\": \"application\/json\"}\n    payload = {\n        \"prompt\": prompt,\n        \"model\": \"qwen:14B\",  # \u66ff\u6362\u4e3a\u4f60\u5b9e\u9645\u4f7f\u7528\u7684\u6a21\u578b\u540d\u79f0\n        \"max_tokens\": 3000\n    }\n    response = requests.post(url, headers=headers, json=payload, stream=True)\n\n    result_text = \"\"\n    # \u9010\u884c\u8bfb\u53d6\u54cd\u5e94\n    for line in response.iter_lines():\n        if line:\n            try:\n                data = json.loads(line.decode(\"utf-8\"))\n                print(\"\u89e3\u6790\u5230\u4e00\u884c\u6570\u636e\uff1a\", data)  # \u8c03\u8bd5\u8f93\u51fa\n                if \"response\" in data:\n                    result_text += data[\"response\"]\n            except Exception as e:\n                print(\"JSON\u89e3\u6790\u9519\u8bef\uff0c\u884c\u5185\u5bb9\uff1a\", line)\n                print(e)\n    return result_text.strip()\n\n# --------------------------\n# 6. \u6574\u5408\u6574\u4e2a\u6d41\u7a0b\uff1a\u6839\u636e\u7528\u6237\u67e5\u8be2\u751f\u6210\u7b54\u6848\n# --------------------------\n\ndef generate_answer(query, model, index, mapping, top_k=5):\n    # 1. \u68c0\u7d22\u77e5\u8bc6\u5e93\u4e2d\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\n    context = retrieve_relevant_context(query, model, index, mapping, top_k)\n    # 2. \u6784\u9020\u5b8c\u6574\u7684\u63d0\u793a\u8bcd\n    prompt = construct_prompt(query, context)\n    print(\"\u6784\u9020\u7684 Prompt:\\n\", prompt)\n    # 3. \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\n    answer = call_ollama(prompt)\n    return answer\n\n# --------------------------\n# 7. \u793a\u4f8b\uff1a\u4f7f\u7528\u6574\u4e2a\u6d41\u7a0b\n# --------------------------\n\nif __name__ == \"__main__\":\n    # \u52a0\u8f7d\u6620\u5c04\u548c FAISS \u7d22\u5f15\n    mapping = load_mapping(\"mapping.json\")\n    index = load_faiss_index(\"faiss_index.index\")\n    \n    # \u793a\u4f8b\u7528\u6237\u63d0\u95ee\n    query = \"Give me one typical error code of DRS(Device Registration Service) issue\uff0cand provide me the solution.\"\n    \n    # \u751f\u6210\u56de\u7b54\n    answer = generate_answer(query, model, index, mapping, top_k=5)\n    print(\"\u751f\u6210\u7684\u56de\u7b54\uff1a\", answer)<\/pre>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"477\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-1024x477.png\" alt=\"\" class=\"wp-image-2606\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-1024x477.png 1024w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-300x140.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-768x358.png 768w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-1536x716.png 1536w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-18-2048x954.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-dots\"\/>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"571\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-1024x571.png\" alt=\"\" class=\"wp-image-2607\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-1024x571.png 1024w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-300x167.png 300w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-768x429.png 768w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-1536x857.png 1536w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-19-2048x1143.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u6d41\u7a0b\u56fe\u793a\u610f<\/h3>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u5f20\u6d41\u7a0b\u56fe\uff0c\u5c55\u793a\u4e86\u6574\u4e2a\u68c0\u7d22\u4e0e\u56de\u7b54\u751f\u6210\u7684\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"215\" height=\"1024\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/Untitled-diagram-2025-02-26-091351-215x1024.png\" alt=\"\" class=\"wp-image-2605\" style=\"width:155px;height:auto\" srcset=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/Untitled-diagram-2025-02-26-091351-215x1024.png 215w, https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/Untitled-diagram-2025-02-26-091351-63x300.png 63w\" sizes=\"auto, (max-width: 215px) 100vw, 215px\" \/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6d41\u7a0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u636e\u91c7\u96c6<\/strong>\uff1a\u5229\u7528 WordPress REST API \u83b7\u53d6\u6587\u7ae0\u6570\u636e\uff1b<\/li>\n\n\n\n<li><strong>\u6570\u636e\u9884\u5904\u7406<\/strong>\uff1a\u6e05\u6d17 HTML\u3001\u5206\u6bb5\u5904\u7406\uff0c\u5e76\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\uff1b<\/li>\n\n\n\n<li><strong>\u6587\u672c\u5d4c\u5165<\/strong>\uff1a\u5229\u7528 SentenceTransformer \u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u5411\u91cf\uff0c\u5e76\u6784\u5efa FAISS \u7d22\u5f15\uff1b<\/li>\n\n\n\n<li><strong>RAG \u4e0e\u56de\u7b54\u751f\u6210<\/strong>\uff1a\u68c0\u7d22\u4e0e\u7528\u6237\u67e5\u8be2\u6700\u76f8\u5173\u7684\u77e5\u8bc6\u5e93\u5185\u5bb9\uff0c\u5e76\u5229\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6574\u4e2a\u7cfb\u7edf\u5b9e\u73b0\u4e86\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u7684\u67b6\u6784\uff0c\u65e2\u80fd\u5229\u7528\u5df2\u6709\u77e5\u8bc6\u5e93\u56de\u7b54\u95ee\u9898\uff0c\u53c8\u53ef\u4ee5\u901a\u8fc7\u5927\u6a21\u578b\u751f\u6210\u66f4\u52a0\u667a\u80fd\u7684\u56de\u7b54\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5c06\u5206\u4eab\u5982\u4f55\u5229\u7528\u4f60\u5728 WordPress \u4e0a\u53d1\u5e03\u7684\u5206\u4eab\u5185\u5bb9\uff0c\u6784\u5efa\u4e00\u4e2a\u4e13\u5c5e\u77e5\u8bc6\u5e93\uff0c\u5e76\u7ed3\u5408\u672c\u5730\u79bb\u7ebf\u5927\u6a21\u578b\uff08\u901a\u8fc7 Ollama \u90e8\u7f72\uff09\u5b9e\u73b0\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08Retrieval Augmented Generation\uff0cRAG\uff09\uff0c\u6253\u9020\u4e13\u5c5e AI \u54a8\u8be2\u673a\u5668\u4eba\u3002\u4e0b\u9762\u662f\u6574\u4e2a\u5b9e\u9a8c\u7684\u914d\u7f6e\u6b65\u9aa4\u548c\u5b9e\u73b0\u8fc7\u7a0b\u3002 \u5b9e\u9a8c\u80cc\u666f \u5728\u8fd9\u4e2a\u5c0f\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5229\u7528\u5df2\u6709\u7684 WordPress \u5185\u5bb9\u4f5c\u4e3a\u77e5\u8bc6\u5e93\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6d41\u7a0b\u5b9e\u73b0\uff1a \u5b9e\u9a8c\u6b65\u9aa4\u8be6\u89e3 \u6b65\u9aa4 1\uff1a\u6570\u636e\u91c7\u96c6 \u76ee\u6807\uff1a\u4ece WordPress \u4e2d\u63d0\u53d6\u6587\u7ae0\u3001\u9875\u9762\u7b49\u5185\u5bb9\uff0c\u5e76\u4fdd\u5b58\u4e3a JSON \u683c\u5f0f\uff0c\u4f5c\u4e3a\u540e\u7eed\u77e5\u8bc6\u5e93\u7684\u539f\u59cb\u6570\u636e\u3002 \u6b65\u9aa4 2\uff1a\u6570\u636e\u9884\u5904\u7406\u4e0e\u6e05\u6d17 \u76ee\u6807\uff1a\u5bf9\u91c7\u96c6\u5230\u7684 JSON \u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u5305\u62ec\u53bb\u9664 HTML \u6807\u7b7e\u3001\u5206\u6bb5\u5904\u7406\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\u3002 \u6b65\u9aa4 3\uff1a\u6587\u672c\u5d4c\u5165\u4e0e\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa \u76ee\u6807\uff1a\u5c06\u9884\u5904\u7406\u597d\u7684\u6587\u672c\uff08\u6bb5\u843d\uff09\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\uff0c\u5e76\u6784\u5efa FAISS \u5411\u91cf\u68c0\u7d22\u7d22\u5f15\u3002 3.1 \u73af\u5883\u51c6\u5907 \u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\uff1a 3.2 \u52a0\u8f7d\u6570\u636e 3.3 \u751f\u6210\u6587\u672c\u5d4c\u5165 3.4 \u6784\u5efa FAISS \u5411\u91cf\u6570\u636e\u5e93 \u5411\u91cf\u6982\u5ff5\u89e3\u91ca \u6b65\u9aa4 4\uff1a\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u4e0e\u56de\u7b54\u751f\u6210 \u76ee\u6807\uff1a\u7ed3\u5408\u5df2\u6784\u5efa\u7684\u5411\u91cf\u6570\u636e\u5e93\uff0c\u5f53\u7528\u6237\u63d0\u51fa\u95ee\u9898\u65f6\uff0c\u5148\u68c0\u7d22\u6700\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\uff0c\u518d\u901a\u8fc7\u672c\u5730\u90e8\u7f72\u7684\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002 4.1 \u68c0\u7d22\u76f8\u5173\u4e0a\u4e0b\u6587 4.2 \u6784\u9020 Prompt 4.3 \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[1,10],"tags":[68,69,67],"class_list":["post-2604","post","type-post","status-publish","format-standard","hentry","category-miscellaneous","category-tutorial","tag-ai","tag-llm","tag-rag"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT<\/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.ruianding.com\/blog\/mini-rag-experiment\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT\" \/>\n<meta property=\"og:description\" content=\"\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5c06\u5206\u4eab\u5982\u4f55\u5229\u7528\u4f60\u5728 WordPress \u4e0a\u53d1\u5e03\u7684\u5206\u4eab\u5185\u5bb9\uff0c\u6784\u5efa\u4e00\u4e2a\u4e13\u5c5e\u77e5\u8bc6\u5e93\uff0c\u5e76\u7ed3\u5408\u672c\u5730\u79bb\u7ebf\u5927\u6a21\u578b\uff08\u901a\u8fc7 Ollama \u90e8\u7f72\uff09\u5b9e\u73b0\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08Retrieval Augmented Generation\uff0cRAG\uff09\uff0c\u6253\u9020\u4e13\u5c5e AI \u54a8\u8be2\u673a\u5668\u4eba\u3002\u4e0b\u9762\u662f\u6574\u4e2a\u5b9e\u9a8c\u7684\u914d\u7f6e\u6b65\u9aa4\u548c\u5b9e\u73b0\u8fc7\u7a0b\u3002 \u5b9e\u9a8c\u80cc\u666f \u5728\u8fd9\u4e2a\u5c0f\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5229\u7528\u5df2\u6709\u7684 WordPress \u5185\u5bb9\u4f5c\u4e3a\u77e5\u8bc6\u5e93\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6d41\u7a0b\u5b9e\u73b0\uff1a \u5b9e\u9a8c\u6b65\u9aa4\u8be6\u89e3 \u6b65\u9aa4 1\uff1a\u6570\u636e\u91c7\u96c6 \u76ee\u6807\uff1a\u4ece WordPress \u4e2d\u63d0\u53d6\u6587\u7ae0\u3001\u9875\u9762\u7b49\u5185\u5bb9\uff0c\u5e76\u4fdd\u5b58\u4e3a JSON \u683c\u5f0f\uff0c\u4f5c\u4e3a\u540e\u7eed\u77e5\u8bc6\u5e93\u7684\u539f\u59cb\u6570\u636e\u3002 \u6b65\u9aa4 2\uff1a\u6570\u636e\u9884\u5904\u7406\u4e0e\u6e05\u6d17 \u76ee\u6807\uff1a\u5bf9\u91c7\u96c6\u5230\u7684 JSON \u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u5305\u62ec\u53bb\u9664 HTML \u6807\u7b7e\u3001\u5206\u6bb5\u5904\u7406\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\u3002 \u6b65\u9aa4 3\uff1a\u6587\u672c\u5d4c\u5165\u4e0e\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa \u76ee\u6807\uff1a\u5c06\u9884\u5904\u7406\u597d\u7684\u6587\u672c\uff08\u6bb5\u843d\uff09\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\uff0c\u5e76\u6784\u5efa FAISS \u5411\u91cf\u68c0\u7d22\u7d22\u5f15\u3002 3.1 \u73af\u5883\u51c6\u5907 \u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\uff1a 3.2 \u52a0\u8f7d\u6570\u636e 3.3 \u751f\u6210\u6587\u672c\u5d4c\u5165 3.4 \u6784\u5efa FAISS \u5411\u91cf\u6570\u636e\u5e93 \u5411\u91cf\u6982\u5ff5\u89e3\u91ca \u6b65\u9aa4 4\uff1a\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u4e0e\u56de\u7b54\u751f\u6210 \u76ee\u6807\uff1a\u7ed3\u5408\u5df2\u6784\u5efa\u7684\u5411\u91cf\u6570\u636e\u5e93\uff0c\u5f53\u7528\u6237\u63d0\u51fa\u95ee\u9898\u65f6\uff0c\u5148\u68c0\u7d22\u6700\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\uff0c\u518d\u901a\u8fc7\u672c\u5730\u90e8\u7f72\u7684\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002 4.1 \u68c0\u7d22\u76f8\u5173\u4e0a\u4e0b\u6587 4.2 \u6784\u9020 Prompt 4.3 \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\" \/>\n<meta property=\"og:site_name\" content=\"\u6781\u7b80IT\uff5cSimpleIT\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-26T09:23:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-10T12:18:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\" \/>\n\t<meta property=\"og:image:width\" content=\"898\" \/>\n\t<meta property=\"og:image:height\" content=\"532\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ruian Ding\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ruian Ding\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\"},\"author\":{\"name\":\"Ruian Ding\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"headline\":\"LLM\u5c0f\u5b9e\u9a8c &#8211; \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba\",\"datePublished\":\"2025-02-26T09:23:54+00:00\",\"dateModified\":\"2025-10-10T12:18:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\"},\"wordCount\":65,\"publisher\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"image\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\",\"keywords\":[\"AI\",\"LLM\",\"RAG\"],\"articleSection\":[\"Miscellaneous\",\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\",\"url\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\",\"name\":\"LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT\",\"isPartOf\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\",\"datePublished\":\"2025-02-26T09:23:54+00:00\",\"dateModified\":\"2025-10-10T12:18:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage\",\"url\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\",\"contentUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png\",\"width\":898,\"height\":532},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ruianding.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LLM\u5c0f\u5b9e\u9a8c &#8211; \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#website\",\"url\":\"https:\/\/www.ruianding.com\/blog\/\",\"name\":\"Ruian's Tech Troubleshooting Toolbox\",\"description\":\"Debug the World.\",\"publisher\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"alternateName\":\"\u4e01\u777f\u5b89\u7684\u6280\u672f\u5206\u4eab\u535a\u5ba2\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ruianding.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\",\"name\":\"Ruian Ding\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png\",\"contentUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png\",\"width\":284,\"height\":284,\"caption\":\"Ruian Ding\"},\"logo\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"I am currently a Support Specialist at NIO, focusing on cloud-related issues for NIO Power. Previously, at Microsoft Entra ID, I specialized in identity and access management (IAM), including device registration, Windows Hello for Business (WHfB), multi-factor authentication (MFA), and single sign-on (SSO). In addition to my core expertise, I have a strong foundation in Active Directory, Servers, Cloud Computing, Network Administration, and Front-end Web Development. This diverse technical skill set enables me to effectively handle a wide range of challenges in a fast-paced IT environment.\",\"sameAs\":[\"https:\/\/www.ruianding.com\"],\"url\":\"https:\/\/www.ruianding.com\/blog\/author\/ruiand\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT","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.ruianding.com\/blog\/mini-rag-experiment\/","og_locale":"en_US","og_type":"article","og_title":"LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT","og_description":"\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u5c06\u5206\u4eab\u5982\u4f55\u5229\u7528\u4f60\u5728 WordPress \u4e0a\u53d1\u5e03\u7684\u5206\u4eab\u5185\u5bb9\uff0c\u6784\u5efa\u4e00\u4e2a\u4e13\u5c5e\u77e5\u8bc6\u5e93\uff0c\u5e76\u7ed3\u5408\u672c\u5730\u79bb\u7ebf\u5927\u6a21\u578b\uff08\u901a\u8fc7 Ollama \u90e8\u7f72\uff09\u5b9e\u73b0\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08Retrieval Augmented Generation\uff0cRAG\uff09\uff0c\u6253\u9020\u4e13\u5c5e AI \u54a8\u8be2\u673a\u5668\u4eba\u3002\u4e0b\u9762\u662f\u6574\u4e2a\u5b9e\u9a8c\u7684\u914d\u7f6e\u6b65\u9aa4\u548c\u5b9e\u73b0\u8fc7\u7a0b\u3002 \u5b9e\u9a8c\u80cc\u666f \u5728\u8fd9\u4e2a\u5c0f\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u5e0c\u671b\u5229\u7528\u5df2\u6709\u7684 WordPress \u5185\u5bb9\u4f5c\u4e3a\u77e5\u8bc6\u5e93\uff0c\u901a\u8fc7\u4ee5\u4e0b\u6d41\u7a0b\u5b9e\u73b0\uff1a \u5b9e\u9a8c\u6b65\u9aa4\u8be6\u89e3 \u6b65\u9aa4 1\uff1a\u6570\u636e\u91c7\u96c6 \u76ee\u6807\uff1a\u4ece WordPress \u4e2d\u63d0\u53d6\u6587\u7ae0\u3001\u9875\u9762\u7b49\u5185\u5bb9\uff0c\u5e76\u4fdd\u5b58\u4e3a JSON \u683c\u5f0f\uff0c\u4f5c\u4e3a\u540e\u7eed\u77e5\u8bc6\u5e93\u7684\u539f\u59cb\u6570\u636e\u3002 \u6b65\u9aa4 2\uff1a\u6570\u636e\u9884\u5904\u7406\u4e0e\u6e05\u6d17 \u76ee\u6807\uff1a\u5bf9\u91c7\u96c6\u5230\u7684 JSON \u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u5305\u62ec\u53bb\u9664 HTML \u6807\u7b7e\u3001\u5206\u6bb5\u5904\u7406\uff0c\u540c\u65f6\u4fdd\u7559\u56fe\u7247\u94fe\u63a5\u4fe1\u606f\u3002 \u6b65\u9aa4 3\uff1a\u6587\u672c\u5d4c\u5165\u4e0e\u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa \u76ee\u6807\uff1a\u5c06\u9884\u5904\u7406\u597d\u7684\u6587\u672c\uff08\u6bb5\u843d\uff09\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a\uff0c\u5e76\u6784\u5efa FAISS \u5411\u91cf\u68c0\u7d22\u7d22\u5f15\u3002 3.1 \u73af\u5883\u51c6\u5907 \u786e\u4fdd\u5df2\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\uff1a 3.2 \u52a0\u8f7d\u6570\u636e 3.3 \u751f\u6210\u6587\u672c\u5d4c\u5165 3.4 \u6784\u5efa FAISS \u5411\u91cf\u6570\u636e\u5e93 \u5411\u91cf\u6982\u5ff5\u89e3\u91ca \u6b65\u9aa4 4\uff1a\u68c0\u7d22\u589e\u5f3a\u751f\u6210\uff08RAG\uff09\u4e0e\u56de\u7b54\u751f\u6210 \u76ee\u6807\uff1a\u7ed3\u5408\u5df2\u6784\u5efa\u7684\u5411\u91cf\u6570\u636e\u5e93\uff0c\u5f53\u7528\u6237\u63d0\u51fa\u95ee\u9898\u65f6\uff0c\u5148\u68c0\u7d22\u6700\u76f8\u5173\u7684\u4e0a\u4e0b\u6587\uff0c\u518d\u901a\u8fc7\u672c\u5730\u90e8\u7f72\u7684\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54\u3002 4.1 \u68c0\u7d22\u76f8\u5173\u4e0a\u4e0b\u6587 4.2 \u6784\u9020 Prompt 4.3 \u8c03\u7528\u672c\u5730\u5927\u6a21\u578b\u751f\u6210\u56de\u7b54 [&hellip;]","og_url":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/","og_site_name":"\u6781\u7b80IT\uff5cSimpleIT","article_published_time":"2025-02-26T09:23:54+00:00","article_modified_time":"2025-10-10T12:18:12+00:00","og_image":[{"width":898,"height":532,"url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png","type":"image\/png"}],"author":"Ruian Ding","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ruian Ding","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#article","isPartOf":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/"},"author":{"name":"Ruian Ding","@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"headline":"LLM\u5c0f\u5b9e\u9a8c &#8211; \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba","datePublished":"2025-02-26T09:23:54+00:00","dateModified":"2025-10-10T12:18:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/"},"wordCount":65,"publisher":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"image":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png","keywords":["AI","LLM","RAG"],"articleSection":["Miscellaneous","Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/","url":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/","name":"LLM\u5c0f\u5b9e\u9a8c - \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba - \u6781\u7b80IT\uff5cSimpleIT","isPartOf":{"@id":"https:\/\/www.ruianding.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage"},"image":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png","datePublished":"2025-02-26T09:23:54+00:00","dateModified":"2025-10-10T12:18:12+00:00","breadcrumb":{"@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#primaryimage","url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png","contentUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2025\/02\/image-25.png","width":898,"height":532},{"@type":"BreadcrumbList","@id":"https:\/\/www.ruianding.com\/blog\/mini-rag-experiment\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ruianding.com\/blog\/"},{"@type":"ListItem","position":2,"name":"LLM\u5c0f\u5b9e\u9a8c &#8211; \u6784\u5efa\u4e13\u5c5e RAG\u77e5\u8bc6\u5e93 \u4e0e AI \u54a8\u8be2\u673a\u5668\u4eba"}]},{"@type":"WebSite","@id":"https:\/\/www.ruianding.com\/blog\/#website","url":"https:\/\/www.ruianding.com\/blog\/","name":"Ruian's Tech Troubleshooting Toolbox","description":"Debug the World.","publisher":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"alternateName":"\u4e01\u777f\u5b89\u7684\u6280\u672f\u5206\u4eab\u535a\u5ba2","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ruianding.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b","name":"Ruian Ding","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png","contentUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png","width":284,"height":284,"caption":"Ruian Ding"},"logo":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/"},"description":"I am currently a Support Specialist at NIO, focusing on cloud-related issues for NIO Power. Previously, at Microsoft Entra ID, I specialized in identity and access management (IAM), including device registration, Windows Hello for Business (WHfB), multi-factor authentication (MFA), and single sign-on (SSO). In addition to my core expertise, I have a strong foundation in Active Directory, Servers, Cloud Computing, Network Administration, and Front-end Web Development. This diverse technical skill set enables me to effectively handle a wide range of challenges in a fast-paced IT environment.","sameAs":["https:\/\/www.ruianding.com"],"url":"https:\/\/www.ruianding.com\/blog\/author\/ruiand\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/comments?post=2604"}],"version-history":[{"count":9,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2604\/revisions"}],"predecessor-version":[{"id":2962,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2604\/revisions\/2962"}],"wp:attachment":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/media?parent=2604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/categories?post=2604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/tags?post=2604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}