SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2202.10610 · ICML · 2022

Knowledge Base Question Answering by Case-based Reasoning over Subgraphs

Manzil Zaheer, Hannaneh Hajishirzi, Andrew Mccallum, Rajarshi Das, Ameya Godbole, Ankita Naik, Elliot Tower, Robin Jia

arXiv · PDF · Open in the Atlas

Code that ran

4 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"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/2202.10610.json · badge: /api/ran/2202.10610.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.

RepositoryRoleRan
rajarshd/CBR-SUBG canonical (classifier label)
classifier basis not recorded on the link
4 ran · 0 no recorded run
FunctionStatusWhere it lives
create_new_vocab Ran
ran on a synthesized input
rajarshd/CBR-SUBG/adaptive_subgraph_collection/create_input_with_cbr_subgraph.py
code served (permissive licence) · get_code("fdb222b2bc63bbcc")
How it ran

Ran 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 tuple, 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 os
import tempfile
from argparse import Namespace

# Create a temporary directory for output
temp_output_dir = tempfile.mkdtemp()

# Create args object with k parameter
args = Namespace(k=5)

# Create sample cbr_subgraph data
# Format: dict of qid -> list of (e1, relation, e2) tuples
cbr_subgraph = {
    "q1": [("entity_1", "rel_1", "entity_2"), ("entity_2", "rel_2", "entity_3")],
    "q2": [("entity_4", "rel_1", "entity_5"), ("entity_3", "rel_3", "entity_1")],
    "q3": [("entity_6", "rel_4", "entity_7")],
}

# Create sample qid2answers data
# Format: dict of qid -> list of answer entities
qid2answers = {
    "q1": ["entity_1", "entity_8"],
    "q2": ["entity_2", "entity_9"],
    "q3": ["entity_7"],
}

# Define ARGS dictionary with all parameters
ARGS = {
    "args": args,
    "cbr_subgraph": cbr_subgraph,
    "qid2answers": qid2answers,
    "output_dir": temp_output_dir,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple 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
gather_paths Ran
ran on a synthesized input
rajarshd/CBR-SUBG/adaptive_subgraph_collection/adaptive_graph_collection.py
code served (permissive licence) · get_code("57cd6171bd6cc811")
How it ran

Ran 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 torch
import numpy as np

def gather_paths(all_subgraphs):
    train_chains = {}
    for ctr, (qid, all_chains) in enumerate(all_subgraphs.items()):
        all_inference_chains = set()
        for chains in all_chains:
            chains_st_en = chains['chains']
            for path_st_en in chains_st_en:
                if path_st_en == ('type.object.type', 'type.type.instance') or path_st_en == ('22-rdf-syntax-ns#type', 'type.type.instance'):
                    continue
                if type(path_st_en) == str:
                    path_st_en = (path_st_en,)
                all_inference_chains.add(path_st_en)
        train_chains[qid] = all_inference_chains
    return train_chains


all_subgraphs = {
    'q1': [
        {
            'chains': [
                ('rel.entity.type',),
                ('type.object.type', 'type.type.instance'),
                'single_string_path'
            ]
        },
        {
            'chains': [
                ('rel.parent', 'rel.child'),
                ('22-rdf-syntax-ns#type', 'type.type.instance')
            ]
        }
    ],
    'q2': [
        {
            'chains': [
                ('rel.name',),
                ('rel.property', 'rel.value')
            ]
        }
    ]
}

ARGS = {
    'all_subgraphs': all_subgraphs
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — 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
read_cbr_subgraphs Ran
ran on a synthesized input
rajarshd/CBR-SUBG/adaptive_subgraph_collection/create_input_with_cbr_subgraph.py
code served (permissive licence) · get_code("3fa9bfbde6dc1cfa")
How it ran

Ran 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 os
import pickle
import tempfile

# Create temporary files with pickle data for the function to read
temp_dir = tempfile.mkdtemp()

# Create sample subgraph data
sample_subgraphs_train = {
    'q1': [('entity1', 'relation1', 'entity2'), ('entity3', 'relation2', 'entity4-08:00')],
    'q2': [('entity5-08:00', 'relation3', 'entity6'), ('entity7', 'relation4', 'entity8-08:00')]
}

sample_subgraphs_dev = {
    'q3': [('entity9', 'relation5', 'entity10-08:00')],
    'q4': [('entity11-08:00', 'relation6', 'entity12')]
}

sample_subgraphs_test = {
    'q5': [('entity13', 'relation7', 'entity14')],
    'q6': [('entity15-08:00', 'relation8', 'entity16-08:00')]
}

# Write pickle files
train_file = os.path.join(temp_dir, 'train_subgraphs.pkl')
dev_file = os.path.join(temp_dir, 'dev_subgraphs.pkl')
test_file = os.path.join(temp_dir, 'test_subgraphs.pkl')

with open(train_file, 'wb') as f:
    pickle.dump(sample_subgraphs_train, f)

with open(dev_file, 'wb') as f:
    pickle.dump(sample_subgraphs_dev, f)

with open(test_file, 'wb') as f:
    pickle.dump(sample_subgraphs_test, f)

# Define ARGS with the required parameters
ARGS = {
    'subgraph_train_file': train_file,
    'subgraph_dev_file': dev_file,
    'subgraph_test_file': test_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tqdm — 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
sparqlQuery Ran
ran on a synthesized input
rajarshd/CBR-SUBG/adaptive_subgraph_collection/adaptive_utils.py
code served (permissive licence) · get_code("21be15434d5e6ef7")
How it ran

Ran 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 urllib.parse

# Mock the urllib.request.urlopen to avoid actual network calls
import urllib.request
from unittest.mock import Mock, patch
import json

# Create a mock response that returns valid JSON
mock_response_data = {
    "results": {
        "bindings": [
            {"subject": {"value": "http://example.org/subject1"}},
            {"subject": {"value": "http://example.org/subject2"}}
        ]
    }
}

# Patch urlopen to return mock data without making network requests
original_urlopen = urllib.request.urlopen

def mock_urlopen(url, data=None):
    mock = Mock()
    mock.read.return_value = json.dumps(mock_response_data).encode('utf-8')
    return mock

urllib.request.urlopen = mock_urlopen

# Define the arguments
ARGS = {
    'query': 'SELECT ?subject WHERE { ?subject ?predicate ?object }',
    'baseURL': 'http://example.org/sparql',
    'format': 'application/json'
}
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 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

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 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 4 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-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Question answering (QA) over knowledge bases (KBs) is challenging because of the diverse, essentially unbounded, types of reasoning patterns needed. However, we hypothesize in a large KB, reasoning patterns required to answer a query type reoccur for various entities in their respective subgraph neighborhoods. Leveraging this structural similarity between local neighborhoods of different subgraphs, we introduce a semiparametric model (CBR-SUBG) with (i) a nonparametric component that for each query, dynamically retrieves other similar k-nearest neighbor (KNN) training queries along with query-specific subgraphs and (ii) a parametric component that is trained to identify the (latent) reasoning patterns from the subgraphs of KNN queries and then apply them to the subgraph of the target query. We also propose an adaptive subgraph collection strategy to select a query-specific compact subgraph, allowing us to scale to full Freebase KB containing billions of facts. We show that CBR-SUBG can answer queries requiring subgraph reasoning patterns and performs competitively with the best models on several KBQA benchmarks. Our subgraph collection strategy also produces more compact subgraphs (e.g. 55% reduction in size for WebQSP while increasing answer recall by 4.85%) 1 .

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2202.10610")
get_code_for_paper("2202.10610")
have("2202.10610")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2202.10610.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2202.10610.svg)](https://syntology.ai/paper/2202.10610)

Connect an agent — have() is free.