Paper · 2507.04127 · EMNLP · 2025
BYOKG-RAG: Multi-Strategy Graph Retrieval for Knowledge Graph Question Answering
Qi Zhu, Zhen Han, George Karypis, Vassilis Ioannidis, Huzefa Rangwala, Soji Adeshina, Costas Mavromatis, Ian Robinson, Bryan Thompson
arXiv · PDF · Open in the Atlas
Code that ran
3 of 3 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 2 failures of our instrument; 0 no recorded run), measured 2026-11-24; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.
- 1 ran with no instrument failure
0 honoured the contract we drafted, 0 violated it, 1 have no contract verdict
- 2 ran where Syntology's instrument failed
failures of Syntology's instrument, not of the code: 2 where our contract draft was wrong, 0 where the contract check could not run
- 0 have no recorded run
- 1 of those that ran constructed an object rather than computing a result
an executed sample whose run returned an instance of its own class (fixture_out_type equals the entry name): the run built an object and did not compute a result
- 0 are pointer only: the body is not served under this paper's link
"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2507.04127.json · badge: /api/ran/2507.04127.svg
Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.
| Function | Status | Where it lives |
|---|
| ByoKGQueryEngine |
Ran ran on a synthesized input · constructed an object; no result was computed |
awslabs/graphrag-toolkit/byokg-rag/src/graphrag_toolkit/byokg_rag/byokg_query_engine.py code served (permissive licence) · get_code("6fc2ec66d1539715") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, ByoKGQueryEngine: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import torch.nn as nn
from typing import List, Dict, Any, Optional
class MockGraphStore:
"""Minimal graph store implementation with required methods."""
def __init__(self):
self.graph_data = {
'nodes': ['node1', 'node2', 'node3'],
'edges': [('node1', 'node2'), ('node2', 'node3')]
}
def get_schema(self):
return {
'node_types': ['entity', 'concept'],
'relation_types': ['related_to', 'has_property']
}
def nodes(self):
return self.graph_data['nodes']
def execute_query(self, query):
return []
class MockEntityLinker:
"""Minimal entity linker with required interface."""
def __init__(self):
self.name = "entity_linker"
def link(self, text):
return []
class MockTripletRetriever:
"""Minimal triplet retriever."""
def retrieve(self, query):
return []
class MockPathRetriever:
"""Minimal path retriever."""
def retrieve(self, source, target):
return []
class MockGraphQueryExecutor:
"""Minimal graph query executor."""
def execute(self, query):
return []
class MockLLMGenerator:
"""Minimal LLM generator with required interface."""
def __call__(self, prompt):
return "Generated response"
def generate(self, prompt):
return "Generated response"
class MockKGLinker:
"""Minimal KG linker with required attributes."""
def __init__(self):
self.task_prompts = {
'task1': 'prompt1',
'task2': 'prompt2'
}
self.task_prompts_iterative = {
'iter_task1': 'iter_prompt1'
}
class MockCypherKGLinker:
"""Minimal Cypher KG linker with required attributes."""
def __init__(self):
self.is_cypher_linker = True
self.task_prompts = {
'cypher_task1': 'cypher_prompt1'
}
self.task_prompts_iterative = {
'cypher_iter_task1': 'cypher_iter_prompt1'
}
# Create instances for ARGS
graph_store = MockGraphStore()
entity_linker = MockEntityLinker()
triplet_retriever = MockTripletRetriever()
path_retriever = MockPathRetriever()
graph_query_executor = MockGraphQueryExecutor()
llm_generator = MockLLMGenerator()
kg_linker = MockKGLinker()
cypher_kg_linker = MockCypherKGLinker()
ARGS = {
'graph_store': graph_store,
'entity_linker': entity_linker,
'triplet_retriever': triplet_retriever,
'path_retriever': path_retriever,
'graph_query_executor': graph_query_executor,
'llm_generator': llm_generator,
'kg_linker': kg_linker,
'cypher_kg_linker': cypher_kg_linker,
'direct_query_linking': False
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch, yaml — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type ByoKGQueryEngine — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ByoKGQueryEngine output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| load_yaml |
Ran ran; our contract draft was wrong, not the code |
awslabs/graphrag-toolkit/byokg-rag/src/graphrag_toolkit/byokg_rag/byokg_query_engine.py code served (permissive licence) · get_code("a73dde4f787afe07") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import yaml
import os.path as osp
import tempfile
import os
# Create a temporary YAML file for testing
temp_dir = tempfile.mkdtemp()
yaml_file_path = osp.join(temp_dir, "test_config.yaml")
# Write a sample YAML file
yaml_content = {
"model": "test_model",
"learning_rate": 0.001,
"batch_size": 32,
"layers": [64, 128, 256]
}
with open(yaml_file_path, 'w') as f:
yaml.dump(yaml_content, f)
# Define ARGS with a relative path that will be resolved
ARGS = {
"file_path": yaml_file_path
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- yaml — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| parse_response |
Ran ran; our contract draft was wrong, not the code |
awslabs/graphrag-toolkit/byokg-rag/src/graphrag_toolkit/byokg_rag/byokg_query_engine.py code served (permissive licence) · get_code("0cac8c1bedf394c9") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import re
def parse_response(response, pattern):
if not isinstance(response, str):
return []
match = re.search(pattern, response, flags=re.DOTALL)
matched = []
if match:
graph_text = match.group(1)
for to_match in graph_text.strip().split('\n'):
if to_match != '':
matched.append(to_match)
return matched
# Setup code
response_text = """
Some intro text here.
START_GRAPH
node1 -> node2
node2 -> node3
edge_label
END_GRAPH
Some outro text.
"""
pattern = r"START_GRAPH\n(.*?)\nEND_GRAPH"
ARGS = {
"response": response_text,
"pattern": pattern
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
Also present in other papers' code
Of 3 samples lifted from this paper's linked repositories, 3 carry a function identity and 0 do not. Of the 3 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 3 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).
Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.
Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.
Repositories linked to this paper
Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.
Abstract
Knowledge graph question answering (KGQA) presents significant challenges due to the structural and semantic variations across input graphs. Existing works rely on Large Language Model (LLM) agents for graph traversal and retrieval; an approach that is sensitive to traversal initialization, as it is prone to entity linking errors and may not generalize well to custom ("bring-your-own") KGs. We introduce BYOKG-RAG, a framework that enhances KGQA by synergistically combining LLMs with specialized graph retrieval tools. In BYOKG-RAG, LLMs generate critical graph artifacts (question entities, candidate answers, reasoning paths, and OpenCypher queries), and graph tools link these artifacts to the KG and retrieve relevant graph context. The retrieved context enables the LLM to iteratively refine its graph linking and retrieval, before final answer generation. By retrieving context from different graph tools, BYOKG-RAG offers a more general and robust solution for QA over custom KGs. Through experiments on five benchmarks spanning diverse KG types, we demonstrate that BYOKG-RAG outperforms the second-best graph retrieval method by 4.5% points while showing better generalization to custom KGs. BYOKG-RAG framework is open-sourced at https:// github.com/awslabs/graphrag-toolkit.
For agents
The same record, over MCP at https://syntology.ai/mcp:
get_harvested_code_for_paper("2507.04127")
get_code_for_paper("2507.04127")
have("2507.04127")
The run record, dated, one paper per request, free:
curl https://syntology.ai/api/ran/2507.04127.json
A badge for a README (the split and the date, never a ratio):
[](https://syntology.ai/paper/2507.04127)
Connect an agent — have() is free.