Skip to main content

Domain-agnostic Graph RAG framework for building governed, auditable Knowledge Graphs

Project description

graphrag-core

A domain-agnostic framework for building governed, auditable Knowledge Graphs from documents using LLM-powered extraction, provenance-native storage, and multi-agent orchestration.

Architecture

YOUR DOMAIN LAYER (Layer 2)
  Ontology, domain tools, domain agents, templates
                    |
                    | imports
                    v
graphrag-core (Layer 1)

  Ingestion   Extraction   Graph Store   Search
  Curation    Registry     Tool Library  Orchestration

Install

pip install graphrag-core                    # core (in-memory backends)
pip install graphrag-core[neo4j]             # + Neo4j graph store and search
pip install graphrag-core[anthropic]         # + Claude LLM client
pip install graphrag-core[all]               # everything

Quick Start

import asyncio
from graphrag_core import (
    TextParser, TokenChunker, IngestionPipeline,
    InMemoryGraphStore, InMemorySearchEngine,
    LLMExtractionEngine, OntologySchema, NodeTypeDefinition,
    PropertyDefinition, RelationshipTypeDefinition,
    ToolLibrary, register_core_tools,
)
from graphrag_core.models import ChunkConfig, DocumentChunk, GraphNode, ImportRun
from datetime import datetime

async def main():
    # 1. Ingest a document
    pipeline = IngestionPipeline(parser=TextParser(), chunker=TokenChunker())
    chunks = await pipeline.ingest(b"Alice works at Acme Corp.", "text/plain")

    # 2. Define your domain schema
    schema = OntologySchema(
        node_types=[
            NodeTypeDefinition(
                label="Person",
                properties=[PropertyDefinition(name="name", type="string", required=True)],
                required_properties=["name"],
            ),
            NodeTypeDefinition(
                label="Company",
                properties=[PropertyDefinition(name="name", type="string", required=True)],
                required_properties=["name"],
            ),
        ],
        relationship_types=[
            RelationshipTypeDefinition(type="WORKS_AT", source_types=["Person"], target_types=["Company"]),
        ],
    )

    # 3. Extract entities (requires an LLMClient implementation)
    # engine = LLMExtractionEngine(llm_client=your_client)
    # result = await engine.extract(chunks, schema, import_run)

    # 4. Store in graph
    store = InMemoryGraphStore()
    await store.merge_node(GraphNode(id="p1", label="Person", properties={"name": "Alice"}), "run-1")
    await store.merge_node(GraphNode(id="c1", label="Company", properties={"name": "Acme Corp"}), "run-1")

    # 5. Search
    search = InMemorySearchEngine(
        nodes=[await store.get_node("p1"), await store.get_node("c1")],
    )
    results = await search.fulltext_search("Acme", top_k=5)
    print(results)

    # 6. Wire up tools for agents
    library = ToolLibrary()
    register_core_tools(library, store, search)
    result = await library.execute("get_entity", entity_id="p1")
    print(result)

asyncio.run(main())

Building Blocks

# Block Interface Implementation Status
1 Document Ingestion DocumentParser, Chunker PDF, DOCX, Text, Markdown parsers; TokenChunker Done
2 Entity Extraction ExtractionEngine, LLMClient LLMExtractionEngine, AnthropicLLMClient Done
3 Knowledge Graph GraphStore InMemoryGraphStore, Neo4jGraphStore Done
4 Hybrid Search SearchEngine InMemorySearchEngine, Neo4jHybridSearch (RRF) Done
5 Governed Curation DetectionLayer DeterministicDetectionLayer, CurationPipeline Done (detection layer)
6 Entity Registry EntityRegistry InMemoryEntityRegistry (fuzzy matching) Done
7 Tool Library ToolLibrary 4 core tools (get_entity, search, audit_trail, related) Done
8 Orchestration Agent, Orchestrator SequentialOrchestrator, AgentContext Done

Protocols marked with (Protocol only) have no default implementation yet:

  • LLMCurationLayer, ApprovalGateway (BB5 layers 2-3)
  • ReportRenderer (BB8)
  • EmbeddingModel (cross-cutting)

Extension Pattern

from graphrag_core import OntologySchema, ToolLibrary, Tool

# 1. Define your domain ontology
schema = OntologySchema(node_types=[...], relationship_types=[...])

# 2. Register domain-specific tools
library = ToolLibrary()
library.register(Tool(name="my_tool", description="...", parameters={}, handler=my_handler))

# 3. Implement domain agents
class MyAgent:
    name = "analyst"
    async def execute(self, context):
        result = await context.tool_library.execute("my_tool")
        context.workflow_state["analysis"] = result.data
        return AgentResult(agent_name=self.name, success=True)

Development

# Clone and install
git clone https://github.com/cdel1/graphrag-core.git
cd graphrag-core
uv sync --all-extras

# Run unit tests
uv run pytest tests/ -x -q

# Run integration tests (requires Neo4j)
docker run -d --name neo4j-test -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/development neo4j:5-community
uv run pytest tests/ -x --run-integration

# Build
uv build

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphrag_core-0.3.0.tar.gz (124.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphrag_core-0.3.0-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file graphrag_core-0.3.0.tar.gz.

File metadata

  • Download URL: graphrag_core-0.3.0.tar.gz
  • Upload date:
  • Size: 124.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for graphrag_core-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3f69017103f26a34ccc41e9a851da57e9f3686963a6d23e0f55b77d033c55b25
MD5 8a5af11c09bc3d59b433d859108855e8
BLAKE2b-256 d68c7c5ffd6666f3684a4d9867308f56204de1f740dc4943727a9f9d7936fa01

See more details on using hashes here.

File details

Details for the file graphrag_core-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: graphrag_core-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for graphrag_core-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb43f78e29e6a75787fcc9209186a008143d95b3046a04953bb4f49e97fbd6d2
MD5 a49e6ed86fa52a29804ed181ce1e4d3d
BLAKE2b-256 5f13cd867bbabc01af7766ed3735a1639aca3974541c6405191d7b153026dc06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page