Skip to content
Marko Ivanovski

GraphRAG against vector retrieval

A worked comparison of GraphRAG against traditional vector retrieval, written as a tutorial for the students taking the course next.

category
academic
year
2026
status
completed
role
One of two on the project
  • PyTorch
  • PyTorch Geometric
  • Python

What it is

A two-notebook tutorial for the Social Networks and Media course, written with one colleague as extra material for the students taking it next. Both notebooks answer WebQSP questions over Freebase with the same retrieval: SentenceBERT embeds every node and edge, and a prize-collecting Steiner tree pulls out a small connected subgraph for each question.

They differ only at generation. The first flattens the subgraph into text triples and asks Llama 3.1 8B zero-shot. The second uses PyTorch Geometric's G-Retriever, where a graph attention network turns the subgraph into soft prompt tokens and LoRA teaches the model to read them. On the same 100 test questions, exact match rose from 41% to 85% and F1 from 69.3% to 88.2%, after one epoch on 300 samples.

figure 1 · results on the WebQSP test split, 100 questionsG-Retriever answered 85% of the 100 test questions exactly, against 41% for the same subgraph given to Llama 3.1 8B as plain-text triples. F1 rose from 69.3% to 88.2%, after one epoch of training on 300 questions.
The numbers
GroupMethodScore
Exact matchTextualised triples, plain prompt41.0%
Exact matchG-Retriever, GAT and LoRA85.0%
F1Textualised triples, plain prompt69.3%
F1G-Retriever, GAT and LoRA88.2%

Evaluation cells of both notebooks, SQuAD exact match and F1.

  • A two-notebook series over WebQSP and Freebase, framed for a reader meeting the technique for the first time.
  • SentenceBERT indexing and PCST subgraph extraction feeding a 4-bit Llama 3.1 8B Instruct.
  • Compares a PyTorch Geometric G-Retriever, GAT with LoRA, against a textualised-triples baseline.

What I learnt

  1. Retrieval quality sets the ceiling. Even a strong model cannot answer well from an incomplete or irrelevant subgraph.
  2. Text triples are readable but flatten the graph into a sequence. The graph encoder keeps multi-hop structure that text loses.
  3. The two approaches are complementary. G-Retriever feeds the model both the graph tokens and the text description.
  4. A little LoRA training goes a long way. One epoch on 300 samples was enough for the jump in exact match.

What I would do next

Train on more of WebQSP and for more epochs, and try larger language models.

Explore hybrid retrieval, graphs built on the fly, and multimodal GraphRAG.