概要
Context graphs that connect enterprise knowledge, conversation history, and decision traces
AI・機械学習計測したスター増加
- 24時間
- 0
- 7日間
- 履歴を収集中
- 15日間
- 履歴を収集中
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルAgentic GraphRAG
Context graphs that connect enterprise knowledge, conversation history, and decision traces.
Documentation | Quickstart | Concepts | Guides | API reference
Agentic GraphRAG is an open source framework that builds one graph connecting your enterprise knowledge to the conversations your agents have and the decisions they make. Each decision links back to the passages and task events behind it, so agents can look up earlier decisions with their evidence, resume work across sessions, and review a decision when its sources change.
- Citations and provenance: Every passage keeps its source document and location, and every relation links to the passages that support it. Agents cite the passages they fetched, and a citation check flags any source they did not read. The retrieval tools enforce a document scope, so an agent cannot read outside it.
- Decision traces: Agents record each decision with its rationale and links to the passages, conversation events, and earlier decisions behind it. When a source document changes, the decision is flagged for review and left out of precedent search until someone reaffirms, replaces, or rejects it.
- Agent memory: Conversation history, tool calls, and task steps persist in the graph. An agent can resume a task in a later session or another process, rerun only the unfinished steps, and search earlier decisions in the same project.
- Ontology-driven extraction: Bring your ontology as OWL or RDFS Turtle, Pydantic models, YAML, or JSON, and export it as JSON Schema, JSON-LD, or SHACL. Extraction returns only the custom entity and relation types you declare, and new types the models propose wait as candidates for your approval.
- Structure-aware chunking: Docling parses Markdown, HTML, and Office files, and PDFs and images with the
doclingextra. Sections, tables, and figures become graph nodes, so an agent can move from a matching chunk to its section, its neighbors, or a whole table with its header row. - Incremental updates and versioning: Add, update, or delete one document without rebuilding the graph. Unchanged documents are skipped. A changed document gets a new version, and an old evidence id still returns the cited text, marked superseded.
- Hybrid retrieval: Passage search fuses keyword and vector results with reciprocal rank fusion, with optional cross-encoder reranking. Entity search follows relations up to two hops, and GraphRAG-style global search matches broad questions against Leiden community reports.
- Entity resolution and deduplication: Exact, fuzzy, embedding, and clustering checks decide most duplicate pairs, and an LLM reviews only the unclear ones. Matches are stored as links, so you can preview, undo, or re-check them.
- Local-first, pluggable LLMs and databases: Through the MCP server, Claude Code, Codex, or another MCP client does the model work. You can also use Anthropic, OpenAI, Google, or any OpenAI-compatible LLM, or extract on your machine with GLiNER and local embeddings. The graph lives in Relate, an embedded database in your project folder with no server to run, or in Neo4j or FalkorDB, and vectors can go to Qdrant, Milvus, or Weaviate.
- Observability and evaluation: OpenTelemetry traces cover ingestion, retrieval, and agent runs, and the evaluation tools score answers, citations, and runs on your own questions.
Quickstart
I use a coding agentGive Claude Code or Codex a graph of your project's documents. Your agent adds files, searches them, and cites the passages it read. You need no database server and no separate API key. |
I build with PythonBuild the graph from your own code, then ask the built-in agent a question and get an answer with numbered sources. You need Python 3.11 or newer and an OpenAI-compatible LLM endpoint. |
Set up Codex or Claude Code
Install uv, then run:
uvx agentic-graphrag setup claude
For Codex, run uvx agentic-graphrag setup codex. The command installs the server as a uv tool and registers it with the client's command-line tool, which must be on your PATH.
Open your project in the client and ask:
Add README.md to the graph, then tell me how to install this project and cite your sources.
To use the plugin instead, run /plugin marketplace add ontogr/agentic-graphrag in Claude Code and install agentic-graphrag. Codex reads the same marketplace from .agents/plugins/marketplace.json. Install the plugin only in a client that you did not set up with the command.
How it works
- Your agent adds a file. The server stores it as a graph in your project's
.agragfolder, which holds an embedded Relate database. - Your agent reads each new chunk and returns its entities and relations. The server checks each result against your schema before it saves it.
- Your agent searches the graph, reads the passages behind the results, and cites them.
check_citationsconfirms that the agent fetched each passage it cites.
Use it from Python
Install the package with local extraction and the built-in agent:
uv pip install "agentic-graphrag[extract,agents]" --torch-backend=auto
Add your OpenAI-compatible endpoint to a .env file. The address ends at /v1.
AGENT_LLM_BASE_URL=https://your-endpoint.example.com/v1
AGENT_LLM_API_KEY=your-api-key
AGENT_LLM_MODEL_NAME=your-model-name
Put a Markdown or text file named your-document.md in the same folder. Save the script below as example.py and run python example.py. The first run downloads the embedding and extraction models.
import asyncio
from pathlib import Path
from agrag.agents import AgentLLMSettings, build_agent
from agrag.embedding import build_embedder
from agrag.graphdb import build_graph_store
from agrag.ingestion import ExtractionSettings, Graph
# Any Markdown or text file you have.
DOCUMENT = Path("your-document.md").resolve()
async def main() -> None:
# Open the embedded graph and load the model that turns text into vectors.
store = build_graph_store("relate")
embedder = build_embedder("ibm-granite/granite-embedding-small-english-r2")
try:
# Read the document into the graph. This step runs on your machine.
# "operations" is a preset schema, and max_llm_pairs=0 sends no
# duplicate-matching pairs to an LLM.
graph = await Graph.open(
schema="operations",
graph_store=store,
embedder=embedder,
extraction_settings=ExtractionSettings(mode="gliner"),
max_llm_pairs=0,
)
await graph.add(DOCUMENT)
# Create an agent that may read only this document.
agent = build_agent(
graph_store=store,
embedder=embedder,
scope=frozenset({str(DOCUMENT)}),
project_id="my-project",
agent_id="researcher",
llm_settings=AgentLLMSettings.from_openai_compatible_env(),
)
# Ask a question about the document.
result = await agent.ainvoke({
"task_name": "first-question",
"question": "What are the main points of this document? Cite your sources.",
})
print(result["answer"])
finally:
await store.close()
asyncio.run(main())
The script prints the answer with a numbered Sources list. The graph stays in a .agrag folder, so there is no database server to start.
To store the graph in Neo4j or FalkorDB, install the neo4j or falkordb extra and call build_graph_store("neo4j") or build_graph_store("falkordb"). Configure storage backends lists the connection settings, and the full quickstart inspects the graph after the add. If you used 0.0.9, follow the upgrade guide first.
Features
Ingestion | Schema | Extraction | Resolution | Communities | Retrieval | History and decisions | Agents and MCP | Tracing
Structure-aware ingestion
Docling reads the layout, and the hierarchy becomes graph structure.
Docling reads each file and reports its parts with their type and level. Agentic GraphRAG stores that hierarchy in the graph, so an agent can use a match at any level.
- Docling loading: It reads Markdown, HTML, AsciiDoc, Word, PowerPoint, and Excel files, and PDFs and images with an optional install. Plain text, XML, CSV, TSV, JSON, and JSON Lines have their own loaders, and a CSV row or a JSON record becomes a document of its own. Running page headers and footers are left out.
- Hierarchy levels: A title is level 0, and headings run from level 1 downward, so a level 2 heading sits under a level 1 heading. Paragraphs, lists, code, formulas, tables, and figures sit under the heading that introduces them. Where a source does not report heading depth, as a PDF often does not, the depth comes from its outline or from numbered headings.
- Structure-aware chunks: Paragraphs and lists are packed within a section up to a size limit, and a chunk that stays small continues into the next section instead of standing alone. A heading stays in the chunk with the text that follows it, and a heading is searchable even when its text is not in the chunk. A table never mixes with text, and a long table is split into groups of rows that each repeat the header row. Chonkie cuts only a paragraph that is too long for one chunk.
- Graph structure: A Document holds Sections nested by depth. A Section holds Chunks, Tables, and Figures in reading order, and a Table holds its row-group Chunks. These nodes are joined by
HAS_CHILD, andNEXT_CHUNKlinks neighboring chunks. - Access at every level: A chunk keeps its heading path and its page or character position. From a matching chunk, an agent can read the section around it, the sibling sections, the chunks next to it, or a table with its header row.
Schema and ontology
Extraction, storage, retrieval, and agents all use the types and relations that your schema declares.
Enterprise knowledge already has a defined structure. Platforms such as Palantir Foundry and Microsoft Fabric IQ describe a business as object or entity types, their properties, and the links between them, and industry standards such as FIBO do the same for finance. Agentic GraphRAG takes that ontology as its starting point, and the whole pipeline is grounded in it.
- Extraction: The extractor sees each entity type and relation with its description, and it can return only what the schema declares. A relation survives only when its source and target types form an allowed pair.
- Graph creation: Each entity type becomes a node label, and a type with parents also carries the labels of its parents. Relations become typed relationships between the allowed pairs, and each label gets its own indexes.
- Retrieval: Entity search and relationship exploration read the schema stored in the graph. They search and follow only the labels and relation types it declares. Each entity shows its own type, or the nearest declared parent.
- Agents: The built-in agent and any MCP client use the same labels and relation types, and every entity they get back carries its schema label and properties.
- Change: The models can propose entity and relation types that your schema does not declare. A proposal that appears in its source passage is saved as a candidate with a link to that passage. Approving one returns a schema patch to apply.
Ontologies
An ontology is mapped to a schema. Classes become entity types, subclasses become parent types, properties become entity properties, and links become relations between allowed pairs of types.
Accepted formats:
- A Python list or dict
- A YAML or JSON file
- Pydantic classes
- An OWL or RDFS Turtle file
- A shipped schema:
default,operations, orlegal
Schemas export to JSON Schema, JSON-LD (an OWL vocabulary), and SHACL shapes. For more detail on the supported ontologies, see ontology formats and examples.
Default schema and domain-specific presets
Each entity type and relation, with the pairs it joins, is defined in the default schema reference. The domain-specific presets are operations and legal.
Entity and relationship extraction
An LLM extracts what your schema declares, and a local model can do the work on your machine.
Extraction reads each chunk and returns typed entities and the relationships between them, all declared in your schema.
- GLiNER: GLiNER is a compact encoder model trained to extract any entity types you define. Your schema's types and descriptions are its input. It runs on your machine, reads every chunk, and returns entities and relations with confidence scores, with no API calls and no LLM key. You choose the mode:
llm(the default, LLM only),hybrid(the local model first, then the LLM), orgliner(local model only). Through MCP, the connected agent does the LLM work. - Schema-constrained LLM: In
llmmode, the LLM reads every chunk. In hybrid mode, it reads the chunks the local model is least sure about, chunks with no local entity and at least eight words, and chunks with an entity whose type declares or inherits properties, up to the budget you set. BAML builds its allowed entity and relation labels from your schema at call time, so it can only return declared types. It keeps, corrects, or adds to the local entities. It does not remove a local entity that it leaves out. Validation then removes anything undeclared, including relations whose pair of types is not allowed. - Candidate review: Anything outside the schema, or below a confidence threshold, is saved as a candidate with a link to its source chunk, and it stays out of search. You approve or reject each one. Approval returns a schema patch. You apply it, raise the schema version, and convert approved candidates into entities, relations, or properties. A rejected candidate is not created again.
Entity resolution
Cheap checks decide most pairs, and an LLM reviews only the unclear ones. A match links two entities and keeps both.
Resolution decides which extracted entities name the same real-world thing.
- Deduplicate: Entities with the same label and the same text collapse into one entity as they are ingested.
- Link: Any other match becomes a link between two entities. The entities stay separate, so every match can be previewed, undone, or re-checked.
- Group: Linked entities are grouped under one resolved entity.
- Undecided: A pair that no step can decide stays undecided. It is never treated as a rejection.
- Cheapest first: Each pair goes down the steps below, and the first step that is sure decides. Only unclear pairs reach the LLM.
- Whole graph: The same steps run over the whole graph on demand, for example after you add an LLM, with a preview before you apply the matches.
The steps, in order:
- Same label: Only entities with the same label are compared.
- Exact: Identical names collapse into one entity, with no judgment needed.
- Name gate: A pair whose names carry different numbers, or a name that is very long, is blocked from matching.
- Fuzzy: Names that differ only in spelling or word order match.
- Embedding: Names with close embeddings match, clearly different names are dropped, and the rest are ambiguous.
- Cluster: Ambiguous pairs are grouped, and a tight group matches without an LLM call.
- LLM: Only the pairs that are still unclear. It answers match, no match, or uncertain, and only a match counts.
Communities
Leiden clusters and reports that make thematic questions searchable.
- Clustering: Hierarchical Leiden (Traag et al.), from the native implementation in graspologic, groups entities that are densely connected by relations. Each relation is weighted by the passages that state it, and a relation with no supporting passage weighs zero. The graph keeps one level of groups, each with at least two entities.
- Reports: A well-supported group gets an LLM-written report with a title, summary, and findings. Other groups, and every group when no LLM is set up, get a template report with no LLM call. Through MCP, the client's model can write reports for groups that are still templates.
- Thematic search: Each report is embedded, so a broad question, such as the main themes of a corpus, is matched against the reports by meaning. Theme search returns the matching themes with their entities and the passages that mention them, inside your document scope. It never returns the report text.
- Schema fit: Communities group the entities your schema defines through their relations, and extraction writes only the relations your schema declares. Document structure, links from entities to passages, history, and candidates are not part of the clustering.
Communityis a graph-owned label, so a schema cannot declare an entity type with that name. - Freshness: Detection runs when you ask, with a dry run by default, and applying it replaces the previous communities. Membership is as current as the last run, and deleted or superseded passages drop out at once.
Retrieval
Search the documents you allow, fetch the stored text, and check every citation.
- Passage search: Lexical, semantic, or hybrid search, with an optional reranker on the top hybrid results. Each result is a short preview with an evidence id. Search reads the passages directly, so a passage is still found when extraction missed the fact it contains.
- Entity search: Finds entities by name and by meaning within your schema's labels, with the passages that mention each one. An agent can follow relations a few steps out, and each relation is marked as backed by a passage or as a bare connection.
- Theme search: A broad question, such as the main themes of a corpus, is matched against the community reports, and the passages behind each matching theme come back.
- Exact text: Fetch returns the stored passage with its status and document version. An evidence id keeps pointing at the same text, and after an edit the old id returns the old text marked superseded. Only text read this way can be cited.
- Document navigation: From any passage, an agent can reach its section, the sibling sections, the passages around it, and the rows of a table with their header.
- Scope: You choose the documents, and the limit is enforced outside the model. An id from outside the scope comes back as unavailable. A scope entry is an exact document key, a folder prefix that ends in
/, or*for all documents. History and decision reads hide any task that read a document outside the scope. - Citation check: Flags every cited id that was never fetched, is out of scope, or is malformed.
- Incomplete results: A cut-off result or a failed part of a search is reported as such. An empty list means that the search ran and found nothing. A scope entry that matches no document is listed in
unmatched_scope, so an empty list can also mean a wrong key.
Search, fetch, navigation, and the citation check are the evidence tools that the built-in agent and the MCP server share.
History and decision traces
Record agent work, and review decisions when their sources change.
- The agent records its work: The built-in agent saves each message, tool call, and tool result as a task event, and it tracks progress as steps.
- Decisions have explicit supports: A decision records a conclusion, a concise rationale, assumptions, and open questions. Its supports point to passages, task events, or earlier decisions.
- Source changes flag decisions: When a document behind a decision is updated or removed, the decision is flagged for review, and so are the decisions that depend on it.
- Reviews end in a clear action: A reviewer can reaffirm a decision after reading the current text, replace it with a new one that explains the change, or reject it. The earlier version stays in the history.
- Tasks resume from recorded state: When a task resumes, the agent sees its goal, events, steps, and decisions, including any that need review. It reuses finished work that is still valid and runs an interrupted step again.
- Past decisions inform new ones: Agents can search earlier decisions in the same project. The built-in agent's search leaves out decisions that need review, and the agent cannot cite one as support.
The same records are available from Python without the built-in agent. The decision traces guide records and reviews decisions end to end.
Agents and MCP
Use the built-in agent, or connect your own through MCP.
- Answers cite numbered sources: The built-in agent searches your documents, reads passages, and answers with numbered sources.
- Checked citations: The passage must have been read during that run, it must belong to the documents the agent may use, and it must match the version cited. If a citation fails the check, the agent gets one chance to fix it.
- Run status: The status tells you whether the agent answered, found too little evidence, or reached a limit. You set how many steps and tool calls a run may use.
- Choose your model: Use Anthropic, OpenAI, Google, or any OpenAI-compatible model, alone, in a fallback chain, or in rotation.
- Connect your own agent: One command registers the MCP server with Claude Code or Codex, and a plugin is available for both. The server gives the agent the evidence tools, conversation history, and decisions. Set a document scope or enable read-only mode when a client needs narrower access.
- One graph per project: Every agent session in a project shares one graph. The first session starts a background owner process, and later sessions attach to it, so two agent windows can search and write at the same time.
- Your agent does the LLM work: The connected agent reads the work that the graph left pending, such as extraction, match checks, merged descriptions, and community reports, and returns its own results. The server checks the results before it saves them, and an extraction result must use declared types and text copied from its chunk.
- Evaluate your runs: The evaluation tools score answers, citations, and agent runs on your own questions.
Tracing
OpenTelemetry traces for ingestion, retrieval, and agent runs.
- OpenTelemetry: Traces use the OpenTelemetry standard, so any tool that reads it can show an Agentic GraphRAG trace.
- Opt in: You pass a tracer to the graph, the agent, the stores, the embedders, and the extractors. Without a tracer, nothing is recorded, and no global provider is installed.
- Pipeline spans: A span covers each step of loading, chunking, extraction, resolution, merging, storage, search, and LLM calls, including each attempt and its token counts.
- Agent runs: Tool calls and model calls appear as spans under your active span.
- Failures: Each failure record carries the trace and span it came from, so you can go from a failure to its trace.
- Data control: Spans can hold full text, such as questions, evidence, and model requests. Choose a destination and retention policy that fit your data controls.
MCP
agrag-mcp gives any MCP client your graph as tools. Claude Code and Codex register it with one command.
What your agent gets
| Tools | What they do |
|---|---|
search_evidence, fetch_evidence, navigate_document_tree |
Find passages, return their stored text, and move to the text around them. |
entity_search, explore_relationships, search_themes |
Find entities, follow their relations, and match broad questions to community themes. |
check_citations |
Compares the cited passages with the passages the agent fetched. |
add_file, add_document, update_document, get_job |
Add or change documents. Each write runs as a job that get_job follows. |
list_pending_work, submit_work_results |
Hand extraction and other model work to your agent, then check and save its results. |
create_task, record_event, record_decision, search_decisions |
Record conversation history and decisions, and search earlier decisions. |
guide |
Returns a workflow guide for a topic, such as ingestion jobs or destructive changes. |
The tools reference lists all of them, including the destructive tools that ask you to confirm.
Other MCP clients
Install the package and add the server to your client's configuration:
uv pip install agentic-graphrag
{
"mcpServers": {
"agrag": {
"command": "agrag-mcp",
"env": {
"RELATE_GRAPH_DIR": "/full/path/to/your/project/.agrag"
}
}
}
}
Set RELATE_GRAPH_DIR when the client starts the server outside your project folder. If the client cannot find agrag-mcp, use its full path inside the virtual environment. Set EMBEDDING_MODEL_NAME when ingestion used a model other than the default, because the server must read the graph with the same model.
Access
The server reads all documents and allows writes by default. Set MCP_SCOPE_DOCUMENT_KEYS to exact document keys or folder prefixes ending in /, and set MCP_READ_ONLY=true to refuse writes. Destructive tools ask for confirmation.
A Python script cannot open a project's .agrag folder while the MCP owner process holds it, because Relate allows one writer per graph.
To extract on your machine instead of through your agent, install agentic-graphrag[extract] and set EXTRACTION_MODE=gliner. To use Neo4j or FalkorDB, set MCP_GRAPH_STORE and the connection settings in Configure storage backends. The MCP server guide lists every setting.
Contributing
We welcome bug fixes, new features, documentation improvements, and other contributions. Please read our Contributing guide before submitting a pull request.
Acknowledgements
Agentic GraphRAG builds on the work behind these projects and papers.
- Graphiti for layered graph search and entity-aware retrieval
- Cognee for data pipelines, graph memory, and consolidation
- FalkorDB GraphRAG SDK for graph-native retrieval and entity resolution
- Neo4j GraphRAG for Neo4j retrieval and vector integration
- GLiNER for generalist zero-shot information extraction
- BAML, Docling, and Chonkie for typed LLM calls, document parsing, and chunk splitting
License
Agentic GraphRAG is licensed under the Apache License 2.0.
関連プロジェクトを探す
読み込み中…