Token导航 LogoToken导航

Agent Skill · 研究检索

graphrag(graphrag 搜索)

graphrag 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

graphrag 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 64,959。

总安装 291周安装 12GitHub Stars 公开资料未说明下载 95核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:graphrag(graphrag 搜索)
来源仓库:https://github.com/aeonbridge/ab-anthropic-claude-skills
仓库路径:skills/graphrag
安装命令:
npx skills add https://github.com/aeonbridge/ab-anthropic-claude-skills --skill graphrag
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/aeonbridge/ab-anthropic-claude-skills --skill graphrag

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于基于图结构的信息检索与知识关联分析。graphrag 属于研究检索类 Skill,可作为该场景下的辅助能力补充。适合从复杂文档集中定位关键节点与关系路径。使用时需提供关键词、任务目标或初始实体作为起点。可返回候选结果列表及相关上下文片段供人工筛选。安装前请确认是否允许联网抓取或访问私有知识库。

来源仓库内路径:skills/graphrag

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/aeonbridge/ab-anthropic-claude-skills --skill…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

graphrag 怎么安装?

在终端执行 npx skills add https://github.com/aeonbridge/ab-anthropic-claude-skills --skill graphrag。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

graphrag 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

graphrag 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

graphrag 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

graphrag 用的人多吗?

公开数据是累计安装 291 次,近一周安装 12 次,下载 95 次。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

graphrag 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
graphrag

graphrag 搜索 · 本页

291—接触敏感数据未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Microsoft GraphRAG Skill

Expert assistance for using Microsoft GraphRAG, a modular graph-based Retrieval-Augmented Generation system that extracts structured knowledge from unstructured text to enhance LLM reasoning over private data.

When to Use This Skill

This skill should be used when:

  • Building RAG systems that need to "connect the dots" across dispersed information
  • Querying large document collections holistically
  • Extracting structured knowledge graphs from unstructured text
  • Implementing graph-based retrieval for LLM applications
  • Processing private datasets with enhanced reasoning capabilities
  • Working with narrative, unstructured documents
  • Building question-answering systems over document corpora
  • Extracting entities, relationships, and claims from text
  • Creating hierarchical knowledge summaries
  • Implementing multi-hop reasoning over documents
  • Comparing GraphRAG with traditional vector-based RAG
  • Tuning prompts for domain-specific datasets
  • Configuring indexing pipelines for knowledge extraction

Overview

What is GraphRAG?

Microsoft GraphRAG is a data pipeline and transformation system that:

  • Extracts meaningful, structured data from unstructured text using LLMs
  • Builds knowledge graph memory structures
  • Enhances LLM outputs through graph-based retrieval
  • Supports private data processing without external exposure

Core Innovation:

"GraphRAG addresses fundamental limitations of baseline RAG: connecting the dots across disparate information pieces and holistically understanding summarized concepts over large collections."

Key Differentiators from Baseline RAG

Traditional vector-based RAG has limitations:

  • ❌ Struggles to connect information across multiple documents
  • ❌ Limited holistic understanding of document collections
  • ❌ Misses relationships between dispersed facts
  • ❌ Poor performance on "summarize the corpus" queries

GraphRAG solves these with:

  • ✅ Knowledge graph extraction from text
  • ✅ Hierarchical community detection
  • ✅ Multi-level summarization
  • ✅ Graph-based reasoning and traversal
  • ✅ Better performance on complex queries

Core Concepts

1. Knowledge Graph Extraction

GraphRAG extracts three primary elements:

Entities: Objects, people, places, concepts

Examples:
- "Microsoft" (Organization)
- "Seattle" (Location)
- "Cloud Computing" (Concept)
- "Satya Nadella" (Person)

Relationships: Connections between entities

Examples:
- Microsoft → headquartered_in → Seattle
- Satya Nadella → is_CEO_of → Microsoft
- Microsoft → provides → Cloud Computing

Claims: Factual statements with supporting evidence

Examples:
- "Microsoft is the largest software company" [Source: Document X, Page 5]
- "Azure revenue grew 30% in Q4" [Source: Earnings Report]

2. Hierarchical Community Detection

GraphRAG uses the Leiden algorithm to:

  • Cluster related entities into communities
  • Create hierarchical levels of organization
  • Generate summaries at each level
  • Enable bottom-up reasoning

Example Hierarchy:

Level 0 (Detailed):
  Community 1: Azure services (Compute, Storage, Networking)
  Community 2: Office products (Word, Excel, PowerPoint)

Level 1 (Mid-level):
  Community A: Cloud services (includes Community 1)
  Community B: Productivity tools (includes Community 2)

Level 2 (High-level):
  Community X: Microsoft product ecosystem (includes A & B)

3. TextUnits

Documents are segmented into TextUnits:

  • Manageable chunks for analysis
  • Sized based on token limits
  • Overlapping to preserve context
  • Form the basis of entity extraction

4. Query Modes

GraphRAG offers multiple search strategies:

Global Search: Holistic corpus reasoning

  • Best for: "Summarize the main themes"
  • Uses: Community summaries at all levels
  • Method: Bottom-up aggregation

Local Search: Entity-specific reasoning

  • Best for: "Tell me about Entity X"
  • Uses: Entity neighborhoods in graph
  • Method: Traversal from seed entities

DRIFT Search: Entity reasoning with community context

  • Best for: "How does X relate to broader themes?"
  • Uses: Entities + community summaries
  • Method: Hybrid approach

Basic Search: Traditional vector similarity

  • Best for: Simple semantic matching
  • Uses: Embedding similarity
  • Method: Baseline RAG fallback

Installation

Prerequisites

# Python 3.10 or higher required
python --version

# Install GraphRAG
pip install graphrag

# Or install from source
git clone https://github.com/microsoft/graphrag.git
cd graphrag
pip install -e .

Environment Setup

# Create environment file
cat > .env << EOF
# LLM Configuration (OpenAI)
GRAPHRAG_LLM_API_KEY=your-openai-api-key
GRAPHRAG_LLM_TYPE=openai_chat
GRAPHRAG_LLM_MODEL=gpt-4o

# Embedding Configuration
GRAPHRAG_EMBEDDING_API_KEY=your-openai-api-key
GRAPHRAG_EMBEDDING_TYPE=openai_embedding
GRAPHRAG_EMBEDDING_MODEL=text-embedding-3-small

# Optional: Azure OpenAI
# GRAPHRAG_LLM_API_BASE=https://your-resource.openai.azure.com
# GRAPHRAG_LLM_API_VERSION=2024-02-15-preview
# GRAPHRAG_LLM_DEPLOYMENT_NAME=gpt-4

# Optional: Local models
# GRAPHRAG_LLM_TYPE=ollama
# GRAPHRAG_LLM_API_BASE=http://localhost:11434
EOF

Quick Start

1. Initialize Project

# Create new GraphRAG project
mkdir my-graphrag-project
cd my-graphrag-project

# Initialize configuration
graphrag init --root .

# This creates:
# - settings.yaml (configuration)
# - .env (environment variables)
# - prompts/ (customizable prompts)

2. Prepare Your Data

# Create input directory
mkdir -p input

# Add your documents
cp /path/to/documents/*.txt input/

# Supported formats: .txt, .pdf, .docx, .md
# Each file will be processed independently

3. Run Indexing Pipeline

# Index your data (this can take time and cost money!)
graphrag index --root .

# The indexing process will:
# 1. Load and chunk documents
# 2. Extract entities, relationships, claims
# 3. Build knowledge graph
# 4. Detect communities (Leiden algorithm)
# 5. Generate community summaries
# 6. Create embeddings
# 7. Store results in output/

# Monitor progress
graphrag index --root . --verbose

4. Query Your Data

# Global Search (holistic queries)
graphrag query --root . \
  --method global \
  --query "What are the main themes in this dataset?"

# Local Search (entity-specific queries)
graphrag query --root . \
  --method local \
  --query "Tell me about Microsoft's cloud strategy"

# DRIFT Search (entity + community context)
graphrag query --root . \
  --method drift \
  --query "How does Azure relate to the broader Microsoft ecosystem?"

Configuration

settings.yaml Structure

# Core Configuration
llm:
  api_key: ${GRAPHRAG_LLM_API_KEY}
  type: openai_chat  # or azure_openai_chat, ollama
  model: gpt-4o
  max_tokens: 4000
  temperature: 0
  top_p: 1

embeddings:
  api_key: ${GRAPHRAG_EMBEDDING_API_KEY}
  type: openai_embedding
  model: text-embedding-3-small

# Chunking Configuration
chunks:
  size: 1200          # Token size per chunk
  overlap: 100        # Overlap between chunks
  group_by_columns: [id]

# Entity Extraction
entity_extraction:
  prompt: "prompts/entity_extraction.txt"
  max_gleanings: 1    # Re-extraction passes
  entity_types: [organization, person, location, event]

# Community Detection
community_reports:
  prompt: "prompts/community_report.txt"
  max_length: 2000
  max_input_length: 8000

# Claim Extraction
claim_extraction:
  enabled: true
  prompt: "prompts/claim_extraction.txt"
  max_gleanings: 1

# Embeddings
embed_graph:
  enabled: true
  strategy: node2vec  # or deepwalk

# Storage
storage:
  type: file          # or blob, cosmosdb
  base_dir: output

# Reporting
reporting:
  type: file
  base_dir: output/reports

Advanced Configuration Options

# Custom LLM Configuration
llm:
  type: azure_openai_chat
  api_base: https://your-resource.openai.azure.com
  api_version: "2024-02-15-preview"
  deployment_name: gpt-4
  api_key: ${AZURE_OPENAI_API_KEY}
  request_timeout: 180
  max_retries: 10
  max_retry_wait: 10

# Parallelization
parallelization:
  stagger: 0.3        # Delay between requests
  num_threads: 4      # Concurrent workers

# Cache Configuration
cache:
  type: file
  base_dir: cache

# Input Configuration
input:
  type: file
  file_type: text     # or csv, parquet
  base_dir: input
  encoding: utf-8
  file_pattern: ".*\\.txt$"

Prompt Tuning

Why Tune Prompts?

"Using GraphRAG with your data out of the box may not yield the best possible results."

Domain-specific datasets require custom prompts for:

  • Relevant entity types
  • Appropriate relationship types
  • Domain-specific language
  • Expected output format

Auto-Tuning Process

# Generate domain-adapted prompts
graphrag prompt-tune --root . \
  --config settings.yaml \
  --output prompts/

# This will:
# 1. Analyze your input documents
# 2. Identify domain-specific patterns
# 3. Generate custom entity extraction prompts
# 4. Generate custom summarization prompts
# 5. Save to prompts/ directory

Manual Prompt Customization

# Edit generated prompts
nano prompts/entity_extraction.txt

Example Entity Extraction Prompt:

-Target activity-
You are an AI assistant helping to identify entities in documents about {DOMAIN}.

-Goal-
Extract all entities and relationships from the text below.

Entity Types:
{ENTITY_TYPES}

Relationship Types:
{RELATIONSHIP_TYPES}

Format your response as JSON:
{{
  "entities": [
    {{"name": "Entity Name", "type": "ENTITY_TYPE", "description": "..."}}
  ],
  "relationships": [
    {{"source": "Entity 1", "target": "Entity 2", "type": "RELATIONSHIP_TYPE", "description": "..."}}
  ]
}}

Text to analyze:
{INPUT_TEXT}

Indexing Pipeline Deep Dive

Step-by-Step Process

1. Document Loading

# Input documents are loaded from input/ directory
# Supported formats: .txt, .pdf, .docx, .md

2. Text Chunking

# Documents split into TextUnits
# Default: 1200 tokens with 100 token overlap
# Preserves context across chunk boundaries

3. Entity Extraction

# For each TextUnit:
#   - Extract entities (with types and descriptions)
#   - Extract relationships (with types and weights)
#   - Extract claims (with sources and confidence)

4. Graph Construction

# Build knowledge graph:
#   - Nodes = Entities
#   - Edges = Relationships
#   - Properties = Attributes and metadata

5. Community Detection

# Leiden algorithm for hierarchical clustering:
#   - Level 0: Fine-grained communities
#   - Level 1: Mid-level aggregations
#   - Level 2+: High-level themes

6. Community Summarization

# For each community at each level:
#   - Aggregate entity and relationship info
#   - Generate natural language summary
#   - Store for query-time retrieval

7. Embedding Generation

# Create vector embeddings for:
#   - TextUnits (for similarity search)
#   - Entities (for semantic matching)
#   - Community summaries (for global search)

8. Output Storage

# Results saved to output/:
#   - create_final_entities.parquet
#   - create_final_relationships.parquet
#   - create_final_communities.parquet
#   - create_final_community_reports.parquet
#   - create_final_text_units.parquet

Query Modes in Detail

Global Search

Best For:

  • "What are the main themes?"
  • "Summarize the entire dataset"
  • "What are the key trends?"

How It Works:

  1. Query is matched against community summaries
  2. Relevant communities selected at all hierarchy levels
  3. Summaries aggregated bottom-up
  4. Final answer synthesized from multiple levels

Example:

graphrag query --root . \
  --method global \
  --query "What are the major technology trends discussed in these documents?"

# Behind the scenes:
# 1. Match query to relevant communities
# 2. Retrieve summaries from levels 0, 1, 2
# 3. Aggregate: AI/ML, Cloud, Cybersecurity communities
# 4. Synthesize comprehensive answer

Python API:

from graphrag.query import GlobalSearch

searcher = GlobalSearch(
    llm=llm,
    context_builder=context_builder,
    map_system_prompt=map_prompt,
    reduce_system_prompt=reduce_prompt
)

result = await searcher.asearch(
    query="What are the major themes?",
    conversation_history=[]
)
print(result.response)

Local Search

Best For:

  • "Tell me about [specific entity]"
  • "What is the relationship between X and Y?"
  • "Find information about [topic]"

How It Works:

  1. Identify entities mentioned in query
  2. Traverse graph from those entities
  3. Collect neighborhood information (N-hop)
  4. Retrieve associated TextUnits
  5. Synthesize answer from local context

Example:

graphrag query --root . \
  --method local \
  --query "What is Microsoft's strategy for artificial intelligence?"

# Behind the scenes:
# 1. Identify: "Microsoft", "artificial intelligence" entities
# 2. Traverse: Find related entities (Azure AI, OpenAI partnership, etc.)
# 3. Collect: Relationships, claims, TextUnits
# 4. Synthesize: Answer from local graph neighborhood

Python API:

from graphrag.query import LocalSearch

searcher = LocalSearch(
    llm=llm,
    context_builder=context_builder,
    system_prompt=system_prompt
)

result = await searcher.asearch(
    query="Tell me about Microsoft's AI strategy",
    conversation_history=[]
)
print(result.response)

DRIFT Search

Best For:

  • "How does [entity] fit into [broader context]?"
  • "What is the significance of [topic]?"
  • Hybrid queries needing both local and global context

How It Works:

  1. Identify query entities (like Local Search)
  2. Find relevant communities (like Global Search)
  3. Combine entity neighborhoods with community summaries
  4. Synthesize answer from both perspectives

Example:

graphrag query --root . \
  --method drift \
  --query "How does Azure AI relate to Microsoft's overall cloud strategy?"

# Behind the scenes:
# 1. Local: Find "Azure AI" entity and neighborhood
# 2. Global: Find "cloud strategy" community summaries
# 3. Combine: Entity details + strategic context
# 4. Synthesize: Comprehensive answer

Python API Usage

Basic Setup

import asyncio
from graphrag.query import LocalSearch, GlobalSearch
from graphrag.llm import create_openai_chat_llm
from graphrag.config import GraphRagConfig

# Load configuration
config = GraphRagConfig.from_file("settings.yaml")

# Create LLM
llm = create_openai_chat_llm(
    api_key=config.llm.api_key,
    model=config.llm.model,
    temperature=0.0
)

Custom Indexing

from graphrag.index import run_pipeline_with_config

# Run indexing programmatically
await run_pipeline_with_config(
    config_path="settings.yaml",
    verbose=True
)

Advanced Query Customization

from graphrag.query.context_builder import LocalContextBuilder

# Build custom context
context_builder = LocalContextBuilder(
    entities=entities_df,
    relationships=relationships_df,
    text_units=text_units_df,
    embeddings=embeddings
)

# Custom search with parameters
result = await searcher.asearch(
    query="Your question here",
    conversation_history=[
        {"role": "user", "content": "Previous question"},
        {"role": "assistant", "content": "Previous answer"}
    ],
    top_k=10,              # Number of results
    temperature=0.5,       # LLM creativity
    max_tokens=2000        # Response length
)

# Access detailed results
print("Response:", result.response)
print("Context used:", result.context_data)
print("Sources:", result.sources)

Use Cases and Examples

1. Research Paper Analysis

# Index academic papers
mkdir -p input/papers
cp research_papers/*.pdf input/papers/

graphrag index --root .

# Global query
graphrag query --method global \
  --query "What are the main research themes across these papers?"

# Local query
graphrag query --method local \
  --query "What methodologies does the Smith et al. paper use?"

2. Legal Document Processing

# Index legal contracts
mkdir -p input/contracts
cp contracts/*.docx input/contracts/

# Tune prompts for legal domain
graphrag prompt-tune --root . --domain "legal contracts"

# Index with legal-specific entities
graphrag index --root .

# Query
graphrag query --method local \
  --query "What are the termination clauses in the Microsoft contracts?"

3. Customer Feedback Analysis

# Index customer feedback
mkdir -p input/feedback
cp feedback_*.txt input/feedback/

# Global themes
graphrag query --method global \
  --query "What are the main customer pain points?"

# Specific product feedback
graphrag query --method local \
  --query "What feedback relates to product X features?"

4. News Article Summarization

# Index news articles
mkdir -p input/news
cp articles/*.txt input/news/

graphrag index --root .

# Get comprehensive summary
graphrag query --method global \
  --query "Summarize the key events and trends from these news articles"

# Entity-specific news
graphrag query --method local \
  --query "What news relates to climate change initiatives?"

Advanced Features

1. Incremental Indexing

# Initial indexing
graphrag index --root .

# Add new documents
cp new_documents/*.txt input/

# Re-index only new content
graphrag index --root . --incremental

# Note: Full graph may need periodic rebuilding

2. Custom Entity Types

Edit prompts/entity_extraction.txt:

Entity Types:
- PRODUCT: Software products, services
- FEATURE: Product features and capabilities
- TECHNOLOGY: Technologies and frameworks
- METRIC: Performance metrics, KPIs
- INITIATIVE: Projects and strategic initiatives
- COMPETITOR: Competing products or companies

3. Multi-Language Support

# settings.yaml
input:
  encoding: utf-8
  language: es  # Spanish

llm:
  model: gpt-4o  # Multilingual model

# Customize prompts in target language

4. Azure OpenAI Integration

llm:
  type: azure_openai_chat
  api_base: https://your-resource.openai.azure.com
  api_version: "2024-02-15-preview"
  deployment_name: gpt-4
  api_key: ${AZURE_OPENAI_API_KEY}

embeddings:
  type: azure_openai_embedding
  api_base: https://your-resource.openai.azure.com
  api_version: "2024-02-15-preview"
  deployment_name: text-embedding-3-small
  api_key: ${AZURE_OPENAI_API_KEY}

5. Local LLM Support (Ollama)

llm:
  type: ollama
  api_base: http://localhost:11434
  model: llama3:70b
  temperature: 0

embeddings:
  type: ollama
  api_base: http://localhost:11434
  model: nomic-embed-text

Cost Management

Understanding Costs

GraphRAG uses LLM APIs which incur costs:

Indexing Phase (most expensive):

  • Entity extraction: Multiple LLM calls per TextUnit
  • Relationship extraction: Additional calls
  • Community summarization: Calls per community
  • Embedding generation: Per entity/TextUnit

Query Phase (less expensive):

  • Context retrieval: Minimal LLM use
  • Answer synthesis: Single LLM call per query

Cost Optimization Strategies

1. Reduce Chunk Size

chunks:
  size: 600  # Smaller chunks = fewer tokens
  overlap: 50

2. Limit Entity Extraction Passes

entity_extraction:
  max_gleanings: 0  # 0 = single pass, 1 = two passes

3. Use Smaller Models

llm:
  model: gpt-4o-mini  # Cheaper than gpt-4o

embeddings:
  model: text-embedding-3-small  # Cheaper than large

4. Process Subset First

# Test on small sample
mkdir input/sample
cp input/full/*.txt input/sample/ | head -5
graphrag index --root . --input-dir input/sample

5. Cache Aggressively

cache:
  type: file
  base_dir: cache

Cost Estimation

# Estimate before indexing
from graphrag.index import estimate_index_cost

cost_estimate = estimate_index_cost(
    input_dir="input/",
    config_path="settings.yaml"
)

print(f"Estimated cost: ${cost_estimate.total_cost}")
print(f"Total tokens: {cost_estimate.total_tokens}")
print(f"Estimated time: {cost_estimate.estimated_hours} hours")

Best Practices

1. Start Small

# Test with 5-10 documents first
# Validate outputs before scaling
# Tune prompts on small sample
# Then scale to full dataset

2. Monitor Indexing Progress

# Use verbose mode
graphrag index --root . --verbose

# Check output files periodically
ls -lh output/*.parquet

# Monitor logs
tail -f output/reports/indexing.log

3. Version Control Configuration

# Track changes
git add settings.yaml prompts/
git commit -m "Update entity types for domain X"

# Tag successful configurations
git tag -a v1.0-config -m "Working config for dataset X"

4. Validate Outputs

import pandas as pd

# Check extracted entities
entities = pd.read_parquet("output/create_final_entities.parquet")
print(f"Total entities: {len(entities)}")
print(f"Entity types: {entities['type'].value_counts()}")

# Check relationships
relationships = pd.read_parquet("output/create_final_relationships.parquet")
print(f"Total relationships: {len(relationships)}")
print(f"Relationship types: {relationships['type'].value_counts()}")

# Check communities
communities = pd.read_parquet("output/create_final_communities.parquet")
print(f"Total communities: {len(communities)}")
print(f"Hierarchy levels: {communities['level'].value_counts()}")

5. Iterate on Prompts

# Run initial index
graphrag index --root .

# Evaluate quality
graphrag query --method global --query "Test query"

# If quality is poor:
# 1. Adjust entity types in prompts
# 2. Modify extraction instructions
# 3. Re-run indexing
# 4. Validate improvements

Troubleshooting

Common Issues

"API rate limit exceeded"
# Add delays between requests
parallelization:
  stagger: 1.0        # Increase delay
  num_threads: 2      # Reduce concurrency

llm:
  max_retries: 20     # More retries
  max_retry_wait: 60  # Longer backoff
"Out of memory during indexing"
# Reduce batch sizes
chunks:
  size: 600           # Smaller chunks

parallelization:
  num_threads: 2      # Less parallelism
"Poor quality entity extraction"
# Run prompt tuning
graphrag prompt-tune --root . --domain "your domain"

# Manually refine prompts
nano prompts/entity_extraction.txt

# Add domain-specific examples
# Specify expected entity types clearly
"Queries return irrelevant results"
# Check if indexing completed successfully
ls -lh output/*.parquet

# Validate extracted entities
python -c "import pandas as pd; print(pd.read_parquet('output/create_final_entities.parquet').head())"

# Try different query methods
graphrag query --method local --query "Your query"
graphrag query --method global --query "Your query"
"Version incompatibility after update"
# Reinitialize configuration
graphrag init --root . --force

# This updates settings.yaml to new schema
# Review and merge your customizations

Performance Optimization

Indexing Performance

# Optimize for speed
parallelization:
  num_threads: 8            # Max concurrent workers
  stagger: 0.1              # Minimal delay

chunks:
  size: 1500               # Larger chunks (fewer API calls)

entity_extraction:
  max_gleanings: 0         # Single pass only

Query Performance

# Cache query results
from functools import lru_cache

@lru_cache(maxsize=100)
def cached_query(query_text):
    return searcher.search(query_text)

# Pre-load data structures
entities_df = pd.read_parquet("output/create_final_entities.parquet")
relationships_df = pd.read_parquet("output/create_final_relationships.parquet")

# Keep in memory for fast access

Storage Optimization

# Use compressed storage
storage:
  type: file
  compression: gzip         # Or snappy, lz4

# Or use database storage
storage:
  type: cosmosdb
  connection_string: ${COSMOS_CONNECTION_STRING}

Integration Examples

LangChain Integration

from langchain.retrievers import GraphRAGRetriever
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI

# Create GraphRAG retriever
retriever = GraphRAGRetriever(
    index_path="output/",
    search_method="local"
)

# Build QA chain
llm = ChatOpenAI(model="gpt-4o")
qa_chain = RetrievalQA.from_chain_type(
    llm=llm,
    retriever=retriever,
    return_source_documents=True
)

# Query
result = qa_chain("What are the main themes?")
print(result["answer"])

FastAPI Service

from fastapi import FastAPI
from graphrag.query import LocalSearch, GlobalSearch

app = FastAPI()

# Initialize searchers
local_searcher = LocalSearch(...)
global_searcher = GlobalSearch(...)

@app.post("/query/local")
async def query_local(query: str):
    result = await local_searcher.asearch(query)
    return {"response": result.response, "sources": result.sources}

@app.post("/query/global")
async def query_global(query: str):
    result = await global_searcher.asearch(query)
    return {"response": result.response}

# Run: uvicorn main:app --reload

Streamlit UI

import streamlit as st
from graphrag.query import GlobalSearch

st.title("GraphRAG Query Interface")

# Query input
query = st.text_input("Enter your question:")
method = st.selectbox("Search method:", ["global", "local", "drift"])

if st.button("Search"):
    with st.spinner("Searching..."):
        # Run query
        result = await searcher.asearch(query)

        # Display results
        st.write("### Answer")
        st.write(result.response)

        st.write("### Sources")
        st.write(result.sources)

Comparison with Other Approaches

GraphRAG vs. Vector RAG

FeatureVector RAGGraphRAG
StructureFlat embeddingsKnowledge graph
RelationshipsImplicit (similarity)Explicit (edges)
Multi-hopPoorExcellent
SummarizationDifficultNatural (communities)
Setup CostLowHigh (indexing)
Query CostLowMedium
Best ForSimple lookupsComplex reasoning

When to Use GraphRAG

✅ Use GraphRAG when:

  • Queries require connecting multiple pieces of information
  • Need holistic understanding of document corpus
  • Relationships between entities matter
  • Multi-hop reasoning is important
  • Domain has rich entity/relationship structure

❌ Use Vector RAG when:

  • Simple semantic search is sufficient
  • Low setup cost is priority
  • Documents are independent
  • Queries are straightforward lookups
  • Budget is constrained

Resources

Documentation

Community

Examples

Important Notes

⚠️ Not an Official Microsoft Product

"This codebase is a demonstration of graph-based RAG and not an officially supported Microsoft offering."

💰 Cost Considerations

  • Indexing can be expensive (especially with GPT-4)
  • Test on small samples first
  • Monitor API costs closely

🔄 Version Management

  • Configuration schemas change between versions
  • Run graphrag init --force after updates
  • Review migration guides for breaking changes

🎯 Prompt Tuning is Critical

  • Out-of-box results may be suboptimal
  • Domain-specific tuning significantly improves quality
  • Invest time in prompt customization

License

Microsoft GraphRAG is released under the MIT License.


Note: This skill provides comprehensive guidance for using Microsoft GraphRAG. Always test on small datasets first, monitor costs, and tune prompts for your specific domain.

适合场景

01

研究助手

02

事实核查

03

知识库问答

04

带来源的搜索总结

能力概览

能力 1

组合搜索和大模型调用

能力 2

支持多来源检索和总结

能力 3

强调引用来源和事实核查

能力 4

适合研究型 Agent 流程

平台分布

Codex

31.22%
按下载量换算30

Claude

32.03%
按下载量换算30

Cursor

19.85%
按下载量换算19

Gemini CLI

9.24%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills