GraphRAG中settings.yaml文件详解(学习笔记)

张开发
2026/5/30 14:25:25 15 分钟阅读
GraphRAG中settings.yaml文件详解(学习笔记)
settings.yaml 是 GraphRAG 的核心配置文件用于定义索引和查询阶段的各项参数包括LLM 连接API key、模型、端点、文本分块大小、图提取策略、社区报告生成、存储与缓存路径等。它使 GraphRAG 的行为可配置、可复现。本文将介绍该配置文件对应的4种search模式以及对应的提示词含义。全部代码### This config file contains required core defaults that must be set, along with a handful of common optional settings.### For a full list of available settings, see https://microsoft.github.io/graphrag/config/yaml/### LLM settings ##### There are a number of settings to tune the threading and token limits for LLM calls - check the docs.models:default_chat_model:type:chatmodel_provider:openaiauth_type:api_key# or azure_managed_identityapi_key:${GRAPHRAG_API_KEY}# set this in the generated .env file, or remove if managed identitymodel:gpt-4-turbo-preview# api_base: https://instance.openai.azure.com# api_version: 2024-05-01-previewmodel_supports_json:true# recommended if this is available for your model.concurrent_requests:25async_mode:threaded# or asyncioretry_strategy:exponential_backoffmax_retries:10tokens_per_minute:nullrequests_per_minute:nulldefault_embedding_model:type:embeddingmodel_provider:openaiauth_type:api_keyapi_key:${GRAPHRAG_API_KEY}model:text-embedding-3-small# api_base: https://instance.openai.azure.com# api_version: 2024-05-01-previewconcurrent_requests:25async_mode:threaded# or asyncioretry_strategy:exponential_backoffmax_retries:10tokens_per_minute:nullrequests_per_minute:null### Input settings ###input:storage:type:file# or blobbase_dir:inputfile_type:text# [csv, text, json]chunks:size:1200overlap:100group_by_columns:[id]### Output/storage settings ##### If blob storage is specified in the following four sections,## connection_string and container_name must be providedoutput:type:file# [file, blob, cosmosdb]base_dir:outputcache:type:file# [file, blob, cosmosdb]base_dir:cachereporting:type:file# [file, blob]base_dir:logsvector_store:default_vector_store:type:lancedbdb_uri:output\lancedbcontainer_name:default### Workflow settings ###embed_text:model_id:default_embedding_modelvector_store_id:default_vector_storeextract_graph:model_id:default_chat_modelprompt:prompts/extract_graph.txtentity_types:[organization,person,geo,event]max_gleanings:1summarize_descriptions:model_id:default_chat_modelprompt:prompts/summarize_descriptions.txtmax_length:500extract_graph_nlp:text_analyzer:extractor_type:regex_english# [regex_english, syntactic_parser, cfg]async_mode:threaded# or asynciocluster_graph:max_cluster_size:10##能容纳多少实体extract_claims:enabled:falsemodel_id:default_chat_modelprompt:prompts/extract_claims.txtdescription:Any claims or facts that could be relevant to information discovery.max_gleanings:1community_reports:model_id:default_chat_modelgraph_prompt:prompts/community_report_graph.txttext_prompt:prompts/community_report_text.txtmax_length:2000max_input_length:8000embed_graph:enabled:false# if true, will generate node2vec embeddings for nodesumap:enabled:false# if true, will generate UMAP embeddings for nodes (embed_graph must also be enabled)snapshots:graphml:falseembeddings:false### Query settings ##### The prompt locations are required here, but each search method has a number of optional knobs that can be tuned.## See the config docs: https://microsoft.github.io/graphrag/config/yaml/#querylocal_search:chat_model_id:default_chat_modelembedding_model_id:default_embedding_modelprompt:prompts/local_search_system_prompt.txtglobal_search:chat_model_id:default_chat_modelmap_prompt:prompts/global_search_map_system_prompt.txtreduce_prompt:prompts/global_search_reduce_system_prompt.txtknowledge_prompt:prompts/global_search_knowledge_system_prompt.txtdrift_search:chat_model_id:default_chat_modelembedding_model_id:default_embedding_modelprompt:prompts/drift_search_system_prompt.txtreduce_prompt:prompts/drift_search_reduce_prompt.txtbasic_search:chat_model_id:default_chat_modelembedding_model_id:default_embedding_modelprompt:prompts/basic_search_system_prompt.txtlocal_search:chat_model_id:default_chat_model embedding_model_id:default_embedding_model prompt:prompts/local_search_system_prompt.txt这是 GraphRAG 中 local_search局部检索 功能的配置用于基于实体邻近关系进行局部上下文检索。各字段含义如下chat_model_id: default_chat_model指定局部检索时用于生成最终回答的对话模型LLM对应配置文件中预定义的模型。embedding_model_id: default_embedding_model指定用于将查询和实体/关系向量化的嵌入模型用于计算相似度以找到与查询最相关的局部子图。prompt: “prompts/local_search_system_prompt.txt”指向局部检索的系统提示词模板文件用于指导模型如何利用从知识图谱中提取的局部上下文相关实体、关系、描述等生成回答。简单说明local_search 聚焦于用户查询中涉及的特定实体周围的小范围子图通过检索该实体的直接邻居及相关信息来回答事实性问题通常比 global_search 更精确、响应更快。这个配置块定义了驱动该过程所需的模型和提示词模板。这段提示词是 GraphRAG 中用于“多源表格数据检索”的系统提示模板常用于 Local Search 或融合检索场景。核心作用如下数据源多样化可同时引用多种表格类型包括 Sources来源、Reports报告、Entities实体、Relationships关系、Claims声明等。引用格式扩展允许在一条引用中混合列出不同数据集及其记录 ID例如 [Data: Sources (15, 16), Reports (1), Entities (5, 7); Relationships (23); Claims (2, 7, 34, 46, 64, more)]。回答原则基于表格数据回答融入通用知识不知道就说不知道每个数据支持的论点必须标注引用每条引用不超过 5 个 ID超出用 more 表示。输出格式按 {response_type} 指定的长度和样式生成 Markdown 回答可分段加注释。该模板的特点在于支持异构数据源的联合引用使模型能够从实体、关系、声明等不同维度综合回答适用于需要精确溯源和复杂推理的检索增强问答场景。global_search:chat_model_id:default_chat_model map_prompt:prompts/global_search_map_system_prompt.txtreduce_prompt:prompts/global_search_reduce_system_prompt.txtknowledge_prompt:prompts/global_search_knowledge_system_prompt.txt这是 GraphRAG 中 global_search全局检索 功能的配置用于基于社区摘要等信息进行全局理解。各字段含义如下chat_model_id: default_chat_model指定执行全局检索时使用的对话模型LLM。map_prompt: “prompts/global_search_map_system_prompt.txt”指向 Map 阶段的系统提示词模板用于将全局数据如多个社区报告拆解成多个独立子任务生成中间答案。reduce_prompt: “prompts/global_search_reduce_system_prompt.txt”指向 Reduce 阶段的提示词模板用于将 Map 阶段生成的所有中间答案汇总、融合成最终回答。knowledge_prompt: “prompts/global_search_knowledge_system_prompt.txt”指向知识提示词模板用于指导模型在生成回答时如何利用社区摘要等结构化知识增强回答的全局一致性。简单说global_search 采用 Map-Reduce 模式处理大规模全局数据通过这四个配置项控制模型和分步提示词。第一个提示词适合需要结构化输出、对信息进行重要性量化的场景常用于自动化流程或需要进一步计算的下游任务。第二个提示词适合需要自然语言总结、融合多个不同来源信息、生成可读性高且带来源追溯的最终答案是 GraphRAG 全局检索Global Search中 Reduce 步骤的典型模板。两者可以串联使用先用第一个从表格中提取关键点再用第二个将多个关键点视为“分析师报告”合成最终答案。但在 GraphRAG 内置流程中它们是针对不同数据形态和输出需求独立设计的drift_search:chat_model_id:default_chat_model embedding_model_id:default_embedding_model prompt:prompts/drift_search_system_prompt.txtreduce_prompt:prompts/drift_search_reduce_prompt.txt这是 GraphRAG 中 drift_search漂移检索 功能的配置用于控制一种能够动态调整检索方向的搜索策略。各字段含义如下chat_model_id: default_chat_model指定用于生成最终回答的对话模型对应配置文件中预定义的 LLM如 llm 部分的模型。embedding_model_id: default_embedding_model指定用于将查询和文档向量化的嵌入模型用于相似度计算和路由判断。prompt: “prompts/drift_search_system_prompt.txt”指向漂移检索的系统提示词模板文件用于指导模型如何根据初始查询生成新的子查询或调整检索方向。reduce_prompt: “prompts/drift_search_reduce_prompt.txt”指向归约提示词模板文件用于将多次漂移检索得到的多个中间结果汇总、去重并合成最终答案。简单说drift_search 通过多轮“生成子查询 → 检索 → 合并”的方式逐步探索与原始问题相关的不同方面减少信息遗漏。这个配置块定义了驱动该过程所需的模型和提示词模板。这两个模板分别是 GraphRAG 的“表格检索提示词” 和 “报告检索提示词”用于指导大模型基于不同数据源回答用户问题。第一个表格检索数据源结构化表格tables如实体、关系、来源表。要求特别关注 Sources 表引用格式 [Data: 数据集名 (记录ID)]可融入通用知识但不强制标注来源。输出JSON包含 responseMarkdown 回答不回答 {global_query}、score0-100 评分、follow_up_queries最多 5 个后续问题。第二个报告检索数据源报告文本reports如社区摘要。要求若使用通用知识必须标注 [Data: General Knowledge (href)]且不能编造。输出纯 Markdown 文本无需 JSON无评分或追问。核心区别数据源不同表格 vs 报告通用知识的处理不同表格版不强制标注报告版必须标注输出格式不同JSON vs 纯文本表格版额外要求评分和后续问题。basic_search:chat_model_id:default_chat_model embedding_model_id:default_embedding_model prompt:prompts/basic_search_system_prompt.txt这是 GraphRAG 中 basic_search基础检索功能的配置chat_model_id: default_chat_model指定用于生成最终回答的聊天模型对应配置文件中预定义的模型如 llm 部分。embedding_model_id: default_embedding_model指定用于将查询文本向量化的嵌入模型用于计算查询与文本块的相似度。prompt: “prompts/basic_search_system_prompt.txt”指向一个外部文本文件其中定义了基础检索时使用的系统提示词system prompt用于指导模型如何基于检索到的上下文生成回答。简单说这个配置块控制 GraphRAG 在基础检索模式下用哪个模型做回答、用哪个模型做向量检索以及使用什么提示词模板。对应的提示词模板含义在 GraphRAG 中当用户提问后系统会把检索到的相关数据表格形式和这段提示词一起发给大模型让模型按照提示词里的规则来生成最终回答。 主要规则包括 只根据提供的表格数据回答数据里没有的就说不知道绝不编造。 每个观点必须标注数据来源source_id格式如[Data:Sources(1,2,3)]且每条引用不超过5个ID。 输出长度和格式由{response_type}变量控制并使用 Markdown 排版。 简单说这是一个强制模型基于事实、可溯源回答的“约束模板”用来提升 GraphRAG 回答的准确性和可信度。

更多文章