Why did we open-source our inference engine? Read the post
← All Glossary Articles

What are Graph Neural Networks (GNNs)?

A Graph Neural Network (GNN) is a type of neural network designed to operate on graph-structured data, where entities (nodes) are connected by relationships (edges). GNNs learn representations by aggregating information from a node’s neighbourhood, capturing both the node’s own features and the structure of its connections. They are used in knowledge graphs, recommendation systems, molecular modelling, and fraud detection.


Why do GNNs matter for search and retrieval?

Graph structures appear naturally in many retrieval problems:

  • Knowledge graphs: entities and their relationships form a graph that can be traversed or queried alongside vector search
  • Document graphs: documents citing each other, co-authored papers, or linked web pages
  • Entity relationships: in enterprise RAG, documents are connected to authors, topics, and projects
  • Recommendation: user-item interaction graphs underpin many modern recommendation systems

GNNs can produce graph-aware embeddings where a node’s representation is informed by its neighbours, enriching retrieval beyond what a text-only embedding captures.


How does a GNN work?

GNNs operate through message passing: each node aggregates feature vectors from its neighbours, combines them with its own features, and updates its representation. This repeats for K layers, gradually expanding the neighbourhood considered.

h_v^(k) = UPDATE(h_v^(k-1), AGGREGATE({h_u^(k-1) : u ∈ N(v)}))

Where:

  • h_v^(k) = representation of node v at layer k
  • N(v) = neighbours of v
  • AGGREGATE = sum, mean, max, or attention-weighted combination
  • UPDATE = neural network (MLP, GRU)

After K layers, each node’s representation encodes information from its K-hop neighbourhood.


Main GNN architectures

ArchitectureAggregationKey feature
GCN (Graph Convolutional Network)Normalised sumSimple, effective for homogeneous graphs
GAT (Graph Attention Network)Attention-weightedLearns which neighbours to weight more
GraphSAGEMean/max/LSTMInductive: generalises to unseen nodes
GIN (Graph Isomorphism Network)Sum + MLPMaximum expressive power

GATs are particularly useful when neighbour importance varies, e.g. some citations are more relevant than others.


GNNs vs standard embedding models

Standard embedding modelGNN
InputSequence (text, image)Graph (nodes + edges)
ContextWithin documentAcross connected nodes
CapturesSemantic contentContent + graph structure
Self-hostable with SIE✓ (text/image models)Requires graph infrastructure

For most RAG and search use cases, text embedding models are the right tool. GNNs add value when the relationship structure between entities is itself informative.


GNNs in recommendation systems

GNNs power several major recommendation systems (Pinterest PinSage, Alibaba EGES) by encoding both item content and user-item interaction graphs. The user’s embedding becomes a function of items they’ve interacted with and their graph-neighbours’ interactions, capturing collaborative filtering signals alongside content signals.

For a more accessible introduction to embedding-based recommendation, see the SIE Recommendation Systems example and the Recommendation Systems glossary article.


Frequently asked questions

When should I use a GNN instead of a standard embedding model? When relationships between entities are informative and you have explicit graph structure. For plain document retrieval, text embeddings are simpler and usually sufficient.

Can GNN embeddings be stored in a vector database? Yes. After training, GNN node embeddings are fixed-size vectors and can be indexed in any vector DB (Qdrant, Weaviate) for ANN search.

What’s the difference between a GNN and a knowledge graph embedding? Knowledge graph embeddings (TransE, RotatE) learn entity and relation representations optimised for link prediction. GNNs are more general; they can incorporate rich node features and are trained end-to-end for arbitrary tasks.


Self-hosted inference for search & document processing

Cut API costs by 50x, boost quality with 85+ SOTA models, and keep your data in your own cloud.

Github 2.0K

Contact us

Tell us about your use case and we'll get back to you shortly.