agentleFS
Goodnight77Goodnight77/rag-skills/skills/retrieval-strategies/graph-rag/SKILL.md

graph-rag

Skill8 starsChanged 7 months agoMITView on GitHub

Use knowledge graphs to connect related information across documents for enhanced retrieval.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use an LLM to identify entities and their relationships from document chunks.

    line 36
  2. Distinctive:

    Create nodes for entities and edges for relationships, building a graph structure that can be queried and traversed.

    line 47
  3. Distinctive:

    Use community detection algorithms (e.g., Leiden, Louvain) to find clusters of highly connected entities.

    line 54
  4. Distinctive:

    When queries require connecting information from disparate sources

    line 86
  5. Distinctive:

    When traditional chunk-based retrieval misses important connections

    line 89
  6. Distinctive:

    When indexing cost and time are major constraints

    line 93
  7. Distinctive:

    When implementation complexity must be minimized

    line 96

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Graph RAG enhances traditional retrieval by constructing knowledge graphs from documents, identifying communities of related entities, and using these structures to improve retrieval. This approach excels at connecting disparate information and providing holistic understanding across large document collections.

Problem Statement

Traditional chunk-based retrieval has limitations:

  • Fragmented Information: Related concepts split across different chunks
  • No Context Connections: Retrieval can't connect information from separate sources
  • Limited Global Understanding: Difficulty synthesizing information across entire corpus
  • Missing Relationships: Entity relationships not captured in flat retrieval
  • Poor Sensemaking: Struggles with tasks requiring global understanding

Key Concepts

  • Entity Extraction: Identifying key entities (people, places, concepts) from text
  • Relationship Extraction: Finding connections between extracted entities
  • Graph Construction: Building knowledge graphs with entities as nodes and relationships as edges
  • Community Detection: Clustering related entities to find thematic groups
  • Community Summarization: Creating summaries for each community for efficient retrieval
  • Local and Global Retrieval: Supporting both specific and comprehensive queries

Implementation Guide

Step 1: Extract Entities and Relationships

Use an LLM to identify entities and their relationships from document chunks.

Why: Entity extraction transforms unstructured text into structured knowledge, enabling graph-based retrieval that understands connections between concepts.

Direct the LLM to extract entities (people, places, concepts, etc.) and the relationships between them.

Step 2: Construct Knowledge Graph

Build a graph from extracted entities and relationships.

Why: A knowledge graph provides a structured representation of how entities connect across the document collection, enabling retrieval that traverses these connections.

Create nodes for entities and edges for relationships, building a graph structure that can be queried and traversed.

Step 3: Detect Communities

Apply community detection algorithms to identify clusters of related entities.

Why: Communities represent thematic groupings in the graph - entities that are closely connected form natural clusters that can be summarized together.

Use community detection algorithms (e.g., Leiden, Louvain) to find clusters of highly connected entities.

Step 4: Summarize Communities

Generate summaries for each community to provide context for retrieval.

Why: Community summaries condense related information into manageable pieces, enabling efficient retrieval while preserving thematic connections.

For each community, summarize the relevant documents and entity information into concise overviews.

Step 5: Implement Local Retrieval

Query using community summaries for specific, focused answers.

Why: Local retrieval provides precise, contextually relevant answers by matching queries to the most appropriate community summaries.

Match queries to community summaries and retrieve documents from the most relevant communities.

Step 6: Implement Global Retrieval

Synthesize information across all communities for comprehensive answers.

Why: Global retrieval is needed for queries that require understanding across multiple communities or the entire corpus.

Generate preliminary answers from each community and synthesize into a comprehensive response.

Step 7: Build Complete Graph RAG Pipeline

Combine all components into a cohesive system.

Why: A complete pipeline with both local and global retrieval modes ensures optimal performance for both specific and comprehensive queries.

For implementation patterns, see Microsoft GraphRAG, the GraphRAG documentation, and networkx community detection for implementation details.

When to Use This Skill

  • Building RAG systems for large document collections with interconnected concepts
  • When queries require connecting information from disparate sources
  • For applications requiring global understanding and sensemaking
  • For domains with clear entity relationships (biographies, technical domains)
  • When traditional chunk-based retrieval misses important connections

When NOT to Use This Skill

  • For small document collections where chunk retrieval is sufficient
  • When indexing cost and time are major constraints
  • For documents with weak entity relationships (unstructured narratives)
  • For simple fact-finding queries that don't require synthesis
  • When implementation complexity must be minimized

Related Skills

  • RAPTOR - Alternative hierarchical approach
  • Explainable Retrieval - Citation and traceability
  • Adaptive Retrieval - Dynamic query processing

Metrics & Success Criteria

  • Global Understanding: Improved performance on sensemaking tasks
  • Connection Discovery: Ability to connect related information across sources
  • Query Coverage: Better results for both specific and comprehensive queries
  • Graph Quality: Meaningful entity and relationship extraction
  • Summary Effectiveness: Community summaries capture essential information

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.