GNN-RAG: Graph Neural Retrieval for Efficient Large Language Model Reasoning on Knowledge Graphs
TL;DR Highlight
Using a GNN to pre-filter relevant paths from a Knowledge Graph before passing them to an LLM improves both KGQA accuracy and speed.
Who Should Read
Backend/ML developers building Knowledge Graph-based QA systems or wanting to use graph-structured data in RAG pipelines. Anyone thinking about connecting large-scale graph DBs like Wikidata or Freebase to LLMs.
Core Mechanics
- When doing RAG on a Knowledge Graph, dumping all paths into the LLM causes token explosion — a GNN pre-filters only relevant subgraph paths and compresses the LLM input
- Uses a GNN (graph neural network) as a retriever, scoring entities and relation paths relevant to the question and selecting only Top-K
- The LLM only receives compressed natural language paths for reasoning, enabling accurate answers with far less context than directly traversing the entire graph
- GNN retriever and LLM reasoner are decoupled — GNN is lightly fine-tuned, LLM works with prompts only — making it cost-efficient
- Clear advantage over embedding-based RAG on multi-hop reasoning (questions requiring crossing multiple relations)
Evidence
- Achieves competitive numbers on WebQSP benchmark Hits@1 vs latest KGQA models (top tier per paper Table)
- GNN retriever compresses average KG path candidates from thousands to tens, dramatically reducing LLM input tokens
- Meaningful improvement over RAG baselines on multi-hop question handling in the CWQ (ComplexWebQuestions) dataset
- Consistent performance improvements when combined with various LLM backends including GPT-3.5/GPT-4
How to Apply
- For Freebase/Wikidata QA services: extract relevant subgraph paths with a GNN retriever at query time, convert to 'entityA → relation → entityB' text, and insert into the LLM prompt
- When the graph DB is too large to feed directly to the LLM, add a lightweight GNN model (e.g., 2-3 layer RGCN) as a retriever fine-tuned to extract only Top-K paths as a preprocessing step before the RAG chain
- For multi-hop questions (e.g., 'Who is the mayor of the city where film X's director was born?'), replace simple vector similarity search with GNN-based path scoring
Code Example
# GNN-RAG pipeline concept code (PyG + LangChain style)
import torch
from torch_geometric.nn import RGCNConv
# 1. GNN Retriever: extract relevant paths from subgraph around question entity
class GNNRetriever(torch.nn.Module):
def __init__(self, in_channels, hidden, num_relations):
super().__init__()
self.conv1 = RGCNConv(in_channels, hidden, num_relations)
self.conv2 = RGCNConv(hidden, hidden, num_relations)
self.score = torch.nn.Linear(hidden, 1)
def forward(self, x, edge_index, edge_type):
x = self.conv1(x, edge_index, edge_type).relu()
x = self.conv2(x, edge_index, edge_type).relu()
return self.score(x).squeeze(-1) # relevance score for each node
# 2. Convert high-scoring paths to natural language
def paths_to_text(top_k_paths):
"""[(entity1, relation, entity2), ...] -> str"""
lines = [f"{e1} --[{rel}]--> {e2}" for e1, rel, e2 in top_k_paths]
return "\n".join(lines)
# 3. Insert paths into LLM prompt
def build_prompt(question, kg_paths_text):
return f"""Answer the question by referring to the following Knowledge Graph paths.
[KG Paths]
{kg_paths_text}
[Question]
{question}
[Answer]"""
# Usage example
# paths = gnn_retriever.get_top_k_paths(question_entity, k=20)
# prompt = build_prompt("What is the nationality of the director of the movie Inception?", paths_to_text(paths))
# answer = llm(prompt)Terminology
Related Papers
Show HN: Airbyte Agents – context for agents across multiple data sources
Airbyte가 Slack, Salesforce, Linear 등 여러 SaaS 시스템의 데이터를 미리 인덱싱해서 Agent가 API를 일일이 뒤지지 않아도 되는 Context Store를 출시했다. 기존 MCP 방식보다 토큰을 최대 90%까지 줄이는 효과를 확인했다.
A polynomial autoencoder beats PCA on transformer embeddings
PCA 인코더에 2차 다항식 디코더를 붙여서 닫힌 형태(closed-form)로 embedding 압축 품질을 크게 개선하는 기법으로, SGD 없이 numpy만으로 구현 가능하다.
From Unstructured Recall to Schema-Grounded Memory: Reliable AI Memory via Iterative, Schema-Aware Extraction
RAG 스타일 텍스트 검색 대신 Schema로 정의된 구조화 레코드에 메모리를 저장하면, 정확한 사실 조회·상태 추적·집계 쿼리에서 압도적으로 높은 정확도를 얻을 수 있다.
Show HN: Atomic – Local-first, AI-augmented personal knowledge base
Atomic builds a self-hosted, open-source personal knowledge graph app that automatically embeds, tags, and links notes, web clips, and RSS feeds—supporting semantic search, LLM-powered wiki synthesis, and MCP integration.
We replaced RAG with a virtual filesystem for our AI documentation assistant
Explains how Mintlify overcame RAG chunking limitations by building a virtual filesystem (ChromaFs) on top of Chroma DB that mimics UNIX commands, reducing session boot time from 46 seconds to 100ms.
Chroma Context-1: Training a Self-Editing Search Agent