Source: "Knowledge graph construction with Claude", Claude Cookbook, published 2026-03-23. What follows covers the whole guide page, including its printed evaluation output. Notebook: capabilities/knowledge_graph/guide.ipynb in anthropics/claude-cookbooks.
What it actually is
A runnable tutorial that builds a knowledge graph from unstructured text with two model calls per concern: extraction on a cheap model, everything downstream on a mid-tier one. It runs entirely in memory on NetworkX, with no database, and the guide says the techniques carry over to Neo4j, Neptune or Postgres.
The corpus is six Wikipedia REST API summaries — Apollo program, Apollo 11, Neil Armstrong, Saturn V, Buzz Aldrin, Kennedy Space Center — not six articles. That matters for reading the numbers below.
The pipeline, in the guide's own order:
Entity and relation extraction — one structured-output call per document on
claude-haiku-5-5,max_tokens=4096, returning a typedExtractedGraph.Entity resolution — one call per entity type on
claude-sonnet-5-5, returning clusters of{canonical, aliases}.Graph assembly — a NetworkX
MultiDiGraph.Entity summarization — a profile for the top three hub nodes by degree.
Querying — a two-hop subgraph serialized to triple lines, answered with a grounded prompt.
Evaluation — precision and recall against a small hand-labelled gold set.
The number that reframes everything
The guide prints its own evaluation, and it is not flattering:
| Gold article | Raw F1 | Precision | Recall | Recall after resolution |
|---|---|---|---|---|
| Apollo 11 | 0.78 | 1.00 | 0.64 | 0.64 |
| Neil Armstrong | 0.55 | 1.00 | 0.38 | 0.38 |
Precision is perfect. Recall is 0.38 to 0.64. The entities it missed are named in the output and they are not obscure: for Apollo 11, columbia, kennedy space center, lunar module eagle, saturn v; for Neil Armstrong, gemini 8, korean war, nasa, purdue university, united states navy.
So the extraction is conservative, not comprehensive. What it puts in the graph is right; between a third and two thirds of what should be there is absent. Resolution does not recover any of it — recall is identical before and after.
This is the single most important thing to carry away, because it inverts the usual pitch. A graph built this way is a reasonable substrate for answering from what it contains. It is not an index of your documents, and any workflow that treats a missing edge as evidence of absence will be confidently wrong. If you need a question like "is there anything linking X and Y" to be trustworthy, this pipeline cannot answer it, and the guide's own numbers say so.
Two caveats on the measurement itself, both from the guide: the gold set covers two articles and its size is not stated, and relation scoring ignores the predicate, which makes relation recall an upper bound.
The data model, and where provenance leaks
Entity types are a closed set of five: PERSON, ORGANIZATION, LOCATION, EVENT, ARTIFACT. Raw extraction emits {name, type, description, source_doc} for entities and {source, predicate, target, source_doc} for relations.
Assembled nodes carry type, description, source_docs (sorted unique document titles), and mentions (a count). Edges carry predicate and source_doc.
Three provenance weaknesses are visible in that schema, and they compound:
Provenance is a document title string, not an ID. Rename or re-ingest a document and the link is a dangling string.
An edge keeps exactly one
source_doc. If three documents independently assert the same relation, the graph records one of them and silently discards the corroboration — which is precisely the signal you would want for ranking or for conflict detection.Only the first mention's description survives. Later, richer descriptions of the same entity are dropped.
There is also a gap between what the guide claims and what the code does. The query step serializes a subgraph as ({s}) --[{predicate}]--> ({t}) lines, and the prompt asks the model to "cite the specific edges that support your answer." But the serialized triples do not include source_doc, so the model can only cite edges, never documents. The guide's summary nonetheless says every claim cites an edge extracted from a specific document. The first half is true; the second is not reachable from the text the model is given. If you want document-level citation — and that is usually the entire point — you must add the source field to the serialization yourself.
Entity resolution: the right call, with a silent failure
Resolution is done by the model over the extraction descriptions, and string similarity is explicitly rejected — the guide's example is "Edwin Aldrin" against "Buzz Aldrin", which no edit distance will merge. The prompt tells the model to use descriptions "to avoid merging entities that merely share a name" and to pick the most complete, unambiguous canonical form. Observed output: Apollo program (also: Apollo), Buzz Aldrin (also: Edwin Aldrin). On the sample run, 40 raw entities and 44 raw relations over 23 unique names resolved to 21 canonical entities, giving a 21-node, 44-edge graph in one weakly connected component.
That design is correct and worth copying. Its failure mode is not.
There is no confidence score and no threshold anywhere in the resolution step. The output is clusters, full stop. And the guide names the consequence itself: a name the model omits from every cluster "silently disappears from the graph." The recommended fix is to fall back to a single-element cluster for any unclustered name — but the notebook code only falls back to singletons when the whole API call fails, not when an individual name goes missing. So the mitigation is described and not implemented, and the defect it guards against is invisible by construction: nothing in the graph records that an entity was dropped.
If you build on this, that reconciliation is the first thing to write: assert that the set of names going in equals the set of names appearing across all clusters, and fail loudly when it doesn't. It is three lines, and without it your graph's recall degrades for reasons you cannot see.
The guide also flags the opposite error, over-merging, with "Gemini 12" into "Project Gemini" — noted as a risk, not observed in the run. Resolution runs per entity type, so nothing can merge across types.
Scaling, as the guide frames it
The honest line is "feeding ten thousand PERSON entities to Claude in one prompt doesn't work." The prescription is to block first — group candidates by cheap signals such as shared surname, overlapping tokens or embedding similarity — and then run the same resolution prompt unchanged on blocks of 50 to 100. Incremental ingestion resolves new entities against the existing canonical set rather than re-resolving everything.
This is the shape worth remembering: the expensive, high-quality judgement is applied inside cheap, mechanically-produced candidate sets. The model never sees the quadratic problem.
Storage guidance: NetworkX is fine to a few hundred thousand edges. The suggested production schema is three tables — entities(id, name, type, summary), relations(source_id, target_id, predicate), aliases(entity_id, alias) — which notably introduces the entity IDs the in-memory version lacks.
On cost, the guide points to the Message Batches API for 50% off jobs that can wait up to 24 hours and recommends prompt caching, with no savings figure. No token counts and no dollar figures appear anywhere, so the economics are unmeasured.
Profiles and querying
The top three hub nodes by degree (Apollo 11 at 12, Apollo program at 11, Kennedy Space Center at 9; then Moon at 7, NASA at 6) get an EntityProfile with a summary, 3–5 atomic key facts and a time_range. The profile prompt is fed the full source excerpts plus the node's in and out relations, and is told "do not invent facts not supported by the excerpts."
Querying serializes a two-hop neighbourhood and answers with "answer using only the knowledge graph below." The guide shows an ungrounded answer beside a grounded one, with the grounded version citing (Buzz Aldrin) --[walked on]--> (Moon) and (Apollo 11) --[landed on]--> (Moon).
Note what the hub-based profile step implies: profiles exist only for the highest-degree nodes, and degree is a function of what extraction happened to catch. With recall at 0.38 on one of the two gold articles, the hub ranking is itself a sample, not a census.
Review checklist, if you are building on this
Reconcile resolution input against output. Every input name must appear in exactly one cluster; fail the run when it doesn't. The guide tells you to; the code doesn't.
Put
source_docin the serialized triples before claiming document-level citation.Give entities IDs and edges a list of sources, not a single title string, if corroboration or conflict matters to you.
Measure recall on your own corpus, on full documents. The published figures come from six short summaries and a two-article gold set.
Never read a missing edge as a negative finding. State that limit wherever the graph's answers are surfaced.
Block before you resolve. The prompt is unchanged; only the candidate sets shrink.
Keep the cheap/expensive split. Extraction on the small model with perfect precision is the part that worked.
Related reading
The recall ceiling here is the mirror image of the usual graph-retrieval failure, which is noise rather than omission. Approaches that avoid model calls at index time trade differently; so do systems that make the graph's own uncertainty explicit, or that put a checker between retrieval and the answer. Worth reading this guide against those rather than on its own — its value is as a precise, honest baseline, and its evaluation section is more useful than its pipeline.