GraphNIAH / README.md
minhnam's picture
Add arXiv link (2610.41704) and citation
b1ab0bd verified
|
Raw History Blame Contribute Delete
21.1 kB
metadata
pretty_name: GraphNIAH
license: other
language:
  - en
task_categories:
  - question-answering
  - text-classification
tags:
  - long-context
  - needle-in-a-haystack
  - multi-hop-reasoning
  - graph-reasoning
  - citation-graph
  - benchmark
size_categories:
  - 1K<n<10K
configs:
  - config_name: default
    data_files:
      - split: test
        path: examples.jsonl

GraphNIAH: A Benchmark for Long-Context Reasoning over Real-World Graphs

Minh-Nam Tran, Abulhair Saparov

Paper Code Project Page BibTeX

GraphNIAH is a needle-in-a-haystack (NIAH) benchmark for long-context, non-linear reasoning over real citation graphs. Each example writes a subgraph of the Semantic Scholar citation graph as text, hides it among distracting content in a 200k–922k-token prompt, and asks whether (or how many) papers are reachable from a source paper through cites / cited_by relationships.

  • Real data, no contamination: every paper on the sampled citation paths was published on or after April 1, 2026, after the evaluated models' knowledge cutoffs.
  • Non-linear reasoning: the model must search many possible paths, not just follow one obvious chain. To answer NO, it must check every paper that is reachable from the source.
  • Verifiable answers: every answer is computed directly from the subgraph. There is no human or LLM annotation.
  • Updatable: the code builds new examples automatically as new papers are published.

Three kinds of NIAH tests: single-hop NIAH, linear multi-hop NIAH, and GraphNIAH.

Tasks

Examples of the YES/NO, counting, and multiple-choice reachability tasks.

Each subgraph has several connected components that share no paper. Reachability is defined only by the relationships written in the context, not by the full Semantic Scholar graph.

reachability_task Question answer
yes-no Is target paper t reachable from source paper s? "YES" or "NO" (balanced)
multiple-choice Which of the options is reachable from s? Exactly one of four options is reachable. "A"–"D" (balanced)
counting How many distinct papers are reachable from s, not counting s? An integer as a string, e.g. "169"

The appended-"None" variant of multiple choice adds a fifth option, E. None of these targets is reachable from the source., which is never correct.

Dataset structure

Files

File Content
examples.jsonl 8,686 unique examples (the test split), one JSON object per line. Each example is listed once, even when several experiments use it.
pipeline_outputs/experiments.v1_data.2026-04-01.zip Full experiment outputs for reproduction (about 4.7 GB). Not part of the test split. See Raw experiment files.

GraphNIAH is an evaluation benchmark. It has no training or validation split.

Fields

Field Type Description
qid string Unique example ID (SHA-256 hex).
reachability_task string yes-no, multiple-choice, or counting.
system_prompt string System message sent to the model.
user_prompt string Full user message: question, context (papers + distractors), and answer-format instructions. This is the long field (about 0.2M–0.9M tokens).
question string The question alone, including the options for multiple choice.
answer string Ground-truth answer (see the table above).
question_type string Internal task name: reachability-yesno, reachability-multiple, reachability-counting.
answer_type string Internal answer type, e.g. REACHABILITY_COUNTING.
options list of {label, text} Multiple-choice options. Present only for multiple-choice examples.
config object Settings used to build the example (see below).
token_counts object Prompt length in tokens for each tokenizer: gpt-5.4 (o200k_base), qwen3.5-397b-a17b, gemma-4-31b.
generator_version string Generator identifier, create_dataset.v1:4.
experiments list of objects The experiments that use this example (see below).

Main config keys:

Key Meaning Values
question_depth Papers on the true path from source to target (including both ends) 4, 8, 16, 32
component_node_count Papers in each connected component 100–250
question_format Task reachability-yesno, reachability-multiple, reachability-counting
distractor_type Distracting content code, essays, books, wikipedia, disjoint-tree (called disjoint-component in the paper)
context_length Target prompt length in tokens 200000, 500000, 922000
answer_condition Planned label (YES/NO or option letter) Not set for counting
none_option 1 if the "None" option was appended 0 or 1
source_qid Original example of a converted "None" example Only when none_option is 1
alpha Preferential-attachment parameter of subgraph growth 0.1
cutoff_date Earliest publication date of the path papers 2026-04-01

The other config keys (traversal_mode, needle_type, needle_order, num_options, yes_ratio, ...) are fixed construction settings.

Each item of experiments has:

Key Meaning
name Experiment name (see the next table).
context_length Target context length of that experiment.
random_seed Seed of that experiment (1).
slot Position of the example in that experiment's ordered list (0-based).
path The experiment file inside the zip archive (repo-relative path).

Experiments

Each experiment varies one variable. All other variables are drawn at random for each example.

experiments[].name Context Varied values Examples in the list Evaluated in the paper
question-depth 200k depth 4, 8, 16, 32 2,000 (500 per value) 100 per value
node-count 200k component size 100, 150, 200, 250 2,000 (500 per value) 100 per value
question-format 200k YES/NO, multiple choice, counting 1,500 (500 per value) 100 per value
distractor-type 200k 5 distractor types 2,500 (500 per value) 100 per value
reasoning_effort 200k low / medium / high (same examples) 500 100
context_length 500k – 500 50
context_length 922k – 500 50
question-format/none-option/reasoning_effort=low/model=<model> 200k appended "None" option 100 per model 100

The 200k context-length point in the paper reuses the reasoning_effort examples. The three "None"-option lists (gpt-5.6-luna, qwen3.5-35b-a3b, gemini-3.8-flash) contain the same 100 converted examples.

Some examples appear in more than one list, because identical settings produce the same example. This is why the 9,800 list entries contain only 8,686 unique examples.

Getting the evaluated subset. Within an experiment, examples are ordered round-robin over the varied values (slot 0 = value 1, slot 1 = value 2, ...). So the first N examples of every value are the slots 0 … N × (number of values) − 1. The paper evaluated 1,760 distinct examples in total.

Usage

from datasets import load_dataset

ds = load_dataset("minhnam/GraphNIAH", split="test")

# Number of varied values per experiment, and examples evaluated per value in the paper.
EVALUATED = {
    ("question-depth", 200_000): (4, 100),
    ("node-count", 200_000): (4, 100),
    ("question-format", 200_000): (3, 100),
    ("distractor-type", 200_000): (5, 100),
    ("reasoning_effort", 200_000): (1, 100),
    ("context_length", 500_000): (1, 50),
    ("context_length", 922_000): (1, 50),
}

def in_paper_subset(example, name, context_length=200_000):
    values, per_value = EVALUATED[(name, context_length)]
    return any(
        e["name"] == name
        and e["context_length"] == context_length
        and e["slot"] < values * per_value
        for e in example["experiments"]
    )

depth = ds.filter(lambda ex: in_paper_subset(ex, "question-depth"))
print(len(depth))  # 400

example = depth[0]
messages = [
    {"role": "system", "content": example["system_prompt"]},
    {"role": "user", "content": example["user_prompt"]},
]

Scoring. Each prompt asks the model to end with one line \answer{...}. The paper reads the answer as follows and compares it with answer, after light normalization of both sides (for example, whitespace, Markdown or LaTeX emphasis, trailing punctuation, and letter case):

  • YES/NO and counting: the last \answer{} block. If there is none, the end of the response (last 100 characters for YES/NO, last 30 for counting) counts only when it is exactly a label or an integer.
  • Multiple choice: one option letter, taken from the whole response (e.g. C, C., Option C), from the \answer{} block, or from the last non-empty line.

Responses without a readable answer count as wrong. A simplified version that reads only the \answer{} block:

import re

def extract_answer(response: str) -> str | None:
    matches = re.findall(r"\\answer\{([^{}]*)\}", response)
    return matches[-1].strip() if matches else None

correct = extract_answer(model_response) == example["answer"]

The full scorer, with confidence intervals and per-label breakdowns, is run_eval.py in the code repository.

The prompts are very long. Most examples need a model with a context window of at least 200k tokens; the context_length examples need about 500k and 922k tokens. Check token_counts for your tokenizer before sending a request.

Raw experiment files

pipeline_outputs/experiments.v1_data.2026-04-01.zip holds the complete outputs behind the paper. Download it and unzip it in the root of the code repository to restore the original folder structure:

hf download minhnam/GraphNIAH pipeline_outputs/experiments.v1_data.2026-04-01.zip \
    --repo-type=dataset --local-dir .
unzip pipeline_outputs/experiments.v1_data.2026-04-01.zip

The archive contains:

output/data.2026-04-01/hops=<10|22|46|94>/papers-only/
    sampled_paths.json            # sampled citation paths (path lengths count papers)
    disjoint_path_groups.json     # path groups used to build disjoint components
output/experiments.v1/
    pool.jsonl                    # every built example, with full metadata
    inference_pool*.jsonl         # cached model responses
    cutoff_date=2026-04-01/hops=10-22-46-94/context_length=<200k|500k|922k>/seed=1/alpha=0.1/
        vary=<experiment>/experiment.jsonl                # ordered list of qids
        vary=<experiment>/experiment.jsonl.settings.json  # experiment settings
        vary=<experiment>/inference/reasoning_effort=<effort>/model=<model>.json  # model responses
        vary=<experiment>/eval/reasoning_effort=<effort>/model=<model>.json       # scores

pool.jsonl has more fields than examples.jsonl. For example, it contains the rendered needles, the paper IDs of each component, the visible citation graph, and the source of every distractor. The zip also has results for gemini-3.7-flash, which is not reported in the paper. The alpha-search pools are not included.

How the examples are built

  1. Backbone: sample a real undirected citation path of 3k − 2 papers (all published on or after 2026-04-01). Split it into a distractor path, the true path from s to t (k papers), and another distractor path. So at least k − 1 search steps are needed from either end.
  2. Subgraph growth: add real neighboring papers with a preferential-attachment rule (α = 0.1), which mimics the scale-free degree distribution of citation graphs. Every component stays a tree.
  3. Rendering: write each paper that cites another paper in its component as a text block (title, authors, publication information) with an APA-style reference list.
  4. Distractors and packing: add distractors until the target context length is full, then shuffle all blocks. The distractor types are: Linux kernel source files (code), Paul Graham essays (essays), PG-19 books (books), Wikipedia passages (wikipedia), or extra citation components (disjoint-tree).

YES-label and NO-label examples differ only in where t is placed, and all components of an example are sampled in the same way. This prevents shortcuts such as guessing from topic similarity.

Limitations

  • The examples cover citation graphs of papers from one Semantic Scholar release (2026-10-06 download recipe) and one cutoff date (2026-04-01). Models trained on later data may have seen these papers.
  • Paper metadata (titles, authors, venues) comes from Semantic Scholar and may contain errors. Answers are still correct by construction, because they are computed from the relationships written in the prompt.
  • The paper evaluated 100 examples per value (50 for 500k/922k), so small accuracy differences are not statistically significant.
  • token_counts were measured with three tokenizers. Other tokenizers may give different prompt lengths.

Licensing

The prompts contain text from third-party sources, each under its own terms:

Source Used for Terms
Semantic Scholar Academic Graph Paper metadata and citations ODC-BY 1.0 (attribution required)
Linux kernel code distractors GPL-2.0
Paul Graham essays (sgoel9/paul_graham_essays) essays distractors Copyright of the author
PG-19 books distractors Public-domain books (Project Gutenberg); dataset under Apache-2.0
Wikipedia (wikipedia-dpr-100w, Pyserini) wikipedia distractors CC BY-SA 4.0

Citation

@article{tran2026graphniah,
  title   = {{GraphNIAH}: A Benchmark for Long-Context Reasoning over Real-World Graphs},
  author  = {Tran, Minh-Nam and Saparov, Abulhair},
  journal = {arXiv preprint arXiv:2610.41704},
  year    = {2026},
  url     = {https://arxiv.org/abs/2610.41704}
}

Contact

Please open a discussion on this dataset page or an issue in the code repository, or contact Minh-Nam Tran (tran555@purdue.edu).