[{"data":1,"prerenderedAt":1065},["ShallowReactive",2],{"navigation_docs":3,"-ai-rag-rag-retrieval-strategy-deep-dive":352,"-ai-rag-rag-retrieval-strategy-deep-dive-surround":1060},[4,54,83,116,125,161,179,200],{"title":5,"path":6,"stem":7,"children":8},"Ai","/ai","ai",[9,12,42,46,50],{"title":10,"path":6,"stem":11},"AI 技術探索","ai/index",{"title":13,"path":14,"stem":15,"children":16,"page":41},"Rag","/ai/rag","ai/RAG",[17,21,25,29,33,37],{"title":18,"path":19,"stem":20},"BM25 演算法深入解析：從 TF-IDF 到現代搜尋引擎的核心技術","/ai/rag/bm25-deep-dive-from-tf-idf-to-rag","ai/RAG/bm25-deep-dive-from-tf-idf-to-rag",{"title":22,"path":23,"stem":24},"Dense Retrieval（向量檢索）深入解析","/ai/rag/dense-retrieval-deep-dive","ai/RAG/dense-retrieval-deep-dive",{"title":26,"path":27,"stem":28},"RAG（Retrieval-Augmented Generation）原理與實作入門","/ai/rag/rag-intro-principles-and-implementation","ai/RAG/rag-intro-principles-and-implementation",{"title":30,"path":31,"stem":32},"RAG Retrieval Strategy 深入解析","/ai/rag/rag-retrieval-strategy-deep-dive","ai/RAG/rag-retrieval-strategy-deep-dive",{"title":34,"path":35,"stem":36},"Reciprocal Rank Fusion（RRF）教學：打造更穩定的檢索融合策略","/ai/rag/rrf-reciprocal-rank-fusion-guide","ai/RAG/rrf-reciprocal-rank-fusion-guide",{"title":38,"path":39,"stem":40},"TF-IDF（Term Frequency–Inverse Document Frequency）深入解析","/ai/rag/tf-idf-deep-dive","ai/RAG/tf-idf-deep-dive",false,{"title":43,"path":44,"stem":45},"Docus AI 功能完整實作指南","/ai/docus-ai-implementation","ai/docus-ai-implementation",{"title":47,"path":48,"stem":49},"llms.txt 是什麼？在 Nuxt 中控制 AI 與搜尋引擎爬蟲的新方式","/ai/llms-txt","ai/llms-txt",{"title":51,"path":52,"stem":53},"MCP（Model Context Protocol）是什麼？用「AI 的 USB-C」理解模型如何安全連接工具與資料","/ai/mcp_concept","ai/mcp_concept",{"title":55,"path":56,"stem":57,"children":58,"page":41},"Data Analysis","/data-analysis","data-analysis",[59,63,67,71,75,79],{"title":60,"path":61,"stem":62},"Exploratory Data Analysis（EDA）資料探索分析入門","/data-analysis/exploratory-data-analysis-eda","data-analysis/exploratory-data-analysis-eda",{"title":64,"path":65,"stem":66},"PR-AUC 深入解析：不平衡分類問題的重要評估指標","/data-analysis/pr-auc-for-imbalanced-classification","data-analysis/pr-auc-for-imbalanced-classification",{"title":68,"path":69,"stem":70},"ROC-AUC 深入解析：理解分類模型的判斷能力","/data-analysis/roc-auc-complete-guide","data-analysis/roc-auc-complete-guide",{"title":72,"path":73,"stem":74},"SHAP（SHapley Additive exPlanations）模型解釋方法深入解析","/data-analysis/shap-model-interpretation-complete-guide","data-analysis/shap-model-interpretation-complete-guide",{"title":76,"path":77,"stem":78},"Social Network Analysis（SNA）深入解析","/data-analysis/social-network-analysis-sna","data-analysis/social-network-analysis-sna",{"title":80,"path":81,"stem":82},"Time-based Split：為什麼時間序列資料不能使用 Random Split？","/data-analysis/time-based-split-vs-random-split","data-analysis/time-based-split-vs-random-split",{"title":84,"path":85,"stem":86,"children":87,"page":41},"MachineLearning","/machine_learning","machine_learning",[88,92,96,100,104,108,112],{"title":89,"path":90,"stem":91},"Confusion Matrix（混淆矩陣）完整解析","/machine_learning/confusion-matrix","machine_learning/confusion-matrix",{"title":93,"path":94,"stem":95},"Decision Tree 模型完整教學：從原理到 Python 實作","/machine_learning/decision-tree-complete-guide","machine_learning/decision-tree-complete-guide",{"title":97,"path":98,"stem":99},"為什麼 Decision Tree 在 Tabular Data 上常常勝過 Deep Learning？","/machine_learning/decision-tree-vs-deep-learning-on-tabular-data","machine_learning/decision-tree-vs-deep-learning-on-tabular-data",{"title":101,"path":102,"stem":103},"LightGBM 模型入門：理解高效能的 Gradient Boosting 演算法","/machine_learning/lightgbm-intro-for-tabular-data","machine_learning/lightgbm-intro-for-tabular-data",{"title":105,"path":106,"stem":107},"Logistic Regression（Logit 回歸）完整教學","/machine_learning/logistic-regression-complete-guide","machine_learning/logistic-regression-complete-guide",{"title":109,"path":110,"stem":111},"為什麼模型訓練需要 Train / Validation / Test Dataset？","/machine_learning/train-validation-test-dataset","machine_learning/train-validation-test-dataset",{"title":113,"path":114,"stem":115},"XGBoost 原理與實務教學","/machine_learning/xgboost-complete-guide","machine_learning/xgboost-complete-guide",{"title":117,"path":118,"stem":119,"children":120,"page":41},"Network","/network","network",[121],{"title":122,"path":123,"stem":124},"DNS 設定入門：CNAME vs A Record 完整解析","/network/dns-cname-vs-a-record-guide","network/dns-cname-vs-a-record-guide",{"title":126,"path":127,"stem":128,"children":129},"Nuxt","/nuxt","nuxt",[130,133,137,141,145,149,153,157],{"title":131,"path":127,"stem":132},"Nuxt 實戰指南","nuxt/index",{"title":134,"path":135,"stem":136},"Abstraction Layer 與 Adapter 的差別，一次搞懂設計角色","/nuxt/adapter_abstraction_layer","nuxt/adapter_abstraction_layer",{"title":138,"path":139,"stem":140},"Nuxt 4 全面理解 — 專案檔案結構解析","/nuxt/directory_structure","nuxt/directory_structure",{"title":142,"path":143,"stem":144},"Nuxt 前端 build 流程完整解析","/nuxt/frontend_build","nuxt/frontend_build",{"title":146,"path":147,"stem":148},"Nitro 是什麼？從 Nuxt 專案到 Server 與 Edge 的關鍵引擎","/nuxt/nitro","nuxt/nitro",{"title":150,"path":151,"stem":152},"深入理解 Nuxt 的 .nuxt 與 .output：為什麼部署時一定要分清楚？","/nuxt/nuxt_and_output","nuxt/nuxt_and_output",{"title":154,"path":155,"stem":156},"Nuxt 中 dev、build、preview 的差異一次搞懂","/nuxt/nuxt_dev_build_preview","nuxt/nuxt_dev_build_preview",{"title":158,"path":159,"stem":160},"Nuxt Image vs \u003Cimg>：為什麼 Nuxt 3 專案幾乎都該用 \u003CNuxtImg>？","/nuxt/nuxt_image","nuxt/nuxt_image",{"title":162,"path":163,"stem":164,"children":165},"Python 程式開發","/python","python/index",[166,167,171,175],{"title":162,"path":163,"stem":164},{"title":168,"path":169,"stem":170},"如何在 FastAPI 中調用記憶體 Buffer 回傳圖片 (附實例)","/python/memory_buffer","python/memory_buffer",{"title":172,"path":173,"stem":174},"Python 單元測試教學：如何為你的程式撰寫 Test","/python/python-unit-testing-unittest-pytest","python/python-unit-testing-unittest-pytest",{"title":176,"path":177,"stem":178},"如何使用 uv 取代 pip：改善 Python 專案的開發流程","/python/uv","python/uv",{"title":180,"path":181,"stem":182,"children":183,"page":41},"Statistic","/statistic","statistic",[184,188,192,196],{"title":185,"path":186,"stem":187},"卡方檢定（Chi-Square Test）入門教學","/statistic/chi-square-test-intro","statistic/chi-square-test-intro",{"title":189,"path":190,"stem":191},"常見抽樣方法（Sampling Methods）教學：Stratified、Quota、Convenience、Systematic、Simple Random","/statistic/common-sampling-methods-guide","statistic/common-sampling-methods-guide",{"title":193,"path":194,"stem":195},"Cramér’s V 指標介紹：如何衡量兩個類別變數之間的關聯","/statistic/cramers-v-for-categorical-association","statistic/cramers-v-for-categorical-association",{"title":197,"path":198,"stem":199},"Mann–Whitney U 與 Kolmogorov–Smirnov（KS）檢定：非參數統計檢定的入門指南","/statistic/mann-whitney-u-and-ks-test-intro","statistic/mann-whitney-u-and-ks-test-intro",{"title":201,"path":202,"stem":203,"children":204},"WebDev","/web_dev","web_dev",[205,208,234,248,282,312,334],{"title":206,"path":202,"stem":207},"Web 前端開發","web_dev/index",{"title":209,"path":210,"stem":211,"children":212},"瀏覽器與渲染","/web_dev/browser","web_dev/browser/index",[213,214,218,222,226,230],{"title":209,"path":210,"stem":211},{"title":215,"path":216,"stem":217},"瀏覽器儲存空間完整解析：Cookie、localStorage、IndexedDB 到 Cache Storage","/web_dev/browser/browser-storage-comprehensive-guide","web_dev/browser/browser-storage-comprehensive-guide",{"title":219,"path":220,"stem":221},"DOM (Document Object Model) 深入解析","/web_dev/browser/dom","web_dev/browser/dom",{"title":223,"path":224,"stem":225},"Service Worker Request Flow 深入解析","/web_dev/browser/service-worker-request-flow","web_dev/browser/service-worker-request-flow",{"title":227,"path":228,"stem":229},"CSR、SSR 與 SSG 是什麼？前端渲染策略完整比較","/web_dev/browser/ssr_csr_ssg","web_dev/browser/ssr_csr_ssg",{"title":231,"path":232,"stem":233},"Virtual DOM 深入解析：為什麼它能優化前端效能？","/web_dev/browser/virtual_dom","web_dev/browser/virtual_dom",{"title":235,"path":236,"stem":237,"children":238},"圖形技術","/web_dev/graphics","web_dev/graphics/index",[239,240,244],{"title":235,"path":236,"stem":237},{"title":241,"path":242,"stem":243},"為什麼 Three.js 專案幾乎都選擇 CSR？從 SSR 問題談起","/web_dev/graphics/threejs_csr","web_dev/graphics/threejs_csr",{"title":245,"path":246,"stem":247},"WebGL 是什麼？為什麼前端 3D 幾乎都靠它？","/web_dev/graphics/webgl","web_dev/graphics/webGL",{"title":249,"path":250,"stem":251,"children":252},"架構與配置","/web_dev/infrastructure","web_dev/infrastructure/index",[253,254,258,262,266,270,274,278],{"title":249,"path":250,"stem":251},{"title":255,"path":256,"stem":257},"Zeabur + K3s + Nuxt 部署架構完整解析","/web_dev/infrastructure/k3s-zeabur","web_dev/infrastructure/K3s-zeabur",{"title":259,"path":260,"stem":261},"ECS vs Docker vs Kubernetes：從部署堆疊理解三層架構","/web_dev/infrastructure/ecs-docker-kubernetes-stack","web_dev/infrastructure/ecs-docker-kubernetes-stack",{"title":263,"path":264,"stem":265},"ECS vs VPS 是什麼？從部署網站的角度一次搞懂差別","/web_dev/infrastructure/ecs-vs-vps","web_dev/infrastructure/ecs-vs-vps",{"title":267,"path":268,"stem":269},"Zeabur 內網服務連線完整入門指南","/web_dev/infrastructure/k3s-internal-networking","web_dev/infrastructure/k3s-internal-networking",{"title":271,"path":272,"stem":273},"使用 Microservices 架構設計系統的優勢解析","/web_dev/infrastructure/microservices-architecture-advantages","web_dev/infrastructure/microservices-architecture-advantages",{"title":275,"path":276,"stem":277},"Nginx 入門教學：從反向代理到與 Kubernetes 的架構比較","/web_dev/infrastructure/nginx-intro","web_dev/infrastructure/nginx-intro",{"title":279,"path":280,"stem":281},"YAML 配置是什麼？為什麼現代開發都在用它","/web_dev/infrastructure/yaml-configuration","web_dev/infrastructure/yaml-configuration",{"title":283,"path":284,"stem":285,"children":286},"網絡與通訊","/web_dev/network","web_dev/network/index",[287,288,292,296,300,304,308],{"title":283,"path":284,"stem":285},{"title":289,"path":290,"stem":291},"HTTP Request 結構完整解析：從 Request Line 到 Header 一次看懂","/web_dev/network/http-request-structure","web_dev/network/http-request-structure",{"title":293,"path":294,"stem":295},"OSI 模型（Open Systems Interconnection Model）完整解析","/web_dev/network/osi-model","web_dev/network/osi-model",{"title":297,"path":298,"stem":299},"RESTful API 設計原則與實務解析","/web_dev/network/restful-api","web_dev/network/restful-api",{"title":301,"path":302,"stem":303},"RESTful API 五大設計原則深入解析","/web_dev/network/restful-api-principles","web_dev/network/restful-api-principles",{"title":305,"path":306,"stem":307},"Server-Sent Events (SSE) 深入解析與實作教學","/web_dev/network/sse-introduction","web_dev/network/sse-introduction",{"title":309,"path":310,"stem":311},"WebSocket 入門教學：從概念到 Node.js 實作","/web_dev/network/websocket-introduction","web_dev/network/websocket-introduction",{"title":313,"path":314,"stem":315,"children":316},"認證與安全","/web_dev/security","web_dev/security/index",[317,318,322,326,330],{"title":313,"path":314,"stem":315},{"title":319,"path":320,"stem":321},"使用 Cookie 與 Session 建立使用者驗證（完整新手教學）","/web_dev/security/cookie-session-authentication","web_dev/security/cookie-session-authentication",{"title":323,"path":324,"stem":325},"JWT 驗證機制完整解析：從登入流程到實務應用","/web_dev/security/jwt-authentication","web_dev/security/jwt-authentication",{"title":327,"path":328,"stem":329},"Secret Key 簽名是什麼？從零理解資料簽名的本質","/web_dev/security/secret-key-signing","web_dev/security/secret-key-signing",{"title":331,"path":332,"stem":333},"SSH（Secure Shell）是什麼？從遠端登入到安全通道的核心概念","/web_dev/security/ssh","web_dev/security/ssh",{"title":335,"path":336,"stem":337,"children":338},"SEO 與規範","/web_dev/seo","web_dev/seo/index",[339,340,344,348],{"title":335,"path":336,"stem":337},{"title":341,"path":342,"stem":343},"Canonical URL 是什麼？用生活化方式搞懂前端 SEO 的基本保命符","/web_dev/seo/canonical_link","web_dev/seo/canonical_link",{"title":345,"path":346,"stem":347},"robots.txt 是什麼？SEO 的第一道守門員","/web_dev/seo/robot_txt","web_dev/seo/robot_txt",{"title":349,"path":350,"stem":351},"Nuxt SEO 中的 Meta 與 SEO 工具是如何運作的？","/web_dev/seo/seo","web_dev/seo/seo",{"id":353,"title":30,"body":354,"description":1045,"extension":1046,"links":1047,"meta":1048,"navigation":1057,"path":31,"seo":1058,"stem":32,"__hash__":1059},"docs/ai/RAG/rag-retrieval-strategy-deep-dive.md",{"type":355,"value":356,"toc":1031},"minimark",[357,362,371,390,393,402,405,409,412,423,426,454,461,463,467,481,488,491,497,500,506,517,523,526,533,536,542,545,551,554,556,560,570,573,579,586,593,599,606,609,626,633,640,646,649,651,655,662,665,671,674,686,689,723,726,731,734,740,743,749,755,757,761,767,770,776,779,786,792,799,802,816,819,824,827,833,836,838,842,845,851,858,860,864,867,945,951,953,957,960,977,980,982,985,991,998,1000,1003],[358,359,361],"h2",{"id":360},"為什麼-retrieval-是-rag-系統的核心","為什麼 Retrieval 是 RAG 系統的核心",[363,364,365,366,370],"p",{},"在 ",[367,368,369],"strong",{},"Retrieval-Augmented Generation（RAG）"," 架構中，整個系統的表現往往取決於「檢索階段（Retrieval）」的品質。雖然生成模型（LLM）負責最後的回答，但如果提供給模型的 context 文件品質不佳，即使是再強大的語言模型也無法生成正確答案。",[363,372,373,374,377,378,381,382,385,386,389],{},"這也是為什麼在許多實務系統中，工程師會花大量時間優化 ",[367,375,376],{},"retrieval strategy","。從最早的 ",[367,379,380],{},"BM25 keyword search","，逐漸演進到 ",[367,383,384],{},"Dense Retrieval","，再到目前主流的 ",[367,387,388],{},"Hybrid Retrieval + Reranker 架構","。這些技術的核心目的都是相同的：盡可能找到最相關的文件，讓 LLM 能基於正確的資訊進行回答。",[363,391,392],{},"換句話說，在 RAG 系統中可以把流程簡化為一句話：",[394,395,396],"blockquote",{},[363,397,398,401],{},[367,399,400],{},"Garbage in, garbage out"," —— 如果檢索到的內容品質差，生成結果幾乎不可能正確。",[403,404],"hr",{},[358,406,408],{"id":407},"rag-retrieval-的整體架構","RAG Retrieval 的整體架構",[363,410,411],{},"在多數 production 等級的 RAG 系統中，retrieval pipeline 通常會包含多個階段，而不是單一搜尋方法。典型架構如下：",[413,414,420],"pre",{"className":415,"code":417,"language":418,"meta":419},[416],"language-text","User Query\n   │\n   ▼\nQuery Embedding\n   │\n   ▼\nRetrieval Layer\n├─ Sparse Retrieval (BM25)\n├─ Dense Retrieval\n└─ Hybrid Retrieval\n   │\n   ▼\nReranker (Cross Encoder / LLM)\n   │\n   ▼\nTop-K Relevant Documents\n   │\n   ▼\nLLM Generation\n   │\n   ▼\nFinal Answer\n","text","",[421,422,417],"code",{"__ignoreMap":419},[363,424,425],{},"在這個架構中，每一層都有不同的角色：",[427,428,429,436,442,448],"ul",{},[430,431,432,435],"li",{},[367,433,434],{},"Sparse retrieval","：負責精確關鍵字搜尋",[430,437,438,441],{},[367,439,440],{},"Dense retrieval","：負責語意搜尋",[430,443,444,447],{},[367,445,446],{},"Hybrid retrieval","：整合兩者結果",[430,449,450,453],{},[367,451,452],{},"Reranker","：進一步提升排序品質",[363,455,456,457,460],{},"透過這樣的分層設計，可以在 ",[367,458,459],{},"速度、召回率（recall）與精確度（precision）之間取得平衡","。",[403,462],{},[358,464,466],{"id":465},"sparse-retrievalbm25-與關鍵字搜尋","Sparse Retrieval：BM25 與關鍵字搜尋",[363,468,469,470,473,474,477,478,460],{},"最早期、也是最經典的資訊檢索方法，是 ",[367,471,472],{},"Sparse Retrieval","。這類方法主要依賴「關鍵字匹配」，而不是語意理解。常見的演算法包括 ",[367,475,476],{},"TF-IDF"," 與 ",[367,479,480],{},"BM25",[363,482,483,484,487],{},"在 BM25 的搜尋流程中，系統會先將所有文件建立 ",[367,485,486],{},"倒排索引（inverted index）","。當使用者輸入查詢時，系統會根據 query 中的關鍵字，快速找到包含這些詞彙的文件，並依照 BM25 scoring 進行排序。",[363,489,490],{},"例如，假設使用者輸入查詢：",[413,492,495],{"className":493,"code":494,"language":418,"meta":419},[416],"credit card fraud detection\n",[421,496,494],{"__ignoreMap":419},[363,498,499],{},"BM25 會優先找出包含這些關鍵詞的文件，例如：",[413,501,504],{"className":502,"code":503,"language":418,"meta":419},[416],"credit card fraud detection model\n",[421,505,503],{"__ignoreMap":419},[363,507,508,509,512,513,516],{},"這種方法的優點在於 ",[367,510,511],{},"速度極快","，因為倒排索引可以在極短時間內完成搜尋。此外，BM25 對於 ",[367,514,515],{},"精確關鍵字查詢"," 特別有效，例如：",[413,518,521],{"className":519,"code":520,"language":418,"meta":419},[416],"API endpoint error code 403\n",[421,522,520],{"__ignoreMap":419},[363,524,525],{},"這類技術文件搜尋通常會有非常好的效果。",[363,527,528,529,532],{},"然而，Sparse Retrieval 最大的限制是 ",[367,530,531],{},"缺乏語意理解能力","。如果 query 和文件使用不同的詞彙，即使語意相同，也可能無法被匹配。例如：",[363,534,535],{},"Query：",[413,537,540],{"className":538,"code":539,"language":418,"meta":419},[416],"信用卡盜刷\n",[421,541,539],{"__ignoreMap":419},[363,543,544],{},"Document：",[413,546,549],{"className":547,"code":548,"language":418,"meta":419},[416],"fraud transaction detection\n",[421,550,548],{"__ignoreMap":419},[363,552,553],{},"由於關鍵字不同，BM25 很可能無法成功找到相關文件。",[403,555],{},[358,557,559],{"id":558},"dense-retrieval向量搜尋","Dense Retrieval：向量搜尋",[363,561,562,563,565,566,569],{},"為了解決語意搜尋的問題，研究者提出了 ",[367,564,384],{},"。這種方法不再依賴關鍵字，而是透過 ",[367,567,568],{},"embedding 向量"," 來表示文本的語意。",[363,571,572],{},"Dense Retrieval 的流程通常如下：",[413,574,577],{"className":575,"code":576,"language":418,"meta":419},[416],"Query\n  ↓\nEmbedding\n  ↓\nVector Search\n  ↓\nSimilar Documents\n",[421,578,576],{"__ignoreMap":419},[363,580,581,582,585],{},"在這個過程中，query 與文件都會被轉換成高維向量，系統會透過 ",[367,583,584],{},"向量相似度（例如 cosine similarity）"," 找到最接近的文件。",[363,587,588,589,592],{},"Dense Retrieval 的最大優勢在於 ",[367,590,591],{},"語意理解能力","。例如：",[413,594,597],{"className":595,"code":596,"language":418,"meta":419},[416],"fraud detection ≈ transaction anomaly detection\n",[421,598,596],{"__ignoreMap":419},[363,600,601,602,605],{},"即使文字不同，向量空間仍然能夠捕捉語意上的相似性。此外，Dense Retrieval 對於 ",[367,603,604],{},"長文本與跨語言搜尋"," 也通常表現更好。",[363,607,608],{},"目前常見的向量資料庫包括：",[427,610,611,614,617,620,623],{},[430,612,613],{},"Chroma",[430,615,616],{},"Pinecone",[430,618,619],{},"Weaviate",[430,621,622],{},"FAISS",[430,624,625],{},"Milvus",[363,627,628,629,632],{},"這些系統通常會結合 ",[367,630,631],{},"ANN（Approximate Nearest Neighbor）演算法","，讓向量搜尋在大規模資料下仍能保持高效率。",[363,634,635,636,639],{},"然而，Dense Retrieval 也有一些限制。例如在 ",[367,637,638],{},"精確 keyword 查詢"," 上，它的表現往往不如 BM25。例如：",[413,641,644],{"className":642,"code":643,"language":418,"meta":419},[416],"error code 0x80070005\n",[421,645,643],{"__ignoreMap":419},[363,647,648],{},"這類查詢需要非常精確的字串匹配，而向量模型未必能理解這些技術代碼的意義。",[403,650],{},[358,652,654],{"id":653},"hybrid-retrieval結合-sparse-與-dense","Hybrid Retrieval：結合 Sparse 與 Dense",[363,656,657,658,661],{},"由於 Sparse Retrieval 與 Dense Retrieval 各有優缺點，現代 RAG 系統通常會採用 ",[367,659,660],{},"Hybrid Retrieval","，同時結合兩種搜尋方式。",[363,663,664],{},"Hybrid Retrieval 的基本架構如下：",[413,666,669],{"className":667,"code":668,"language":418,"meta":419},[416],"Query\n │\n ├── BM25\n │\n └── Dense Retrieval\n      │\n      ▼\n Merge Ranking\n",[421,670,668],{"__ignoreMap":419},[363,672,673],{},"在實作上，系統會同時執行 BM25 搜尋與向量搜尋，然後將兩組結果合併並重新排序。常見的方法包括：",[427,675,676,681],{},[430,677,678],{},[367,679,680],{},"Score Fusion",[430,682,683],{},[367,684,685],{},"Reciprocal Rank Fusion（RRF）",[363,687,688],{},"Hybrid Retrieval 的優勢在於可以同時取得：",[690,691,692,705],"table",{},[693,694,695],"thead",{},[696,697,698,702],"tr",{},[699,700,701],"th",{},"能力",[699,703,704],{},"來源",[706,707,708,716],"tbody",{},[696,709,710,714],{},[711,712,713],"td",{},"Keyword precision",[711,715,480],{},[696,717,718,721],{},[711,719,720],{},"Semantic search",[711,722,384],{},[363,724,725],{},"例如 query：",[413,727,729],{"className":728,"code":503,"language":418,"meta":419},[416],[421,730,503],{"__ignoreMap":419},[363,732,733],{},"BM25 可能會找到：",[413,735,738],{"className":736,"code":737,"language":418,"meta":419},[416],"fraud detection model\n",[421,739,737],{"__ignoreMap":419},[363,741,742],{},"而 Dense Retrieval 可能會找到：",[413,744,747],{"className":745,"code":746,"language":418,"meta":419},[416],"transaction anomaly detection\n",[421,748,746],{"__ignoreMap":419},[363,750,751,752,460],{},"Hybrid 方法能夠同時捕捉這兩種類型的文件，因此通常能大幅提升 ",[367,753,754],{},"retrieval recall",[403,756],{},[358,758,760],{"id":759},"reranker提升檢索品質的關鍵","Reranker：提升檢索品質的關鍵",[363,762,763,764,460],{},"即使使用 Hybrid Retrieval，初步檢索的結果仍然可能包含許多「語意相似但不完全相關」的文件。因此許多系統會在 retrieval 之後加入 ",[367,765,766],{},"Reranker（第二階排序）",[363,768,769],{},"典型流程如下：",[413,771,774],{"className":772,"code":773,"language":418,"meta":419},[416],"Query\n  ↓\nRetrieve Top 50 documents\n  ↓\nReranker\n  ↓\nTop 5 documents\n",[421,775,773],{"__ignoreMap":419},[363,777,778],{},"Reranker 的核心概念是使用更精確但較慢的模型，重新評估 query 與每個文件之間的相關性。",[363,780,781,782,785],{},"最常見的技術是 ",[367,783,784],{},"Cross-Encoder","。與 embedding 模型不同，Cross-Encoder 會直接把 query 與 document 一起輸入模型：",[413,787,790],{"className":788,"code":789,"language":418,"meta":419},[416],"[Query] + [Document]\n",[421,791,789],{"__ignoreMap":419},[363,793,794,795,798],{},"模型會輸出一個 ",[367,796,797],{},"relevance score","，用來判斷該文件是否真正相關。",[363,800,801],{},"常見的 reranker 模型包括：",[427,803,804,807,810,813],{},[430,805,806],{},"BGE Reranker",[430,808,809],{},"monoT5",[430,811,812],{},"Cohere Rerank",[430,814,815],{},"OpenAI Rerank",[363,817,818],{},"Reranker 的重要性在於：向量相似度並不一定等於真正的「相關性」。例如 query：",[413,820,822],{"className":821,"code":494,"language":418,"meta":419},[416],[421,823,494],{"__ignoreMap":419},[363,825,826],{},"Dense Retrieval 可能找到：",[413,828,831],{"className":829,"code":830,"language":418,"meta":419},[416],"bank transaction analysis\n",[421,832,830],{"__ignoreMap":419},[363,834,835],{},"雖然語意相近，但未必是最相關的文件。Reranker 可以透過更精細的語意理解重新排序，從而顯著提升最終 Top-K 文件的品質。",[403,837],{},[358,839,841],{"id":840},"production-等級-rag-架構","Production 等級 RAG 架構",[363,843,844],{},"在企業實務中，許多 RAG 系統會採用以下架構：",[413,846,849],{"className":847,"code":848,"language":418,"meta":419},[416],"User Query\n   │\n   ▼\nQuery Processing\n   │\n   ▼\nHybrid Retrieval (BM25 + Dense)\n   │\n   ▼\nTop 50 Documents\n   │\n   ▼\nReranker (Cross Encoder)\n   │\n   ▼\nTop 5 Context\n   │\n   ▼\nLLM (GPT / Claude / Llama)\n   │\n   ▼\nAnswer\n",[421,850,848],{"__ignoreMap":419},[363,852,853,854,857],{},"這種設計能在 ",[367,855,856],{},"召回率（recall）與精確度（precision）之間取得良好平衡","，同時控制推理成本。",[403,859],{},[358,861,863],{"id":862},"不同-retrieval-方法的比較","不同 Retrieval 方法的比較",[363,865,866],{},"不同 retrieval strategy 在語意理解、速度與效果上各有差異：",[690,868,869,888],{},[693,870,871],{},[696,872,873,876,879,882,885],{},[699,874,875],{},"方法",[699,877,878],{},"語意理解",[699,880,881],{},"Keyword 精確度",[699,883,884],{},"速度",[699,886,887],{},"效果",[706,889,890,906,918,930],{},[696,891,892,894,897,900,903],{},[711,893,480],{},[711,895,896],{},"低",[711,898,899],{},"高",[711,901,902],{},"非常快",[711,904,905],{},"中",[696,907,908,910,912,914,916],{},[711,909,384],{},[711,911,899],{},[711,913,905],{},[711,915,905],{},[711,917,905],{},[696,919,920,922,924,926,928],{},[711,921,660],{},[711,923,899],{},[711,925,899],{},[711,927,905],{},[711,929,899],{},[696,931,932,935,938,940,943],{},[711,933,934],{},"Hybrid + Reranker",[711,936,937],{},"非常高",[711,939,899],{},[711,941,942],{},"較慢",[711,944,937],{},[363,946,947,948,950],{},"因此，在實務系統中，",[367,949,934],{}," 已逐漸成為最主流的 RAG retrieval strategy。",[403,952],{},[358,954,956],{"id":955},"retrieval-品質對-rag-表現的影響","Retrieval 品質對 RAG 表現的影響",[363,958,959],{},"如果 RAG 系統的 accuracy 非常低，常見原因通常並不是 LLM 本身，而是 retrieval 階段的品質不足。例如：",[427,961,962,965,968,971,974],{},[430,963,964],{},"只使用 Dense Retrieval",[430,966,967],{},"文件 chunking 設計不佳",[430,969,970],{},"Top-K 設定過小",[430,972,973],{},"embedding model 表現不佳",[430,975,976],{},"缺乏 reranker",[363,978,979],{},"這些因素都會導致系統無法找到真正相關的文件，進而讓 LLM 在缺乏正確 context 的情況下生成答案。",[403,981],{},[358,983,984],{"id":984},"結論",[363,986,987,988,460],{},"在 RAG 系統中，retrieval strategy 是影響模型品質最重要的因素之一。從早期的 BM25 keyword search，到後來的 Dense Retrieval，再到現今主流的 Hybrid Retrieval 與 Reranker，整個技術演進的核心目標都是提升 ",[367,989,990],{},"檢索品質與文件相關性排序能力",[363,992,993,994,997],{},"透過多層次的 retrieval pipeline，系統能同時兼顧 ",[367,995,996],{},"關鍵字匹配、語意搜尋與精細排序","，從而提供 LLM 更高品質的 context。當 retrieval 能夠穩定找到最相關的文件時，RAG 系統的整體回答品質也會隨之顯著提升。",[403,999],{},[358,1001,1002],{"id":1002},"參考資料",[1004,1005,1006,1013,1019,1025],"ol",{},[430,1007,1008,1009],{},"Lewis, Patrick et al. ",[1010,1011,1012],"em",{},"Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.",[430,1014,1015,1016],{},"Robertson, Stephen & Zaragoza, Hugo. ",[1010,1017,1018],{},"The Probabilistic Relevance Framework: BM25.",[430,1020,1021,1022],{},"Reimers, Nils & Gurevych, Iryna. ",[1010,1023,1024],{},"Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks.",[430,1026,1027,1028],{},"Gao, Luyu et al. ",[1010,1029,1030],{},"Reranking for Information Retrieval with Cross-Encoders.",{"title":419,"searchDepth":1032,"depth":1032,"links":1033},2,[1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044],{"id":360,"depth":1032,"text":361},{"id":407,"depth":1032,"text":408},{"id":465,"depth":1032,"text":466},{"id":558,"depth":1032,"text":559},{"id":653,"depth":1032,"text":654},{"id":759,"depth":1032,"text":760},{"id":840,"depth":1032,"text":841},{"id":862,"depth":1032,"text":863},{"id":955,"depth":1032,"text":956},{"id":984,"depth":1032,"text":984},{"id":1002,"depth":1032,"text":1002},"從 BM25、Dense Retrieval 到 Hybrid 與 Reranker，完整理解 RAG 系統中的檢索策略與其對模型品質的影響。","md",null,{"tags":1049,"category":1055,"date":1056},[1050,1051,1052,1053,1054,7],"rag","retrieval","bm25","vector-search","llm","RAG","2026-03-13",true,{"title":30,"description":1045},"y-ftqoIzh4hq3vNGxlfl2nJb8xpz_aUzGBwPVJehvxk",[1061,1063],{"title":26,"path":27,"stem":28,"description":1062,"children":-1},"介紹 Retrieval-Augmented Generation（RAG）的核心概念、系統架構與實作流程，理解大型語言模型如何透過外部知識提升回答品質。",{"title":34,"path":35,"stem":36,"description":1064,"children":-1},"深入理解 RRF（Reciprocal Rank Fusion）如何結合多種檢索結果，提升搜尋與 RAG 系統的準確度與穩定性。",1776690844748]