What is Graph RAG?

Graph RAG means connecting a large language model (LLM) to a knowledge graph: before answering, the model looks up the facts relevant to the question in the graph.

The answer is then based on knowledge that is identified, interlinked and verifiable.

  1. Questionin natural language
  2. LLMguided by the ontology
  3. QuerySPARQL on the graph
  4. Graphfacts and resources
  5. Answerwritten and sourced
The journey of a question in Graph RAG

Why an LLM alone is not enough

An LLM writes well, but:

  • it does not know your organisation’s data,
  • its knowledge stops at the date of its training,
  • it can produce a plausible but wrong answer, without citing its sources.

From RAG to Graph RAG

RAG (Retrieval Augmented Generation) means giving the model, along with the question, pieces of information retrieved from a database. In its most common form, it retrieves passages of text that are close to the question.

This approach reaches its limits when the answer requires linking several pieces of information, counting, comparing or respecting precise business definitions.

With Graph RAG, the model queries a knowledge graph: it follows the named relations between resources and retrieves precise facts rather than text excerpts.

How it works

  1. the user asks a question in natural language,
  2. the LLM, guided by the ontology, identifies the resources involved and writes a query on the graph, for example in SPARQL,
  3. the graph returns the facts and resources that answer the query,
  4. the LLM writes the answer from these facts, citing the resources used.

The graph can be combined with a search in texts: the graph provides the facts and context, the documents provide the detail.

An example

Let us take the music graph from the other pages and ask the question: “Which songs performed by Beyoncé were released before 2005?”

  • the LLM finds in the ontology the class “musical work” and the properties “is performed by” and “was released on”,
  • it writes the SPARQL query expressing these constraints,
  • the graph returns “Dangerously in Love”, released on 17 June 2003,
  • the LLM writes the answer, citing this resource.

This is the principle of the music discovery application built on the DOREMUS ontology: an agent writes its own SPARQL queries on a graph of 5 million triples.

The strengths of Graph RAG

  • answers based on the organisation’s data, up to date,
  • traceable answers: each fact points to an identified resource in the graph,
  • the ability to answer questions that link several pieces of information,
  • respect for business vocabulary thanks to the ontology and controlled vocabularies.

The LLM serving the graph

The relationship works both ways. LLMs make it easier to populate the graph by extracting knowledge from texts, according to the ontology. They also help design and maintain ontologies and controlled vocabularies.

SHACL validation rules make it possible to check what the model proposes before adding it to the graph.

The ontology, key to quality

The more formal the specification given to a model, the more effective it is. The ontology and its modelling notes, provided to the model, tell it what the graph contains and how to query it.