BYOKG-RAG: Bring Your Own Knowledge Graph for Retrieval Augmented Generation
BYOKG-RAG is a novel approach to Knowledge Graph Question Answering (KGQA) that combines the power of Large Language Models (LLMs) with structured knowledge graphs. The system allows users to bring their own knowledge graph and perform complex question answering over it.
Key Features
- Multi-strategy Retrieval: Combines multiple retrieval strategies through iterative processing:
- Agentic triplet retrieval for LLM-guided dynamic graph exploration
- Scoring-based triplet retrieval for semantic-based triplet retrieval
- Path-based retrieval for multi-hop reasoning through entity paths
- Query-based retrieval for direct Cypher graph queries
- Iterative Processing: Uses iterative approach combining multi-strategy and Cypher-based retrieval
- LLM-powered Reasoning: Leverages state-of-the-art LLMs for question understanding and answer generation
Prerequisites
Python Version
Python 3.10 or higher is required.
AWS Services
The byokg-rag library integrates with the following AWS services:
- Amazon Bedrock - Provides access to foundation models for LLM inference and embeddings
- Amazon Neptune Analytics - Graph analytics service with native vector search (optional)
- Amazon Neptune Database - Graph database service for transactional workloads (optional)
- Amazon S3 - Object storage for data loading and embedding storage
NOTE: You can use the local graph store for development without AWS services. Production deployments typically use Neptune Analytics or Neptune Database.
IAM Permissions
Minimum IAM permissions required for AWS integration:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel"
],
"Resource": "arn:aws:bedrock:<region>::foundation-model/*"
},
{
"Effect": "Allow",
"Action": [
"neptune-graph:ReadDataViaQuery",
"neptune-graph:GetGraph"
],
"Resource": "arn:aws:neptune-graph:<region>:<account-id>:graph/*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::<bucket-name>/*"
}
]
}
NOTE: Additional permissions may be required for Neptune Database (neptune-db:*) or specific Bedrock models. Adjust the policy based on your deployment.
System Components
-
ByoKGQueryEngine (src/graphrag_toolkit/byokg_rag/byokg_query_engine.py)
- Core orchestrating component with dual-mode processing
- Implements iterative retrieval with configurable iterations
- Combines multi-strategy and Cypher-based approaches
-
KG Linkers (src/graphrag_toolkit/byokg_rag/graph_connectors)
- KGLinker: Base class for LLM-guided graph operations
- CypherKGLinker: Specialized for Cypher query generation and execution
- Links natural language queries to graph entities and relationships
-
Graph Retrievers (src/graphrag_toolkit/byokg_rag/graph_retrievers)
- AgenticRetriever: LLM-guided iterative exploration with entity linking
- PathRetriever: Multi-hop reasoning through entity relationship paths
- GraphQueryRetriever: Direct Cypher query execution and result processing
- Rerankers: BGE-based semantic reranking for improving retrieval relevance
-
Graph Store (src/graphrag_toolkit/byokg_rag/graphstore)
- Manages knowledge graph data structure and connectivity
- Provides interfaces for graph traversal and querying
- Supports multiple graph database backends
Security: Query Modification Protection
The GraphQueryRetriever blocks Cypher queries containing modification keywords (CREATE, MERGE, DELETE, SET, REMOVE, DROP, DETACH, CALL) to protect against LLM-generated or user-supplied queries that could modify graph data.
Neptune Database and Neptune Analytics (Graph): Neither service supports a server-enforced readOnly query parameter. Write protection relies solely on application-level Cypher validation (is_query_safe()). For stronger server-side guarantees, restrict the IAM role to neptune-db:ReadDataViaQuery (Neptune DB) or neptune-graph:ReadDataViaQuery (Neptune Analytics).
Performance
Our results show that BYOKG-RAG outperforms existing approaches across multiple knowledge graph benchmarks:
| KGQA Hit (%) | Wiki-KG | Temp-KG | Med-KG |
|---|---|---|---|
| Agent | 77.8 | 57.3 | 59.2 |
| BYOKG-RAG | 80.1 | 65.5 | 65.0 |
See our paper for detailed methodology and results.
Getting Started
The byokg-rag toolkit requires Python and pip to install. You can install from PyPI:
pip install graphrag-byokg
Or install from source:
pip install .
Or install from GitHub:
pip install https://github.com/awslabs/graphrag-toolkit/archive/refs/tags/graphrag-byokg/v3.19.0.zip#subdirectory=byokg-rag
NOTE: The version number will vary based on the latest GitHub release.
Quick Start
Run the demo notebooks:
Configuration Reference
Complete documentation is available in the docs/byokg-rag/ directory:
- Overview - Architecture, KGQA approach, and system components
- Indexing - Dense index, fuzzy string index, and graph-store index setup
- Graph Stores - Supported graph stores and connection setup
- Configuration - Complete parameter documentation
- FAQ - Common questions and troubleshooting
Examples
Additional examples are available in the examples/byokg-rag/ directory.
Unit testing
The complete unit tests can be found under tests/, please see `tests/README.md for more details.
Citation
If you use BYOKG-RAG in your research, please cite our paper (to appear in EMNLP Main 2025):
Paper: BYOKG-RAG: Multi-Strategy Graph Retrieval for Knowledge Graph Question Answering
@article{mavromatis2025byokg,
title={BYOKG-RAG: Multi-Strategy Graph Retrieval for Knowledge Graph Question Answering},
author={Mavromatis, Costas and Adeshina, Soji and Ioannidis, Vassilis N and Han, Zhen and Zhu, Qi and Robinson, Ian and Thompson, Bryan and Rangwala, Huzefa and Karypis, George},
journal={arXiv preprint arXiv:2507.04127},
year={2025}
}
License
This project is licensed under the Apache-2.0 License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphrag_byokg-3.19.0.tar.gz.
File metadata
- Download URL: graphrag_byokg-3.19.0.tar.gz
- Upload date:
- Size: 86.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80a219201cf80a3eed585f897d479b641cb9902450340362c3d2843369d2a12
|
|
| MD5 |
b1358fe7886b11a57aa1f70bfc49b17b
|
|
| BLAKE2b-256 |
fcb059fac838bb8ecc5607ba862d4062f90711b6c8c8ec6f804a70c21cd30eea
|
Provenance
The following attestation bundles were made for graphrag_byokg-3.19.0.tar.gz:
Publisher:
byokg-rag-release.yml on awslabs/graphrag-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphrag_byokg-3.19.0.tar.gz -
Subject digest:
c80a219201cf80a3eed585f897d479b641cb9902450340362c3d2843369d2a12 - Sigstore transparency entry: 2505879136
- Sigstore integration time:
-
Permalink:
awslabs/graphrag-toolkit@cd008fdabf6c79157d17af3e4a2a5a3a43f97451 -
Branch / Tag:
refs/tags/graphrag-byokg/v3.19.0 - Owner: https://github.com/awslabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
byokg-rag-release.yml@cd008fdabf6c79157d17af3e4a2a5a3a43f97451 -
Trigger Event:
release
-
Statement type:
File details
Details for the file graphrag_byokg-3.19.0-py3-none-any.whl.
File metadata
- Download URL: graphrag_byokg-3.19.0-py3-none-any.whl
- Upload date:
- Size: 52.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
571da401329ff7e3ba09cac0ff7c449ed6d1d02279c406742b857c13f53c91a7
|
|
| MD5 |
bc3b8fe249120b40f5319f34f45a61e8
|
|
| BLAKE2b-256 |
c8ebe873f510788c08748c890b7a6d822c6e0f7725923dca39c1f772fe81d1e5
|
Provenance
The following attestation bundles were made for graphrag_byokg-3.19.0-py3-none-any.whl:
Publisher:
byokg-rag-release.yml on awslabs/graphrag-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphrag_byokg-3.19.0-py3-none-any.whl -
Subject digest:
571da401329ff7e3ba09cac0ff7c449ed6d1d02279c406742b857c13f53c91a7 - Sigstore transparency entry: 2505879740
- Sigstore integration time:
-
Permalink:
awslabs/graphrag-toolkit@cd008fdabf6c79157d17af3e4a2a5a3a43f97451 -
Branch / Tag:
refs/tags/graphrag-byokg/v3.19.0 - Owner: https://github.com/awslabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
byokg-rag-release.yml@cd008fdabf6c79157d17af3e4a2a5a3a43f97451 -
Trigger Event:
release
-
Statement type: