AntflyAntfly
Back to Workshops
Workshop

Building Knowledge Graphs

From a pile of documents to entities and relationships you can query, computed on your own machine

Length
2 hours
For
Anyone who has wanted to use the relationships in their data to answer questions that span documents. No graph database experience needed
Open the deck

Arrow keys advance. P shows the notes. Esc comes back here.

  1. 01
    Dot draws a connection on a knowledge graph beside the title Building Knowledge Graphs and the Antfly lockup

    antfly.io/events/building-knowledge-graphs

  2. 02

    What we cover

    • Extracting entities and relationships from documents with a local model
    • Storing relationships alongside the source documents themselves
    • Querying across the graph and the text in one request
  3. 03

    Contents

    1. Why Graphs
    2. From Documents to a Graph
    3. Why Not Just Ask an Agent?
  4. 04

    Why Graphs

  5. 05

    AI search engines for science

    The essay AI Search Engines for Science: the Good, the Bad, and the Ugly
    • Often irrelevant results
    • Pretty slow
    • Bad precision
  6. 06

    We take our agents having access to web-scale data as a given

    An agent answering which bird would win a bracket tournament against all other birds, citing scientific literature
  7. 07

    The OG web-scale graph: PageRank

    "Everyone links to Website B, so it must be important."

    "Website B links to Website C, so it probably is as well."

    PageRank example: circles sized by score, with B and C largest because many pages link to them
  8. 08

    From Documents to a Graph

  9. 09

    But what if you just have a pile of documents?

    Three overlapping plain-text Wikipedia articles about A Song of Ice and Fire characters
  10. 10
    The workshop's graph search page: Tyrion Lannister's connections, with the source passages for each
  11. 11

    Try it yourself

    Ask your agent:

    Or do it yourself:

    terminal
    git clone https://github.com/antflydb/knowledge-graphs-workshop
    cd knowledge-graphs-workshop
    make up          # → http://127.0.0.1:8000   (Ctrl-C stops everything)
    

    Prerequisites: uv and Antfly v0.3.0-rc.1 on your PATH (set ANTFLY_BIN if an older antfly is installed).

    The first run pulls GLiNER2.5 and EmbeddingGemma (~2 GB) and the prebuilt database (~350 MB); after that it starts in seconds.

    QR code for antfly.io/learn/workshops/building-knowledge-graphs
  12. 12
    The Text to graph tab: sentences on the left, the graph extracted from them on the right
  13. 13

    Entity extraction from text

    Entity typesRelationship vocabulary
    characterparent_of
    housemember_of
    kingdomrules
    citylocated_in
    Entity extraction from text Eddard, a character, rules Winterfell, typed as a kingdom. Winterfell, typed as a city, is located in the North, a kingdom. Eddard Winterfell Winterfell North character kingdom city kingdom rules located_in
  14. 14
    Graph search for Jon Snow: his relationships fanned out around him, with evidence passages on the right
  15. 15

    Entity resolving

    Arnold S. and Schwarzenegger resolve to the same entity, who was Governor of California and starred in Predator
  16. 16

    Pass through a decision model

    Try to weed out weak or untrue relations.

    Ordered pairSaved decision
    Eddard "Ned" Stark → Winterfellrules0.575
    "is the Lord of Winterfell"no_relation0.241
    unclear0.184
  17. 17

    Change the config and rerun

    The ASoIaF config.yaml: entity types and relation definitions with head and tail types
    More of config.yaml: member_of, rules and located_in, and the relation decision instruction
  18. 18

    Things to try

    Search the ASoIaF graph:

    • Why does Tyrion kill Tywin?
    • Jon Snow mother
    • Dorne

    Then pick one relationship:

    1. Open its supporting passage.
    2. Does the passage support the relationship's type and direction?
    3. Change one choice in config.yaml, rebuild, and compare.
  19. 19

    Why Not Just Ask an Agent?

  20. 20
    Claude Code with the prompt: please make me a knowledge graph of all the characters in here. make no mistakes
  21. 21
    Claude Code planning: 56 Wikipedia articles, a config of relationship types, chunks for parallel extraction
  22. 22
    Claude Code running 18 extraction subagents in parallel
  23. 23
    Citadel Ledger, the character graph Claude built: 708 characters and 3,643 relations, with Jon Snow selected
  24. 24

    What Claude did

    • Used a bunch of knowledge outside the text corpus
    • Used 18 subagents and $62 of API credits
    • Merged entities "by hand"
    • Its agents used varying conventions

    Agents can totally build knowledge graphs, but you should give them the right tools to do it.

  25. 25

    Why not just ask an agent?

    • Keep data on-prem
    • More reproducible, scalable, and deterministic
    • Control terminology
    • Run it yourself, own it yourself
    • An agent won't know your data. Hallucinations are definitely still a thing
  26. 26

    Why else? Enterprise

    Each of our systems is internally coherent and externally isolated. Atlas, our telemetry platform, knows applications and their time series. Radar, our alerting system, knows thresholds and firing history. incident.io knows severities and responders. PagerDuty knows rotations. Spinnaker knows what shipped and when. And our Slack history knows, in a form no query engine can reach, which engineer solved something very similar last quarter and what they found.

    The difficulty is that they do not agree on what they are talking about.

    Ontology-Driven Observability: Building an End-to-End Knowledge Graph at Netflix Scale netflixtechblog.com

  27. 27

    Other tools

    ToolWhat it's for
    GraphitiReal-time knowledge graphs for agent memory
    GraphRAGGraph-based retrieval-augmented generation, from Microsoft
    LightRAGSimple, fast graph-based RAG
    LLM Graph BuilderNeo4j graphs from unstructured documents
    CogneeOpen-source memory platform for agents
    Mem0A memory layer for agents and apps
  28. 28

    Apollo 13

    The Apollo 13 dataset in the workshop's graph search: the air-to-ground transcript on the left, one message's entities as a graph in the middle, and Review Board passages that share them on the right
  29. 29

Events