R2R 检索与 RAG 实战指南:从向量搜索、混合检索到流式生成
R2R 检索与 RAG 实战指南从向量搜索、混合检索到流式生成【免费下载链接】R2RSoTA production-ready AI retrieval system. Agentic Retrieval-Augmented Generation (RAG) with a RESTful API.项目地址: https://gitcode.com/GitHub_Trending/r2/R2RR2R 是一套生产可用的 AI 检索系统围绕/retrieval/search与/retrieval/rag两个核心端点提供了向量搜索、全文搜索、混合搜索Hybrid Search以及检索增强生成RAG的完整能力。本文以 search-and-rag.md 为主线结合仓库内的路由实现、服务层源码与集成测试系统讲解search_mode、search_settings、过滤语法、距离度量、知识图谱增强与流式 RAG 的配置与调用方式。读完本文你将能够在 R2R 中按需组合语义检索、关键词检索与 LLM 生成构建可落地、可调试的检索问答管线。阅读前提文档与代码示例均针对 R2R v3 API。默认服务地址为http://localhost:7272示例中的https://api.sciphi.ai为官方托管服务地址自建部署时请替换为本地地址。所有请求都需要在Authorization: Bearer头中携带有效令牌使用认证功能时。检索的核心控制面search_mode与search_settings无论是调用 Search 还是 RAG 端点检索过程都由两个参数共同驱动search_mode可选默认custom选择预设模式或完全自定义。basic默认使用简单的语义搜索配置适合快速上手advanced默认使用结合语义与全文的混合搜索配置召回面更广custom通过search_settings对象完全自定义。若custom模式下省略search_settings则应用默认向量搜索配置。search_settings可选细粒度配置对象。如果与basic或advanced模式同时提供这些设置会覆盖模式的默认值。关键字段包括字段类型默认值说明use_semantic_searchbooltrue启用/禁用基于向量的语义搜索use_fulltext_searchboolfalse启用/禁用基于关键词的全文搜索use_hybrid_searchboolfalse启用混合搜索语义 全文需要配合hybrid_settingsfiltersdict{}使用 MongoDB 风格语法应用复杂过滤规则见下文高级过滤limitint10返回结果的最大数量hybrid_settingsobject—配置混合搜索的权重semantic_weight、full_text_weight、限制full_text_limit与融合参数rrf_kchunk_settingsobject—微调向量索引参数如index_measure距离度量、probes、ef_searchsearch_strategystringvanilla启用 HyDE 或 RAG-Fusion 等高级 RAG 技术见 高级 RAG 指南include_scoresbooltrue是否在结果中包含相关性分数include_metadatasbooltrue是否在结果中包含元数据从源码看这些字段在 py/shared/abstractions/search.py 的SearchSettings中被正式定义。值得注意的默认值与约束limit被限制在1 ~ 1000之间ge1, le1_000还提供offset字段默认0用于分页search_strategy的可选值在服务层被解释为vanilla基础检索、hydeHyDE与rag_fusionRAG-Fusion代码注释中还提及了query_fusion当使用 HyDE 或 RAG-Fusion 策略时num_sub_queries默认5控制生成子查询/假设文档的数量。SearchSettings.get_default(mode)方法search.py展示了三种模式的实际差异basic模式仅开启use_semantic_searchTrueadvanced模式则同时开启语义与全文并默认采用hyde策略custom模式返回空配置所有字段使用默认值。模式与设置如何合并路由层的真实逻辑在 py/core/main/api/v3/retrieval_router.py 的_prepare_search_settings中可以看到模式与覆盖参数的合并逻辑若search_mode ! custom先从SearchSettings.get_default(mode.value)取模式默认配置若用户同时提供了search_settings则调用merge_search_settings将用户设置逐字段覆盖到模式默认值上exclude_unsetTrue保证只有显式设置的字段才参与覆盖custom模式则直接使用传入的search_settings否则使用默认的SearchSettings()最后调用select_search_filters(auth_user, effective_settings)为当前用户注入权限相关的过滤条件——非超级用户会被自动追加owner_id 当前用户或collection_ids与用户可见集合重叠的$or约束见 search.py。这意味着过滤与权限在路由层自动叠加即使调用方未显式传filters非超级用户也只会检索到属于自己的文档或所属集合内的文档。纯检索/retrieval/search/retrieval/search返回原始检索结果不经过 LLM 生成。它适合需要直接消费检索证据、做二次重排或构建自定义管线的场景。基本搜索示例# Uses default settings (likely semantic search in custom mode) results client.retrieval.search( queryWhat is DeepSeek R1?, ) # Explicitly using basic mode results_basic client.retrieval.search( queryWhat is DeepSeek R1?, search_modebasic, )// Uses default settings const results await client.retrieval.search({ query: What is DeepSeek R1?, }); // Explicitly using basic mode const resultsBasic await client.retrieval.search({ query: What is DeepSeek R1?, searchMode: basic, });# Uses default settings curl -X POST https://api.sciphi.ai/v3/retrieval/search \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: What is DeepSeek R1? } # Explicitly using basic mode curl -X POST https://api.sciphi.ai/v3/retrieval/search \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: What is DeepSeek R1?, search_mode: basic }在路由层retrieval_router.pysearch_app会校验query非空空查询直接返回 400随后调用services.retrieval.search(query, effective_settings)并返回WrappedSearchResponse。Python SDK 与 JS SDK 的对应方法分别位于 py/sdk/asnyc_methods/retrieval.py 与 js/sdk/src/v3/clients/retrieval.ts。响应结构WrappedSearchResponseSearch 端点返回WrappedSearchResponse其中包含AggregateSearchResult对象主要字段如下results.chunk_search_results相关文本块ChunkSearchResult列表包含id、document_id、text、score、metadataresults.graph_search_results相关GraphSearchResult列表实体、关系、社区在图检索激活且有结果时出现results.web_search_resultsWebSearchResult列表若网络搜索被启用通常网络搜索经由 RAG/Agent 路径完成。// Simplified Example Structure { results: { chunk_search_results: [ { score: 0.643, text: Document Title: DeepSeek_R1.pdf..., id: chunk-uuid-..., document_id: doc-uuid-..., metadata: { ... } }, // ... more chunks ], graph_search_results: [ // Example: An entity result if graph search ran { id: graph-entity-uuid..., content: { name: DeepSeek-R1, description: A large language model..., id: entity-uuid... }, result_type: ENTITY, score: 0.95, metadata: { ... } } // ... potentially relationships or communities ], web_search_results: [] } }对照 py/shared/abstractions/search.pyChunkSearchResult的实际字段为id、document_id、owner_id、collection_ids、score、text、metadataGraphSearchResultsearch.py则通过content字段承载GraphEntityResult/GraphRelationshipResult/GraphCommunityResult三种类型之一并以result_type区分entity/relationship/community。混合搜索示例将基于关键词的全文检索与向量检索结合可以获得更广的召回。hybrid_results client.retrieval.search( queryWhat was Ubers profit in 2020?, search_settings{ use_hybrid_search: True, hybrid_settings: { full_text_weight: 1.0, semantic_weight: 5.0, full_text_limit: 200, # How many full-text results to initially consider rrf_k: 50, # Parameter for Reciprocal Rank Fusion }, filters: {metadata.title: {$in: [uber_2021.pdf]}}, # Filter by metadata field limit: 10 # Final number of results after fusion/ranking }, )const hybridResults await client.retrieval.search({ query: What was Ubers profit in 2020?, searchSettings: { useHybridSearch: true, hybridSettings: { fullTextWeight: 1.0, semanticWeight: 5.0, fullTextLimit: 200, rrfK: 50 // Assuming camelCase mapping in JS SDK }, filters: {metadata.title: {$in: [uber_2021.pdf]}}, limit: 10 }, });curl -X POST https://api.sciphi.ai/v3/retrieval/search \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: What was Uber\s profit in 2020?, search_settings: { use_hybrid_search: true, hybrid_settings: { full_text_weight: 1.0, semantic_weight: 5.0, full_text_limit: 200, rrf_k: 50 }, filters: {metadata.title: {$in: [uber_2021.pdf]}}, limit: 10, chunk_settings: { index_measure: l2_distance } } }HybridSearchSettings在 search.py 中定义了四个字段full_text_weight默认1.0、semantic_weight默认5.0、full_text_limit默认200与rrf_k默认50。其中rrf_k是 Reciprocal Rank Fusion倒数排名融合的平滑常数k用于合并两路检索排名从服务层实现可以看到RAG-Fusion 策略的融合逻辑_reciprocal_rank_fusion_chunkspy/core/main/services/retrieval_service.py使用的 RRF 分数公式为1 / (k rank)默认k60。在服务层_vector_search_logicretrieval_service.py中混合检索的条件是use_fulltext_search use_semantic_search或use_hybrid_search为真此时调用chunks_handler.hybrid_search(query_vector, query_text, search_settings)随后所有检索结果都会经过completion_embedding.arerank(query, results, limit)做一次基于原查询语义的重排并为每条结果写入associated_query元数据、在存在标题时拼接Document Title: ...前缀——这也解释了示例响应中text字段为何带有文档标题。高级过滤基于文档属性或元数据缩小检索范围。支持的运算符包括$eq、$neq、$gt、$gte、$lt、$lte、$like、$ilike、$in、$nin并可通过$and与$or组合多个条件。filtered_results client.retrieval.search( queryWhat are the effects of climate change?, search_settings{ filters: { $and:[ {document_type: {$eq: pdf}}, # Assuming document_type is stored {metadata.year: {$gt: 2020}} # Access nested metadata fields ] }, limit: 10 } )const filteredResults await client.retrieval.search({ query: What are the effects of climate change?, searchSettings: { filters: { $and: [ {document_type: {$eq: pdf}}, {metadata.year: {$gt: 2020}} ] }, limit: 10 } });从 py/core/providers/database/filters.py 可以看到FilterOperator定义了完整的运算符集合除上述列出的比较/匹配运算符外还包含$overlap检查数组是否有共同元素底层映射为 PostgreSQL 的、$contains、$not_contains、$array_contains、$length等并支持$and/$or组合。值得注意的两点$like/$ilike要求字段值为字符串$ilike大小写不敏感当collection_ids使用$eq时查询会被自动映射为$overlap见 filters.py方便用集合 ID 直接圈定检索范围。向量搜索的距离度量通过chunk_settings.index_measure参数可配置向量检索的距离度量。选择合适的度量会显著影响检索质量具体取决于嵌入模型与使用场景cosine_distance默认度量向量间的夹角余弦忽略向量长度。最适合比较不同长度的文档。l2_distance欧氏距离度量向量间的直线距离。当方向与长度都重要时适用。max_inner_product针对寻找方向相似向量的场景优化。适合推荐系统。l1_distance曼哈顿距离度量各维度绝对差之和。对离群值不如 L2 敏感。hamming_distance统计向量各位置不同的数量。最适合二值嵌入。jaccard_distance度量样本集合间的不相似度。适用于稀疏嵌入。results client.retrieval.search( queryWhat are the key features of quantum computing?, search_settings{ chunk_settings: { index_measure: l2_distance # Use Euclidean distance instead of default } } )对于大多数文本嵌入模型如 OpenAI 的模型推荐使用cosine_distance。对于特殊嵌入或特定场景可以实验不同度量以找到数据的最优配置。IndexMeasure枚举定义在 py/shared/abstractions/vector.py后端如 pgvector通过算子映射对应 cosine、#对应 max_inner_product 等见同文件 L60-L72执行对应索引扫描ChunkSearchSettingssearch.py中还提供了probes默认10ivfflat 索引查询的列表数量与ef_search默认40HNSW 索引的动态候选列表大小两者调高可提升准确率但降低速度。知识图谱增强检索除文本块检索外R2R 还可以利用知识图谱丰富检索过程带来以下收益上下文理解知识图谱以实体如人物、组织、概念与关系如就职于相关于是……的一种存储信息。在图谱中检索可以发现纯文本检索容易遗漏的关联与上下文。基于关系的查询回答依赖连接关系的问题例如人物 X 参与了哪些项目或概念 A 与概念 B 之间有何关联。结构发现图检索可以揭示更高层的结构例如数据中相关实体的社区或关键连接性概念。结果互补图结果实体、关系、社区摘要通过提供结构化信息与更广上下文与文本块形成互补。当知识图谱搜索在 R2R 中激活时Search 或 RAG 端点返回的AggregateSearchResult会在graph_search_results列表中携带相关项从而为理解或生成提供更丰富的上下文。在服务层_graph_search_logicretrieval_service.py中图检索默认通过graph_settings.enabled默认true开启依次执行实体entities、关系relationships、社区communities三类搜索分别受graph_settings.limits中的entities/relationships/communities键控制未设置时回退到search_settings.limit并且同样支持include_scores与include_metadatas开关。因此即使只调用 Search 端点只要数据集中构建了知识图谱返回结果就可能同时包含文本块与图实体/关系/社区。检索增强生成/retrieval/ragR2R 的 RAG 引擎将上文所述的检索能力文本、向量、混合以及可选的图谱结果与 LLM 结合生成以你摄入文档以及可选的网络搜索结果为事实依据、上下文相关的回答。RAG 生成配置rag_generation_config控制 LLM 生成过程的主要参数model指定使用的 LLM例如openai/gpt-4o-mini、anthropic/claude-3-haiku-20240307。默认值在 R2R 配置中设定。stream布尔值默认false。设为true时启用流式响应。temperature、max_tokens、top_p等标准 LLM 生成参数。GenerationConfig的完整字段定义在 py/shared/abstractions/llm.py除上述参数外还包括max_tokens_to_sample默认1024兼容max_tokens写法并自动映射、top_p默认1.0、functions/tools、api_base、response_format支持传入 Pydantic 模型以 JSON Schema 方式结构化输出以及 Anthropic 的extended_thinking/thinking_budget与 OpenAI 的reasoning_effort。在 retrieval_router.py 中若请求未显式指定model路由会自动回退到config.app.quality_llm指定的质量模型。基本 RAG使用与 Search 端点相同的search_mode与search_settings检索相关信息再生成回答。# Basic RAG call using default search and generation settings rag_response client.retrieval.rag(queryWhat is DeepSeek R1?)// Basic RAG call using default settings const ragResponse await client.retrieval.rag({ query: What is DeepSeek R1? });curl -X POST https://api.sciphi.ai/v3/retrieval/rag \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: What is DeepSeek R1? }RAG 端点还额外支持task_prompt自定义任务提示词覆盖默认值与include_title_if_available在可用时把文档标题加入 LLM 上下文默认false。响应结构WrappedRAGResponse非流式 RAG 端点返回WrappedRAGResponse其中RAGResponse对象包含以下字段results.generated_answerLLM 合成的最终回答。results.search_results用于生成回答的AggregateSearchResult包含文本块可能还有图结果与网络结果。results.citationsCitation对象列表将回答的各个部分链接到search_results中的具体来源ChunkSearchResult、GraphSearchResult、WebSearchResult等。每条引用包含id文本中使用的短标识符如[1]与包含来源对象的payload。results.metadata关于本次生成调用的 LLM 提供商元数据。// Simplified Example Structure { results: { generated_answer: DeepSeek-R1 is a model that... [1]. It excels in tasks... [2]., search_results: { chunk_search_results: [ { id: chunk-abc..., text: ..., score: 0.8 }, /* ... */ ], graph_search_results: [ { /* Graph Entity/Relationship */ } ], web_search_results: [ { url: ..., title: ..., snippet: ... }, /* ... */ ] }, citations: [ { id: cit.1, // Corresponds to [1] in text object: citation, payload: { /* ChunkSearchResult for chunk-abc... */ } }, { id: cit.2, // Corresponds to [2] in text object: citation, payload: { /* WebSearchResult for relevant web page */ } } // ... more citations potentially linking to graph results too ], metadata: { model: openai/gpt-4o-mini, ... } } }非流式 RAG 的完整执行链路在 retrieval_service.py先执行聚合检索得到aggregated_results用format_search_results_for_llm构建上下文从 prompts 库加载system与rag提示词模板并注入query与context再调用 LLM回答文本中的短 ID 引用通过extract_citations提取并借助SearchResultsCollector将短 ID 映射回完整来源对象组装成citations。RAG 集成网络搜索通过设置include_web_searchTrue可以让 RAG 响应补充来自网络的最新信息。web_rag_response client.retrieval.rag( queryWhat are the latest developments with DeepSeek R1?, include_web_searchTrue )const webRagResponse await client.retrieval.rag({ query: What are the latest developments with DeepSeek R1?, includeWebSearch: true // Use camelCase for JS SDK });curl -X POST https://api.sciphi.ai/v3/retrieval/rag \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: What are the latest developments with DeepSeek R1?, include_web_search: true }启用后R2R 会基于查询执行一次网络搜索服务层_perform_web_search见 retrieval_service.py并将结果合并进AggregateSearchResult.web_search_results随文档/图谱结果一并提供给 LLM。注意此功能依赖服务端配置的网络搜索提供商仓库中可看到 py/core/utils/serper.py 与tavily.toml配置示例以及 py/core/base/agent/tools/built_in/tavily_search.py 等工具。RAG 结合混合搜索通过配置search_settings将混合检索与 RAG 结合。hybrid_rag_response client.retrieval.rag( queryWho is Jon Snow?, search_settings{use_hybrid_search: True} )const hybridRagResponse await client.retrieval.rag({ query: Who is Jon Snow?, searchSettings: { useHybridSearch: true }, });# Correctly place use_hybrid_search in search_settings curl -X POST https://api.sciphi.ai/v3/retrieval/rag \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: Who is Jon Snow?, search_settings: { use_hybrid_search: true, limit: 10 } }流式 RAGSSE在rag_generation_config中设置stream: True即可将 RAG 响应以 Server-Sent EventsSSE流的形式接收非常适合实时应用。事件类型search_results包含初始AggregateSearchResult开始时发送一次。data完整的AggregateSearchResult对象文本块可能有图结果、网络结果。message随生成过程流式推送部分 token。data.delta.content正在流式传输的文本片段。citation当某个引用来源被识别时触发。每个唯一来源在首次被引用时发送一次。data.id短引用 ID如cit.1。data.payload完整来源对象ChunkSearchResult、GraphSearchResult、WebSearchResult等。data.is_new若该引用 ID 首次发送则为True。data.span当前累计文本中引用标记如[1]出现的起始/结束字符索引。final_answer结束时发送一次包含完整生成回答与结构化引用。data.generated_answer完整最终文本。data.citations全部引用列表包含id、payload以及它们在最终文本中出现的所有spans。from r2r import ( CitationEvent, FinalAnswerEvent, MessageEvent, SearchResultsEvent, R2RClient, ) # Set streamTrue in rag_generation_config result_stream client.retrieval.rag( queryWhat is DeepSeek R1?, search_settings{limit: 25}, rag_generation_config{stream: True, model: openai/gpt-4o-mini}, include_web_searchTrue, ) for event in result_stream: if isinstance(event, SearchResultsEvent): print(fSearch results received (Chunks: {len(event.data.data.chunk_search_results)}, Graph: {len(event.data.data.graph_search_results)}, Web: {len(event.data.data.web_search_results)})) elif isinstance(event, MessageEvent): # Access the actual text delta if event.data.delta and event.data.delta.content and event.data.delta.content[0].type text and event.data.delta.content[0].payload.value: print(event.data.delta.content[0].payload.value, end, flushTrue) elif isinstance(event, CitationEvent): # Payload is only sent when is_new is True if event.data.is_new: print(f\n New Citation Source Detected: ID{event.data.id} ) elif isinstance(event, FinalAnswerEvent): print(\n\n--- Final Answer ---) print(event.data.generated_answer) print(\n--- Citations Summary ---) for cit in event.data.citations: print(f ID: {cit.id}, Spans: {cit.span})// Set stream: true in ragGenerationConfig const resultStream await client.retrieval.rag({ query: What is DeepSeek R1?, searchSettings: { limit: 25 }, ragGenerationConfig: { stream: true, model: openai/gpt-4o-mini }, includeWebSearch: true, }); // Check if we got an async iterator (streaming) if (Symbol.asyncIterator in resultStream) { console.log(Starting stream processing...); // Loop over each event from the server for await (const event of resultStream) { switch (event.event) { case search_results: console.log(\nSearch results received (Chunks: ${event.data.chunk_search_results?.length || 0}, Graph: ${event.data.graph_search_results?.length || 0}, Web: ${event.data.web_search_results?.length || 0})); break; case message: // Access the actual text delta if (event.data?.delta?.content?.[0]?.text?.value) { process.stdout.write(event.data.delta.content[0].text.value); } break; case citation: // Payload only sent when is_new is true if (event.data?.is_new) { process.stdout.write(\n New Citation Source Detected: ID${event.data.id} ); } else { // Citation already seen, no need to log payload again } break; case final_answer: process.stdout.write(\n\n--- Final Answer ---\n); console.log(event.data.generated_answer); console.log(\n--- Citations Summary ---); event.data.citations?.forEach(cit { console.log( ID: ${cit.id}, Spans: ${JSON.stringify(cit.spans)}); }); break; default: console.log(\nUnknown or unhandled event:, event.event); } } console.log(\nStream finished.); } else { // Handle non-streaming response if necessary (though we requested stream) console.log(Received non-streaming response:, resultStream); }流式链路的服务端实现在 retrieval_service.py先通过SSEFormatter.yield_search_results_event发送检索结果事件随后逐 chunk 消费 LLM 流对每个文本增量先发送message事件再用find_new_citation_spans在累计文本中查找新出现的引用短 ID并通过CitationTracker判定是否为首次出现——首次出现时携带完整payload后续仅携带id与span收到finish_reason stop后发送包含全部引用含所有出现位置spans的final_answer事件最后发送结束信号。路由层retrieval_router.py将生成器包装为text/event-stream的StreamingResponse。自定义 RAG除search_settings外可以通过rag_generation_config自定义 RAG 生成过程。使用 Anthropic 模型并开启网络搜索的示例# Requires ANTHROPIC_API_KEY env var if using Anthropic models response client.retrieval.rag( queryWho was Aristotle and what are his recent influences?, rag_generation_config{ model:anthropic/claude-3-haiku-20240307, stream: False, # Get a single response object temperature: 0.5 }, include_web_searchTrue ) print(response.results.generated_answer)// Requires ANTHROPIC_API_KEY env var if using Anthropic models const response await client.retrieval.rag({ query: Who was Aristotle and what are his recent influences?, ragGenerationConfig: { model: anthropic/claude-3-haiku-20240307, temperature: 0.5, stream: false // Get a single response object }, includeWebSearch: true }); console.log(response.results.generated_answer);# Requires ANTHROPIC_API_KEY env var if using Anthropic models curl -X POST https://api.sciphi.ai/v3/retrieval/rag \ -H Content-Type: application/json \ -H Authorization: Bearer YOUR_API_KEY \ -d { query: Who was Aristotle and what are his recent influences?, rag_generation_config: { model: anthropic/claude-3-haiku-20240307, temperature: 0.5, stream: false }, include_web_search: true }检索策略的分发与实现原理/retrieval/search与/retrieval/rag共用同一套检索内核RetrievalService.searchretrieval_service.py根据search_settings.search_strategy将请求分发到三条路径vanilla默认_basic_search——对查询做嵌入执行向量/全文/混合检索随后做图检索最后合并为AggregateSearchResulthyde_hyde_search——先用 LLM 基于查询生成num_sub_queries个假设文档使用的提示词模板见 py/core/providers/database/prompts/hyde.yaml要求生成互相独立、避免跨文档信息的候选回答再对每个假设文档并行做块检索与图检索最后用原始查询对所有结果做语义重排rag_fusion_rag_fusion_search——先用 LLM 生成num_sub_queries - 1个改写查询连同原查询组成查询集对每个查询分别做块/图检索再用 Reciprocal Rank Fusion 对多路排名做融合最后同样经过一次语义重排。也就是说search_strategy不仅作用于 RAG 端点对纯/retrieval/search同样生效。关于 HyDE 与 RAG-Fusion 的详细原理、流程图与组合用法可继续阅读 高级 RAG 指南。测试与验证仓库在 py/tests/integration/test_retrieval.py 中提供了覆盖检索与 RAG 主路径的集成测试如use_semantic_search、limit、混合检索、过滤等各类search_settings组合JS SDK 侧则在 js/sdk/tests/RetrievalIntegrationSuperUser.test.ts 中验证了client.retrieval.search/client.retrieval.rag的端到端行为。结合 docs/cookbooks/rag.md、docs/cookbooks/hybrid-search.md 与 docs/cookbooks/advanced-rag.md 的烹饪手册可以在本地把检索链路跑通后再逐步叠加混合检索、过滤、图检索与流式 RAG。小结R2R 的检索与 RAG 能力为找到信息并对其进行上下文化提供了高度灵活的机制从一行代码的语义搜索到带权重与 RRF 融合的混合检索再到叠加元数据过滤、知识图谱增强与网络搜索的完整 RAG 管线均可通过search_mode、search_settings与rag_generation_config在运行时按需组合。无论你需要简单语义搜索、面向更广召回的混合检索还是融合文档块、图谱洞察与网络结果流式或单次响应的可定制 RAG 生成这套系统都能通过配置满足具体需求。【免费下载链接】R2RSoTA production-ready AI retrieval system. Agentic Retrieval-Augmented Generation (RAG) with a RESTful API.项目地址: https://gitcode.com/GitHub_Trending/r2/R2R创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考