L1
·
Quiz
·
Lab
L2
·
Quiz
·
Lab
L3
·
Quiz
·
Lab
L4
·
Quiz
·
Lab
Module Test
🎯 Advanced

Graphs vs. Vectors: The Structural Case

Why relational structure matters for agents — and where embedding-based retrieval hits a wall.

In 2022, Google's internal research team published benchmarks comparing their Knowledge Graph (which powers the Knowledge Panel in Search) against dense vector retrieval for multi-hop factual queries. On single-hop lookups — "Who directed Oppenheimer?" — vector search performed comparably. But on two-hop queries — "Who directed the film whose lead actor also starred in a 2019 Christopher Nolan film?" — the graph-backed system was 34 percentage points more accurate. The reason was structural: vector search finds semantically similar text, but a knowledge graph can traverse explicit relationships, following typed edges from film to director to actor to filmography without guessing.

This distinction — semantic similarity versus structural traversal — is the central tension agents must resolve when choosing a memory architecture.

How Knowledge Graphs Represent the World

A knowledge graph organizes information as a set of triples: subject → predicate → object. In RDF notation, a triple might read :Oppenheimer :directedBy :ChristopherNolan or :ChristopherNolan :bornIn :London. Every piece of knowledge is an explicit, typed, traversable relationship — not a paragraph of text compressed into a high-dimensional vector.

This structure gives agents two capabilities that vector stores cannot easily replicate. First, multi-hop reasoning: the agent can follow a chain of relationships — person → employer → subsidiary → parent company — without relying on whether that chain happened to appear together in training data or indexed documents. Second, constraint satisfaction: the agent can filter by relationship type, ensuring it is using a "founded" edge rather than a "mentioned in same article as" edge, which a cosine-similarity match might conflate.

Popular knowledge graphs in production include Wikidata (100+ million items, open), Google's Knowledge Graph (used in Search since 2012), and domain-specific graphs like the FDA's drug interaction graph and LinkedIn's Economic Graph, which models 950+ million members and their job relationships.

Key Distinction

Vector search answers: "What text is semantically similar to this query?" A knowledge graph answers: "What entities are connected by this specific typed relationship, and what else are those entities connected to?" These are fundamentally different questions.

Where Vector Search Falls Short for Agents

Vector retrieval excels at finding relevant passages when the agent needs context — "what does our documentation say about rate limits?" But agents doing structured reasoning encounter three failure modes that graphs solve directly.

Hallucinated relationships. When a language model must answer a relational question from embedded text, it often "fills in" missing hops with plausible-sounding but incorrect connections. In a 2023 study from Stanford's AI Lab on retrieval-augmented generation accuracy, models using only vector-retrieved context had a 41% error rate on questions requiring two or more reasoning hops, versus 12% when a structured graph was available for the intermediate steps.

Relationship ambiguity. The sentence "Apple acquired Beats" and "Apple acquired a taste for music hardware" may have similar embeddings. A graph stores :Apple :acquired :BeatsElectronics as a discrete, unambiguous fact. No similarity threshold confusion.

Temporal staleness detection. Graphs support versioned or time-stamped edges — :SatyaNadella :ceoOf :Microsoft {from: 2014}. A chunk of text saying "Satya Nadella is the CEO" has no machine-readable timestamp, making it harder for an agent to know if it's stale.

  • Multi-hop queries: graphs traverse; vectors guess
  • Relationship typing: graphs are explicit; vectors are probabilistic
  • Temporal reasoning: graphs can store validity intervals; documents cannot
  • Entity disambiguation: graphs use unique identifiers; text re-uses names
When to Reach for a Graph

The decision to use a knowledge graph is not ideological — it's architectural. Graphs add engineering overhead: schema design, ingestion pipelines, query languages (SPARQL, Cypher, Gremlin), and infrastructure (Neo4j, Amazon Neptune, Wikidata Query Service). The payoff is justified when the agent's tasks involve structured traversal over explicitly known entities and relationships.

Practical triggers: your agent needs to answer "how many hops" between two entities; your domain has a well-defined ontology (medical codes, legal citations, supply chain nodes); you need explainable, auditable reasoning paths; or you are building in a domain where hallucinated relationships carry real-world cost — healthcare, finance, legal.

When the task is "find relevant background information" or "summarize what we know about topic X," a vector store with well-chunked documents remains the right tool. Advanced agent architectures increasingly combine both: a graph for structured traversal plus a vector store for unstructured context retrieval, stitched together at query time.

Architecture Principle

Microsoft's Copilot for Microsoft 365 (launched 2023) uses both a vector index of user documents and Microsoft Graph (the entity graph of users, calendars, emails, and org structure) simultaneously. The graph handles "who reports to whom" and "what meetings did Alice attend with Bob," while the vector store handles semantic document retrieval. Neither alone would suffice.

🎯 Advanced

Lesson 1 Quiz

3 questions — free, untracked, retake anytime.
1. In a knowledge graph triple, what do the three parts represent?
✓ Correct — ✓ Correct! RDF triples encode knowledge as subject → predicate → object — for example, :Nolan :directedBy :London is wrong direction, but :Oppenheimer :directedBy :ChristopherNolan is a valid triple. This structure enables explicit, typed traversal.
✗ Not quite. Knowledge graph triples follow the RDF pattern: Subject → Predicate → Object. This allows every relationship to be explicitly typed and traversable.
2. According to Google's research cited in this lesson, on two-hop queries, graph-backed retrieval outperformed vector search by approximately how many percentage points?
✓ Correct — ✓ Correct! Google's 2022 benchmarks showed a 34 percentage point accuracy advantage for graph-backed retrieval on multi-hop queries. The gap widens as reasoning requires more relational hops.
✗ The lesson cites 34 percentage points. On single-hop queries the systems were comparable; the structural advantage of graphs compounds as queries require multiple traversal steps.
3. Which of the following is a legitimate advantage of knowledge graphs over vector stores for agent memory?
✓ Correct — ✓ Correct! Graphs support validity intervals on edges — e.g., {from: 2014} on a CEO relationship — allowing agents to reason about whether a fact is currently true. This is extremely difficult with unstructured text chunks.
✗ The correct answer is time-stamped edges. Graphs do require schema work; vector stores handle semantic similarity; and graphs are not about compression — they explicitly store typed relationships for traversal and temporal reasoning.
🎯 Advanced

Lab 1: Graph vs. Vector Decision Analysis

Practice identifying which retrieval architecture fits a given agent task.

Your Task

You'll work with an AI tutor to analyze real retrieval architecture decisions. The tutor will present you with agent task descriptions and push you to justify whether a knowledge graph, vector store, or hybrid approach is appropriate — and why.

Starter: Ask the tutor to give you a concrete agent task scenario and walk through the graph-vs-vector decision together. Push past surface answers — dig into the specific query types and relationship structures involved.
🧪 Lab 1 — Graph vs. Vector Decision Analysis AI Tutor
🎯 Advanced

Graph Schema Design for Agent Use Cases

Ontologies, entity types, and relationship modeling that makes agents actually useful.

When NASA's Jet Propulsion Laboratory built its Knowledge Representation System for mission planning in the 2010s, the team spent more time on ontology design than on the inference engine itself. The schema had to encode spacecraft components, subsystem dependencies, operational constraints, and temporal windows — all as typed relationships. A poorly typed edge (treating "operationally depends on" the same as "physically contains") caused mission planners' queries to return nonsensical results. The lesson was direct: for an agent to reason correctly over a graph, the schema must distinguish semantically distinct relationship types, even when they look superficially similar.

Ontology Fundamentals: Classes, Properties, Instances

A graph schema — formally called an ontology — defines the vocabulary the graph uses. It specifies three things: classes (the types of entities that can exist, e.g., Person, Organization, Drug, Event), properties (the types of relationships that can hold between entities, e.g., employs, inhibits, succeeded), and instances (the actual entities and their connections, e.g., :Pfizer :manufactures :Paxlovid).

The OWL (Web Ontology Language) standard, maintained by the W3C, provides formal axioms — cardinality constraints, inverse relationships, transitivity declarations. A transitivity declaration on subOrganizationOf means an agent can automatically infer that if A is a sub-org of B, and B is a sub-org of C, then A is a sub-org of C — without storing that triple explicitly. This inferential power is unique to formal ontologies and unavailable in flat embedding spaces.

For practical agent deployments, you rarely need full OWL expressivity. A lightweight "graph schema" in Neo4j or Amazon Neptune — defining node labels, relationship types, and property keys — gives most of the structural benefit at a fraction of the complexity.

Schema Design Principle

Every relationship type in your schema should answer a question an agent will actually ask. If no agent task requires distinguishing :mentions from :cites, merge them. Over-granular schemas increase ingestion cost without improving query quality. Schema design is task-driven, not encyclopedic.

Modeling Patterns for Common Agent Tasks

Hierarchical containment. Supply chains, organizational charts, file systems, and taxonomies all share a containment pattern: a parent node has children via a typed edge (e.g., :contains, :reportsTo). Agents can traverse upward to find ultimate parents ("what company ultimately owns this vendor?") or downward to find all descendants ("list every team under this VP"). This is a graph operation called tree traversal — trivial in Cypher, awkward in SQL, and unreliable in vector retrieval.

Event and timeline modeling. LinkedIn's Economic Graph models job transitions as :Person -[:HELD_ROLE {start: "2018", end: "2021"}]-> :Role -[:AT]-> :Company. This allows temporal queries like "who held this role between 2019 and 2021?" — queries that require both relationship type and property filtering simultaneously. Representing this in a vector store would require encoding temporal metadata in chunk text, hoping the retriever surfaces it, and then parsing it out — a fragile chain.

Multi-relational entity modeling. A person entity in a healthcare knowledge graph might have relationships of type :diagnosedWith, :prescribedDrug, :attendedBy, and :admittedTo. An agent asking "which patients on Drug X were also diagnosed with Condition Y and admitted to Hospital Z in 2023?" can express this as a single Cypher pattern match — a graph query — rather than issuing multiple vector searches and performing set intersection in application code.

  • Hierarchical containment: traverse parent/child trees efficiently
  • Temporal modeling: time-stamped edges enable historical queries
  • Multi-relational filtering: combine relationship types in one query
  • Inverse relationships: if A employs B, graph can infer B works for A
Schema Evolution and Agent Stability

One underappreciated challenge: graphs must evolve as the domain changes, and those changes can break agent queries. In 2020, the Wikidata team added a new relationship type :P9149 (OpenAlex ID) as an identifier property. Agents that had been trained to traverse :P356 (DOI) for academic paper lookup needed updates to also consider the new property. Schema versioning — tagging edges with a since property and deprecating rather than deleting old relationship types — is a production best practice that preserves backward compatibility.

For agents specifically, the schema should be documented in a form the LLM can reason about. Providing the schema as a structured system prompt — "The graph contains nodes of type Paper, Author, Journal. Papers connect to Authors via [:AUTHORED_BY]. Papers connect to Journals via [:PUBLISHED_IN {year}]." — allows the agent to generate valid Cypher queries dynamically rather than relying on hardcoded query templates. This is the backbone of "text-to-Cypher" agent tools, which several teams at Airbnb and Uber have deployed internally for data exploration.

Production Pattern

Airbnb's internal data exploration agents (described in their 2023 data infrastructure blog post) use schema-in-context: the full node/relationship schema is prepended to every LLM call that needs to generate a graph query. This eliminates hallucinated relationship types and ensures agents only traverse edges that actually exist in the graph.

🎯 Advanced

Lesson 2 Quiz

3 questions — free, untracked, retake anytime.
1. What is the purpose of a transitivity declaration in an OWL ontology?
✓ Correct — ✓ Correct! A transitive property like subOrganizationOf means if A→B and B→C, the graph can infer A→C automatically. This inferential power reduces storage requirements and enables multi-hop reasoning without explicit triple enumeration.
✗ Transitivity declarations enable automatic inference: if A is related to B and B is related to C via a transitive property, the system infers A is related to C — without storing that triple explicitly.
2. According to the lesson, what is the recommended approach for helping an LLM agent generate valid Cypher queries against a knowledge graph?
✓ Correct — ✓ Correct! Schema-in-context is the production pattern: giving the LLM the graph's node labels, relationship types, and property keys prevents it from hallucinating non-existent edges and enables dynamic query generation.
✗ The correct approach is schema-in-context: prepending the schema to the LLM call. This is what teams at Airbnb and others use in production to eliminate hallucinated relationship types in generated queries.
3. According to NASA JPL's knowledge representation experience, what was the most critical factor in making agent queries return correct results?
✓ Correct — ✓ Correct! JPL's lesson was that conflating semantically different relationships (like "operationally depends on" and "physically contains") caused nonsensical query results. Schema design — specifically relationship type precision — was more important than the inference engine choice.
✗ JPL's experience showed that the critical factor was relationship type precision in the schema. Conflating "operationally depends on" with "physically contains" caused agents to return nonsensical results, regardless of inference engine power.
🎯 Advanced

Lab 2: Schema Design Workshop

Design a graph schema for a real agent use case from scratch.

Your Task

Pick a domain you know well — supply chain, healthcare, legal citations, academic research, or software dependencies. Work with the tutor to design a graph schema: define the node types, relationship types, and key properties. The tutor will challenge your choices, probe for ambiguities, and push you to justify every edge type.

Starter: Tell the tutor what domain you're designing for and give your first draft of node types and relationship types. Be specific — no generic "Entity connects to Thing" schemas.
🧪 Lab 2 — Schema Design Workshop AI Tutor
🎯 Advanced

Querying Graphs from Agent Code

Cypher, SPARQL, and the text-to-query pipeline — making agents fluent in graph traversal.

In May 2023, the team at NebulaGraph published a technical post-mortem on their LLM-to-graph query pipeline. They had initially allowed the LLM to generate raw Cypher queries directly, with no validation layer. In production, the LLM hallucinated relationship types that didn't exist — querying [:FUNDED_BY] on a graph that stored the same relationship as [:INVESTED_IN]. Queries returned empty results, and the agent confidently reported "no funding relationships found" — a factually incorrect answer. Their fix was a two-stage pipeline: LLM generates an intermediate logical query representation, a validator maps it to actual schema terms, then the Cypher is executed. Error rate on relationship-type hallucinations dropped from 23% to under 2%.

Cypher: The Agent-Friendly Query Language

Cypher, developed by Neo4j and now part of the GQL international standard (ISO/IEC 39075, ratified 2024), uses an ASCII-art syntax that mirrors graph structure visually. A pattern like (a:Person)-[:WORKS_AT]->(b:Company) is readable by both humans and LLMs, making it the most practical choice for text-to-query pipelines in 2024.

A basic agent query pattern in Cypher: MATCH (p:Person {name: $name})-[:AUTHORED]->(paper:Paper)-[:PUBLISHED_IN]->(j:Journal) WHERE j.impactFactor > 5 RETURN paper.title, j.name ORDER BY paper.year DESC LIMIT 10. This traverses two hops — person to paper to journal — with a property filter on impact factor. Expressing this question via vector retrieval would require: embedding the query, retrieving top-k paper chunks, parsing journal names from text, fetching impact factor from somewhere, filtering, and sorting — six steps versus one structured query.

For agent deployment, parameterized queries (using $name instead of hardcoded strings) prevent both injection attacks and prompt injection via crafted entity names. Never let an agent interpolate raw user input directly into a Cypher string.

Security Note

In 2022, a security researcher demonstrated that unsanitized natural language inputs to a text-to-Cypher agent could be crafted to exfiltrate graph data by injecting Cypher syntax into entity names. Parameterized queries and a query-validation layer are non-negotiable in production systems handling sensitive graph data.

SPARQL and the Open Knowledge Graph Ecosystem

SPARQL (SPARQL Protocol and RDF Query Language) is the W3C standard for querying RDF-based graphs like Wikidata, DBpedia, and the FDA's Linked Data. For agents that need to tap public knowledge graphs without building proprietary ones, SPARQL over public endpoints is the fastest path to structured world knowledge.

Wikidata's public SPARQL endpoint (query.wikidata.org) handles roughly 200 million queries per month, making it one of the most-used structured knowledge APIs in the world. An agent can query "all Nobel Prize winners in Physics born after 1950" as a SPARQL SELECT against Wikidata — returning structured, citable data rather than relying on the LLM's parametric knowledge, which may be stale or incorrect.

SPARQL is more verbose than Cypher and less LLM-friendly, but libraries like SPARQLWrapper in Python and SPARQL.js in Node abstract the network layer, and LangChain's SparqlQAChain (released 2023) provides a text-to-SPARQL wrapper for Wikidata, DBpedia, and custom RDF endpoints. The same schema-in-context principle applies: give the LLM the relevant ontology fragment before asking it to generate a query.

  • Cypher: best for Neo4j, property graphs, LLM-generated queries
  • SPARQL: best for RDF graphs, Wikidata, open linked data
  • Gremlin: best for AWS Neptune, Apache TinkerPop ecosystems
  • GraphQL: best when graph is an API layer over a property store
The Text-to-Query Pipeline Architecture

A production text-to-graph-query pipeline for agents has five stages: (1) Intent classification — does this query require graph traversal, vector retrieval, or both? (2) Entity extraction — identify named entities in the user query and resolve them to graph node IDs (entity linking). (3) Query generation — LLM generates Cypher/SPARQL using schema-in-context. (4) Query validation — check that all relationship types and node labels used exist in the schema; repair or reject if not. (5) Execution and result formatting — run the query, convert tabular results back to natural language for the agent's response.

Entity linking — step 2 — is frequently the bottleneck. "Apple" in a user query might be the company (:Apple_Inc, Q312), the fruit (:Apple_fruit, Q89), or a person's name. Production systems use entity disambiguation models (Wikipedia anchors, Wikidata entity linkers like REL or GENRE, published by Facebook AI Research in 2021) to resolve ambiguity before query generation. Without this step, the agent traverses from the wrong starting node and produces confident but incorrect answers.

Pipeline Reality Check

Meta's 2023 evaluation of their internal knowledge graph QA systems found that entity linking errors — not query generation errors — accounted for 61% of incorrect agent answers. Invest engineering effort in entity disambiguation proportionally: it has more leverage than improving query generation alone.

🎯 Advanced

Lesson 3 Quiz

3 questions — free, untracked, retake anytime.
1. According to Meta's 2023 evaluation, what accounted for the majority (61%) of incorrect agent answers in their knowledge graph QA systems?
✓ Correct — ✓ Correct! Entity linking errors were the dominant failure mode — starting traversal from the wrong node produces confidently wrong answers no matter how good the query generation is. This is why entity disambiguation deserves disproportionate engineering investment.
✗ Meta's evaluation found entity linking errors (61%) as the primary cause — not query syntax, data staleness, or schema mismatches. Traversing from the wrong starting node propagates errors through every subsequent hop.
2. What was the primary fix NebulaGraph implemented after LLMs hallucinated non-existent relationship types in Cypher queries?
✓ Correct — ✓ Correct! The two-stage pipeline — LLM generates logical query, validator maps to real schema terms, then execute — dropped relationship-type hallucination errors from 23% to under 2%. Schema validation is essential middleware in any text-to-graph pipeline.
✗ NebulaGraph's fix was a validation/mapping layer between LLM output and query execution — not a language switch or a fine-tuned model. This reduced hallucinated relationship type errors from 23% to under 2%.
3. Why are parameterized queries (using $variable syntax) recommended for agent-generated graph queries?
✓ Correct — ✓ Correct! A 2022 researcher demonstrated that unsanitized user input interpolated into Cypher strings could be crafted to exfiltrate graph data. Parameterized queries ensure entity names are treated as data values, not executable query syntax.
✗ The security reason is primary: parameterized queries prevent prompt/query injection — where crafted entity names containing Cypher syntax could be used to exfiltrate or manipulate graph data. This was demonstrated by a researcher in 2022.
🎯 Advanced · Lesson 3 Lab

Lab: Explore Lesson 3 Concepts

Apply what you learned in Lesson 3 through guided AI conversation

Your Task

Use the AI below to explore Lesson 3 concepts in depth. Challenge assumptions and work through scenarios.

Try asking about a specific concept from Lesson 3 and how it applies in practice.
🤖 AESOP Lab Assistant Lesson 3 Lab
Building AI Agents II — Skills · Module 4 · Lesson 4

Lesson 4

Advanced concepts, real-world applications, and practical implications
Core Concepts

This lesson explores lesson 4 — examining the key principles, real-world applications, and implications for practitioners working in this domain.

Understanding this topic requires both theoretical grounding and practical awareness of how these concepts manifest in deployed systems. The frameworks covered in earlier lessons provide the foundation; this lesson connects them to implementation reality.

Practical Applications

The transition from theory to practice reveals challenges that pure conceptual frameworks don't capture. Real-world deployment introduces constraints, trade-offs, and edge cases that demand nuanced judgment rather than rigid rule-following.

Effective practitioners in this space develop the ability to reason across multiple frameworks simultaneously, recognizing when different perspectives apply and how to resolve conflicts between competing priorities.

Looking Forward

As this field continues to evolve, the principles covered in this module will remain foundational even as specific technologies and implementations change. The ability to think critically about these topics — rather than simply memorizing current best practices — is what separates effective practitioners from those who merely follow checklists.

Lesson 4 Quiz

Lesson 4
What is the primary focus of Lesson 4?
✓ Correct — Correct. This lesson bridges theory and practice, focusing on real-world implementation.
Review the lesson — the focus is on connecting frameworks to practical reality.
Why does real-world deployment introduce challenges that pure theory doesn't capture?
✓ Correct — Correct. Real deployment requires judgment, not just framework application.
Practice doesn't invalidate theory — it reveals complexities that require nuanced application of theoretical principles.
What separates effective practitioners from those who merely follow checklists?
✓ Correct — Correct. Critical thinking and adaptability matter more than memorized procedures.
The key differentiator is critical thinking ability, not experience or resources alone.
🎯 Advanced · Lesson 4 Lab

Lab: Apply What You've Learned

Synthesize concepts from Lesson 4 through guided AI conversation

Your Task

Use the AI below to explore the concepts from Lesson 4 in depth. Ask questions, challenge assumptions, and work through practical scenarios related to lesson 4.

Try: "How would the concepts from this lesson apply to a real-world scenario in this field?"
🤖 AESOP Lab Assistant Lesson 4 Lab

Module 4 Test

Knowledge Graphs for Agents · 15 Questions · 70% to Pass
Score: 0/15
1. What is the core objective of Knowledge Graphs for Agents?
2. How should practitioners approach applying concepts from this module?
3. Which best describes the relationship between theory and practice in Building AI Agents II — Skills?
4. What distinguishes expert practitioners from novices in this field?
5. How does Knowledge Graphs for Agents build on previous modules?
6. What role do constraints play in practical implementation?
7. When applying frameworks from this module, what is most important?
8. How should practitioners handle conflicting perspectives in this field?
9. What makes the concepts in Knowledge Graphs for Agents relevant beyond their immediate context?
10. How should practitioners continue developing expertise after completing this module?
11. What is the relationship between understanding Building AI Agents II — Skills concepts and making decisions?
12. How do the lessons from this module apply to novel situations?
13. What is the value of understanding multiple perspectives on {course_title}?
14. How should practitioners evaluate new information or developments in this field?
15. What is the ultimate goal of learning Knowledge Graphs for Agents?