Data Stories

Knowledge graphs · RAG · a worked example

Beyond Chunks: How Knowledge Graphs Answer What Documents Can't

Explained with a working knowledge graph of about 3000 Telugu films

What a knowledge graph is, where the idea came from, why it makes retrieval-augmented generation better at some questions and no better at others — and a complete one, built from Wikipedia's lists of Tollywood films from 2000 to 2025, so you can see every step and every number.

Part 1The idea

What a knowledge graph is, where it came from, and what LLMs changed about building one.

1. What is a knowledge graph?

A knowledge graph stores things, and the relationships between them, as data you can query. The things are called nodes: a film, a person, a company, a genre. The relationships are edges, and every edge has a type: DIRECTED,ACTED_IN, COMPOSED. One edge is one fact:

S. S. Rajamouli —DIRECTED→ Magadheera

That three-part shape — subject, relationship, object — is called a triple, and it's the atom of every knowledge graph. Here is the same information in the three shapes data usually comes in:

As a table rowtitleMagadheerayear2009directorS. S. RajamoulimusicM. M. KeeravaniAs a sentence“Magadheera is a 2009 Telugu fantasy action film directed byS. S. Rajamouli, with music composed by M. M. Keeravani.”As a graphMagadheeraS. S. RajamouliM. M. KeeravaniDIRECTEDCOMPOSED
The same facts as a table row, a sentence, and a graph. The table needs you to know which column means what; the sentence needs reading; the graph states each relationship explicitly, with its type.

Each shape has a strength. A table is perfect when every record has the same fields. A sentence carries nuance and context. A graph wins when the interesting part is how things connect — because the connections are first-class data, not something you reconstruct by joining tables or reading between the lines.

Edges carry details too

In the graph built here, an ACTED_IN edge records the actor's billing position (1 for the lead), and every edge records which source asserted it (wikipedia, wikidata, or both). That's the property graph model: nodes and edges are both little records with fields.

Zoom out from one film and you see a neighbourhood. This is Magadheera's:

ChiranjeeviACTED_INKajal AggarwalACTED_INRam CharanACTED_INM. M. KeeravaniCOMPOSEDS. S. RajamouliDIRECTEDAllu AravindPRODUCEDB. V. S. N. PrasadPRODUCEDS. S. RajamouliWROTEV. Vijayendra PrasadWROTEGeetha ArtsCREDITED_COMPANYNetflixCREDITED_COMPANYromanceHAS_GENREactionHAS_GENREfantasyHAS_GENREmusicalHAS_GENREmelodramaHAS_GENREMagadheerafilmpersoncompanygenre
Magadheera (2009) and its crew, top-billed cast, Chiranjeevi's cameo, companies and genres. Hover a spoke to see the triple it stands for.

A knowledge graph is millions of these neighbourhoods stitched together, because the same M. M. Keeravani node that appears here also hangs off every other film he scored. That shared node is the whole trick: walk from one film to its composer and on to all of his other films, and yo're following connections no single document lists.

The schema: the kinds of things and relationships

Every graph has a schema (sometimes called an ontology): the list of node types and edge types it allows. This one is small: five kinds of node (Film, Person, Company, Genre, Community) and about ten kinds of relationship. Small and explicit is good. when nobody defines the relationships in advance, they multiply until nobody can query them.

In one line: a knowledge graph is data about things and their typed relationships, so that the relationships can be searched, counted and followed.

2. Where it came from, before LLMs

Knowledge graphs are about sixty years older. The term became popular in 2012, but the idea — represent knowledge as things joined by labelled links — goes back to the earliest days of artificial intelligence.

1960sSemantic networksConcepts as nodes, meaning as labelled links1976The entity–relationship modelPeter Chen: data is entities and relationships1984CycCommon sense, encoded by hand, for decades1999RDFThe W3C standardises the triple2001The Semantic WebA web of data machines can read2007DBpedia and FreebaseGraphs built from Wikipedia and the crowd2010Property-graph databasesNeo4j 1.0; Cypher follows2012Google's Knowledge Graph“Things, not strings”2012WikidataOne open ID for every thing2022→Large language modelsExtraction, linking and querying become prompts2024GQL and GraphRAGAn ISO graph query standard; graphs for RAG
A short history. Blue: the pre-LLM era. Orange: what LLMs added. Hover an event for detail; sources are listed at the end of the article. This timeline is the one part of the article not generated from the data.

The AI years: networks of meaning

In the 1960s, researchers modelling human memory drew concepts as nodes and meanings as labelled links — a canary IS-A bird, a bird HAS wings. These semantic networks are recognisably knowledge graphs. A decade later, Peter Chen's entity–relationship model gave database designers the same vocabulary for business data. And from 1984 the Cyc project tried to hand-write all of common sense as logical facts — an effort that taught everyone how expensive it is to build knowledge by hand.

The web years: a web of data

Around 2000, the idea moved to the web. The W3C standardised the triple as RDF, and Tim Berners-Lee and colleagues described a Semantic Web in which pages would carry data machines could read, not just text for people. The full vision never arrived, but its building blocks did: shared IDs for things, and triples as a common format. In 2007 DBpedia started pulling structured data out of Wikipedia's infoboxes, and Freebase built a crowd-edited graph of things.

The industry years: things, not strings

In 2012 Google announced its Knowledge Graph with a phrase that stuck:

“Things, not strings.”

A search for a film stopped being just a list of pages that contain its name. It became an entity, with a director, a cast and a release date shown right on the results page. The same year, Wikimedia launched Wikidata, a free knowledge graph that gives every thing a stable ID. (Those IDs are how this project knows that “NTR Jr” and “N. T. Rama Rao Jr.” are the same person — more on that in Part 3.) Meanwhile graph databases such as Neo4j made it practical to store and query graphs with ordinary engineering tools, and the Cypher query language used throughout this article grew out of that world.

Why organisations built them

Long before anyone paired them with language models, knowledge graphs earned their keep in a handful of jobs:

The hard part was always the same: getting knowledge into the graph. Either someone mapped existing databases into it, carefully, or someone wrote rules and trained models to pull facts out of text, expensively. That bottleneck is exactly what large language models changed — but before that, it helps to see the two routes clearly.

In one line: knowledge graphs predate LLMs by decades; they were built for search, integration, recommendations, fraud and science, and the hard part was always filling them.

3. What LLMs changed

Large language models made the expensive part of knowledge graphs — reading text into facts — cheap.

TaskBefore LLMsWith LLMs
Find the entities in textNamed-entity models trained per domain, on labelled examplesAsk for them in a prompt
Extract relationshipsHand-written patterns, or a relation classifier per relationship typeOne call with a schema: “return credits with role ∈ {director, writer, …}”
Write the queryAn engineer, or a fixed query templateGenerated from the question (text-to-Cypher)
Cost to startWeeks of annotation and tuningAn afternoon and a few dollars

LLMs made extraction cheap. They did not make it correct, and they did not make identity easy.

What didn't change: knowing who is who

The hardest step in building a knowledge graph was never extraction. It's entity resolution: deciding that two mentions are the same thing, and that two similar mentions are not. Telugu cinema makes this vivid:

An LLM can help with each of these, but it can also confidently get them wrong. What works best is boring: stable IDs, explicit rules for when two records are the same, and validation that refuses to continue when the numbers look wrong.

In one line: LLMs turned extraction into a prompt; identity, validation and schema design are still engineering work.

5. What kind of data suits a graph

A graph pays off when your questions are about connections. A useful test: read your users' real questions and count how many contain words like with, between, linked to, depends on, most, how many, who else*. Those are graph questions.

Films are a textbook case: a small number of entity types (films, people, companies) joined by a large number of relationships. Many serious domains have the same shape.

DomainThings (nodes)Relationships (edges)A question a graph answers easily
Films (this article)films, people, companies, genresDIRECTED, ACTED_IN, COMPOSED, CREDITED_COMPANYWhich director and music director have made the most films together?
Lawcases, statutes, judges, courtsCITES, INTERPRETS, OVERRULES, DECIDED_BYWhich current rulings rest on a precedent that was later overruled?
Pharma and biomedicinedrugs, protein targets, diseases, trials, adverse eventsTARGETS, ASSOCIATED_WITH, TESTED_IN, CAUSESWhich approved drugs hit a target linked to this disease but were never trialled for it?
Finance and fraudaccounts, devices, addresses, phones, paymentsUSES, LIVES_AT, PAIDWhich new accounts share a device or address with accounts already flagged?
Enterprise knowledgepeople, teams, systems, documents, ticketsOWNS, DEPENDS_ON, DOCUMENTS, RAISED_BYIf this service fails, which teams, systems and runbooks are affected?
Supply chainsuppliers, parts, products, factories, regionsSUPPLIES, USED_IN, LOCATED_INWhich products depend, two tiers down, on one supplier in one region?

A few sketches of how that plays out:

When a graph isn't worth it

If your questions are answered by a passage of text (“explain our refund policy”), use document search. If they're about one table (“total sales by month”), use SQL. If your relationships are few and rarely change, a couple of database joins will do. A graph earns its cost when relationships are many, varied, and the actual subject of the questions.

In one line: use a graph when the questions are about how things connect — credits, citations, targets, dependencies — not when the answer is a paragraph or a single table.

Part 2Why it helps retrieval

What a graph adds to retrieval-augmented generation, and what it doesn't.

1. How a graph helps retrieval

Retrieval-augmented generation (RAG) means: before the model answers, fetch some relevant material and put it in front of it. The model then answers from that material instead of from memory. The usual way to fetch is to split documents into chunks and find the chunks most similar to the question — by shared keywords, or by meaning (vector search).

That works beautifully when the answer is written down in a chunk. Whether it is depends on the shape of the question:

Question shapeExample from this corpusWhat answering it requires
LookupWho directed Magadheera, and who scored it?One fact about one named thing
RelationshipWhat roles did Pawan Kalyan hold on Johnny (2003)?Several typed links between two named things
PathHow many films apart are Vijay Deverakonda and Chiranjeevi?A chain through nodes nobody named
AggregateWhich director and music director made the most films together?Count and rank across everything
DescriptiveWhich film is about a man reincarnated as a housefly?Match a description; no name to look up

Lookups and relationships are often written somewhere. Paths and aggregates almost never are — the answer is spread across thousands of records. Descriptive questions are the reverse: no name to look up, just a description to match.

Three ways to retrieve from a graph

  1. Walk the neighbourhood. Find the people and films named in the question, collect every fact within two hops, and hand those facts to the model. Precise, but only as good as the step that matches names in the question to nodes in the graph.
  2. Write a query. Show the model the graph's schema and let it write a database query , run it safely read-only, and answer from the rows. This is the only approach that can compute an answer: count, rank, find a path.
  3. Summarise communities (the “GraphRAG” pattern). Cluster the graph into groups of closely connected nodes, have a model write a summary of each group in advance, then answer from the summaries. Built for broad questions about themes.

In one line: ordinary RAG finds text that looks like the question; a graph can also follow relationships and compute answers that no text contains.

2. Where it improves RAG answers, and where it doesn't

A graph doesn't make every answer better. It makes specific kinds of answer possible, and others more trustworthy.

And where it might not:

The graph doesn't replace document search. It answers the questions document search can't, and the best systems route each question to the right one.

In one line: graphs add computed answers, typed facts, long-tail coverage and provenance; they add nothing for questions that describe content instead of naming it.

Part 3Building one: the Tollywood graph

Every step, from Wikipedia pages to a queryable graph, with what went wrong at each.

1. The Seven steps of building and using a graph

Every knowledge-graph project, whatever the domain, runs roughly the same pipeline. Here it is for this one, with what each step produced:

1Source26 list pages + articles2Parse2,853 film rows3Identify3,904 Wikidata IDs4Resolve6,061 distinct people5Load10,714 nodes in Kuzu6Indexfull-text + communities7QueryCypher, five ways
external datacodelanguage modelgraph database
The pipeline. Each step writes a file you can open and inspect, so when something goes wrong you can see where. Only two steps use a language model.

Here's what each step does — and, because this is where projects actually go wrong, what went wrong at each one here.

1. Source: decide what the graph is of

The corpus is Wikipedia's List of Telugu films of 2000 through 2025: 2,000+ film articles for the plot, the lead paragraph, and the budget and box office from the information box.

2. Parse: turn pages into records

Each year page has tables of releases, month, day, title, director, cast, production company etc. Turning those into clean records sounds trivial but it isn't. The layout changes from year to year, and each change has to be understood and coded for.

3. Identify: give every thing an ID

Every film, person and company that Wikipedia links has to be identified & given an ID. Looking those up turned names into identities: 2,006 films, 1,791 people and 107 companies resolved. This is the single most valuable step in the pipeline, because from here on, “are these the same person?” is a comparison of two IDs, not a guess about two spellings.

4. Resolve: decide who is who

Each credited person is matched by the strongest evidence available: their own Wikidata ID, a name match within the same film, or a name that is unique across the whole corpus. Anyone else stays a separate node rather than being merged on a guess.

5. Load: one fact, one edge

Everything goes into Kuzu, an embedded graph database (a single file, no server).

6. Index: make it searchable

A full-text index over titles and plots powers keyword search. A community-detection algorithm (Louvain) groups actors who often work together into 78 clusters, and a model writes a short summary of each, for the GraphRAG-style method.

7. Query: answer questions

Finally, questions go in and answers come out . Text-to-Cypher produced a runnable query for 19 of 19 questions; when the first attempt failed, the database's error message was fed back and the model fixed its own query.

In one line: source, parse, identify, resolve, load, index, query — and validate at every step, because the worst errors don't crash.

8. Where the data comes from

Three free sources, used for three different jobs.

  1. Wikipedia's year lists — the spine. 26 pages, each listing a year's Telugu releases with release date, director, cast and production company, plus a top-ten box-office table (198 box-office rows in all). Snapshotted 2026-11-07.
  2. Wikidata — the IDs, plus genre, music director, writer, producer and IMDb ID.
  3. Each film's Wikipedia article — 2,004 articles, for the plot summary (searched by keyword search, read by the language model) and infobox budgets.
20002002200420062008201020122014201620182020202220242025248
Films per year in the graph. 2024 is the peak with 248 films; 2020 is the pandemic dip. The rise after it is real — streaming premieres and small independents now make the lists.

9. The graph

Here's what came out: 10,714 nodes and 63,224 relationships, in a single 56 MB database file.

Person6,061 nodes Film2,846 nodes Company1,657 nodes Genre72 nodes Community78 clusters DIRECTED 3,011 WROTE · PRODUCED · COMPOSED ACTED_IN 14,601 {billing} CREDITED_COMPANY HAS_GENRE IN_COMMUNITY COSTARRED_WITH 35,854 (derived)
The schema, with live counts. COSTARRED_WITH links two actors who share a film (top-billed cast only) and exists to find communities. LLM_ASSERTS holds the model's actor-to-character readings, kept apart from the curated credits.

Explore it

Below are two views of the graph you can play with. Sample is the box-office top ten of each year, topped up to fifteen films a year, with their directors and leading actors. Full graph is every film, person, company, genre and community, and every relationship between them. Click a node to see its neighbourhood — exactly what the neighbourhood-walk method hands the model. Connect two names to find the shortest chain of credits between them.

Esc to exit
Click any node to see its neighbourhood, or connect two names to find the shortest chain between them. Drag to pan, scroll to zoom.
film person director (ringed) DIRECTED 412 ACTED_IN 1,134 size = connections in this view

Showing 15 films per year (390 films): each year's box-office top ten (198 films), with the remaining slots filled by the films whose top 3 billed actors appear in the most corpus films; plus their credited directors and top 3 billed cast: 1,021 nodes and 1,546 edges. The full graph has 10,714 nodes and 63,224 relationships, all drawn in the Full graph tab; this is a sample chosen by a stated rule, not a summary. Use expand for a full-screen canvas with the details panel alongside.

What the graph knows that no page says

Each of these took one short query.

Puri Jagannadh126Anil Ravipudi109Trivikram Srinivas105Srinu Vaitla102K. S. Ravindra99Boyapati Srinu90Koratala Siva90S. S. Rajamouli88
Who has worked with the most actors? Distinct actors directed, 2000–2025. Puri Jagannadh leads on volume (33 films); Anil Ravipudi reaches 109 actors in just 8.
S. S. Rajamouli + M. M. Keeravani13Puri Jagannadh + Chakri10Sukumar + Devi Sri Prasad8Srinu Vaitla + Devi Sri Prasad7Ravi Babu + Shekar Chandra7K. Raghavendra Rao + M. M. Keeravani7B. Gopal + Mani Sharma6Teja + R. P. Patnaik6
The great partnerships. Director + music director pairs by films together. These are lower bounds: music credits come only from Wikidata.
Brahmanandam24Prakash Raj15Kota Srinivasa Rao10Ali9Chandra Mohan8Sunil8Dharmavarapu Subramanyam7M. S. Narayana7
Everyone's co-star. Ravi Teja has the most leading roles in the corpus; his most frequent co-star is Brahmanandam, who appears in 466 of the 2,846 films — about one in 6. A short comedy role and a lead are the same ACTED_IN edge, so he tops nearly everyone's list.
ACTED_INACTED_INACTED_INACTED_INVijay DeverakondaGeetha Govindam (2018)Nagendra BabuHands Up (2000)Chiranjeevi
Degrees of separation. Vijay Deverakonda and Chiranjeevi have never shared a film, but they are 2 films apart in the full graph. (The sample tab holds fewer films, so its path can be longer.)

Conclusions

Knowledge graphs aren't a replacement for RAG. They're the part of it that handles connections. Put together, the results make a simple routing table:

If the question is…UseEvidence here
Count, rank, compare, “most”, “how many”Graph + generated queryPuri Jagannadh, 126 actors — 7/8 aggregates right
A path between two thingsGraph + query, with exact IDsDeverakonda → Chiranjeevi; fuzzy names pick the wrong node
Who did what on a named thingGraph (walk or query)Pawan Kalyan on Johnny: writer, director, actor
Data the model has never seenAny retrieval; a graph if the answer is a relationshipSmall 2024–25 films
Described by content, not namedText search (vector, then keyword)Keyword search 4/4
Themes across a whole collectionCommunity summaries — if the collection has themes0/19 on one industry

Five things to take away

  1. A graph is for connections. If your users ask “who else”, “how many”, “linked to” and “depends on”, a graph answers what document search can't.
  2. Let the database do the arithmetic. A model writing a query and reading the result beats a model reading documents and trying to count.
  3. LLMs made graphs cheap to fill, not correct. Extraction cost cents; identity, validation and provenance still decide whether the answers can be trusted.
  4. Constrain the vocabulary. A fixed list of relationship types keeps a graph queryable; free-form extraction produced 201 relationship names, most used once.
  5. Route by question shape. Keep a text index beside the graph and send each question to the one that can answer it.

Sources for the history

Film data from Wikipedia (CC BY-SA 4.0) and Wikidata (CC0). Every figure about films, the graph and the evaluation is generated from the pipeline's own artifacts at build time.