Claude Cookbook guide to building knowledge graphs from unstructured text
Deconstruction
My note at capture · 2026-11-28
knowledge graph construction with claude
Source summary · machine-written at capture, not my interpretationShow
This is an official Claude Cookbook notebook that builds a knowledge graph from unstructured documents using only prompts. Its test corpus is six Wikipedia summaries about the Apollo program. Claude Haiku extracts typed entities and subject–predicate–object triples through structured outputs (Pydantic models with client.messages.parse). Claude Sonnet then merges entity variants, writes profiles for the hub nodes and answers multi-hop questions over serialized subgraphs held in an in-memory NetworkX MultiDiGraph. The guide ends with precision/recall scoring against a hand-labeled gold set and notes on scaling up.
- Each document gets one structured-output call that pulls out entities (PERSON, ORGANIZATION, LOCATION, EVENT, ARTIFACT) with a one-sentence description, plus relations. This replaces a trained NER model and a trained relation classifier.
- Entity resolution: per entity type, Sonnet sorts names into canonical names and aliases, using the descriptions to tell them apart. It catches 'Edwin Aldrin' = 'Buzz Aldrin', which string similarity misses.
- Failure modes it names: names left out of every cluster silently disappear (fix: fall back to a one-name cluster), and over-merging (e.g. 'Gemini 12' folded into 'Project Gemini').
- To answer questions, it serializes the 2-hop neighborhood as triples and tells Claude to answer only from the graph and cite edges. Answers become traceable and work on private data Claude has no prior knowledge of.
- Evaluation: precision/recall/F1 against gold triples, with an alias map. In the demo, precision was 1.0 and recall was 0.38–0.64.
- Scaling: prompt caching and the Batches API (50% off) for extraction; group candidates into blocks by cheap signals before resolution (50–100 per prompt); incremental updates against the existing canonical set.
- Storage maps to Neo4j or Neptune, or to three Postgres tables: entities, relations and aliases.
Encountered and saved. Saving is not endorsement.
Association
Suggested at capture. Proposed by my capture tool, not yet reviewed as my reasoning.
Next to it on a thought trajectory. An agent that learns from feedback needs a structured memory of what it has encountered. A knowledge graph built from unstructured text is one such memory: entities, typed relations and the reasons behind them. This site is that idea applied to its owner's own notes. Illustrative, not authored