Skip to main content

Document knowledge graphs — extract structured data from documents (Confluence, PDFs, CSV, JSON, Excel) into Neptune

Project description

Document Graph

Document knowledge graphs — extract structured data from documents (Confluence, PDFs, CSV, JSON, Excel) into Neptune.

This package depends on AWS GraphRAG Toolkit (graphrag-toolkit-lexical-graph) for graph storage, vector indexing, and retrieval.

Quick Start

Install

pip install document-graph                    # core
pip install document-graph[graphrag]          # with lexical-graph integration

Python API Example

from graphrag_toolkit.document_graph import PipelineExecutor, Node, Edge
from graphrag_toolkit.document_graph.graph_build.cypher_builder import CypherBuilder

# Create typed nodes from structured data
node = Node(
    id="doc-001",
    labels=["Document"],
    properties={"title": "Q4 Report", "source": "confluence", "tenant_id": "acme"}
)

# Build Cypher for Neptune ingestion
cypher, params = CypherBuilder.node_to_cypher(node, tenant_id="acme")

# Execute against Neptune via graphrag-toolkit GraphStore
graph_store.execute_query(cypher, params)

Schema-Driven Pipeline

from graphrag_toolkit.document_graph.schema.providers.csv_schema_provider import CSVSchemaProvider
from graphrag_toolkit.document_graph.schema.providers.schema_provider_config import SchemaProviderConfig

# Auto-discover schema from CSV
config = SchemaProviderConfig(type="csv", connection_config={"path": "data/employees.csv"})
provider = CSVSchemaProvider(config)
schema = provider.load_schema()

# Transform and load
from graphrag_toolkit.document_graph.transform.graph_transformers.row_to_node import RowToNodeTransformer
from graphrag_toolkit.document_graph.transform.transformer_provider_config import TransformerProviderConfig

transformer = RowToNodeTransformer(TransformerProviderConfig(name="r2n", args={"type": "Employee"}))
nodes = transformer.transform(records)

Hybrid Search (Document Graph + Lexical Graph)

from graphrag_toolkit.lexical_graph import LexicalGraphIndex, LexicalGraphQueryEngine
from graphrag_toolkit.lexical_graph.storage import GraphStoreFactory, VectorStoreFactory
from llama_index.core.schema import Document

# Write document-graph nodes, then index into lexical-graph for semantic search
graph_store = GraphStoreFactory.for_graph_store("neptune-db://endpoint:8182").__enter__()
vector_store = VectorStoreFactory.for_vector_store("aoss://endpoint")

graph_index = LexicalGraphIndex(graph_store, vector_store)
graph_index.extract_and_build(docs, show_progress=True)

# Semantic query across both structured and unstructured data
query_engine = LexicalGraphQueryEngine.for_traversal_based_search(graph_store, vector_store)
results = query_engine.retrieve("Who are the senior engineers?")

Package Structure

src/graphrag_toolkit/document_graph/
├── __init__.py             # Public API: PipelineExecutor, Node, Edge, models
├── config.py               # Configuration
├── errors.py               # Custom exceptions
├── model.py                # NodeModel, EdgeModel
├── model_elements.py       # Node, Edge primitives
├── pipeline_executor.py    # Orchestrates ingest → transform → build
├── schema/                 # ETL schema model, providers, discovery
│   ├── providers/          # CSV, JSON, S3, Static, File, Glue
│   └── discovery/          # Auto-infer schema from data files
├── ingest/                 # Data ingestion (column, field, row processors)
├── transform/              # 20+ transformers
│   ├── normalizers/        # Whitespace, nulls, case, enum, timestamp
│   ├── field_transformers/ # JSON flattener, UUID gen, regex clean
│   ├── document_transformers/  # JSON to rows, text chunker, PII redactor
│   ├── filter_transformers/    # Row filter, column pruner
│   ├── graph_transformers/     # Row to node, infer edges
│   └── truncators/         # Length, field count, token limits
├── graph_build/            # Cypher generation with tenant-scoped labels
│   └── constructors/       # Node/edge Cypher builders
├── query/                  # DocumentGraphQueryEngine
├── pipeline/               # Extract (CSV, Excel, JSON, Parquet) and load
└── plugins/                # Plugin system for extensibility

Integration

With AWS GraphRAG Toolkit

Document Graph extends the AWS GraphRAG Toolkit architecture:

┌─────────────────────────────────────────────────────┐
│          document-graph (this package)               │
│  Structured ETL: CSV, Excel, JSON, PDF → typed nodes│
├─────────────────────────────────────────────────────┤
│     graphrag-toolkit-lexical-graph (foundation)     │
│  GraphStore, VectorStore, Neptune/AOSS writers      │
│  LexicalGraphIndex, entity resolution, retrieval    │
└─────────────────────────────────────────────────────┘

With Neptune & OpenSearch Serverless

Deploy infrastructure via the graphrag-toolkit CloudFormation templates which provisions:

  • Amazon Neptune (graph database)
  • Amazon OpenSearch Serverless (vector search)
  • SageMaker notebook instance

Multi-Tenancy

All operations use tenant-scoped labels for complete data isolation:

# Tenant A's data is completely isolated from Tenant B
node_to_cypher(node, tenant_id="acme_corp")   # → MERGE (n:`__User__acme_corp__` ...)
node_to_cypher(node, tenant_id="beta_inc")    # → MERGE (n:`__User__beta_inc__` ...)

Requirements

  • Python >= 3.11
  • pydantic >= 2.0
  • pandas >= 2.0
  • boto3 >= 1.26
  • Optional: graphrag-toolkit-lexical-graph >= 3.18.0 (for hybrid search)

License

MIT — see LICENSE for details.

See NOTICE for third-party acknowledgments.

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_document_graph-3.0.8.tar.gz (230.4 kB view details)

Uploaded Source

Built Distribution

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

graphrag_document_graph-3.0.8-py3-none-any.whl (255.0 kB view details)

Uploaded Python 3

File details

Details for the file graphrag_document_graph-3.0.8.tar.gz.

File metadata

  • Download URL: graphrag_document_graph-3.0.8.tar.gz
  • Upload date:
  • Size: 230.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for graphrag_document_graph-3.0.8.tar.gz
Algorithm Hash digest
SHA256 438f7f52d8044c532a1f4da0f52f251e45086003ed7c9407b7ef22eb6c8fa26a
MD5 e7cf76480fcddecf66effdc2228f08c4
BLAKE2b-256 387645479c3731613a0ae34a21b177d87cd9018e4500106c4c35346f141e3096

See more details on using hashes here.

File details

Details for the file graphrag_document_graph-3.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for graphrag_document_graph-3.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ca248a29c04f031fab0ee510340ba5d27683e4e4d4b055f7b1f70c2f36f6d862
MD5 6b30b0982363af2aa246b3d412145eaa
BLAKE2b-256 a1d3e603b1ebec42db7e5ae8b98d24ae4acd694006b22dfbe1c7fefdfb27bd08

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