實戰上下文圖譜與 Neo4j:建構能記憶並運用「為何」的 AI 系統

實戰上下文圖譜與 Neo4j:建構能記憶並運用「為何」的 AI 系統

Hacker News·

本文探討了使用 Neo4j 實現的上下文圖譜概念,旨在建構超越單純決策的 AI 系統,透過捕捉和運用決策背後的推理與因果關係,解決傳統資料庫的限制。

Sign up

Sign in

Sign up

Sign in

Image

Neo4j Developer Blog

Image

Developer content about graph databases, Neo4j, Cypher, data science, graph analytics, GraphQL, and more

Hands On With Context Graphs And Neo4j

Building AI systems that don’t just make decisions, but remember and use the “why”.

Image

--

Listen

Share

The Problem: The missing “why”

Traditional databases are designed around a fundamental assumption: what matters is what’s true right now. Your Postgres database can tell you a customer’s current credit limit is $50,000 — but it can’t tell you why it was set to that amount, what factors were considered, or what similar decisions were made in the past.

The State Clock vs. Event Clock

This is what is known as the State Clock: a snapshot of current reality. And for decades, it was enough.

But AI agents are changing everything. When an AI-powered assistant recommends approving a $100K credit line increase, the question isn’t just “is this the right answer?” Instead we want to understand :

This requires a different kind of data structure — one that captures the Event Clock: what happened, when it happened, and why.

Enter The Context Graph

Using Jaya Gupta’s description, a Context Graph is a knowledge graph specifically designed to capture decision traces — the full context, reasoning, and causal relationships behind every significant decision in an organization.

Unlike a traditional audit log (which just records actions), a context graph captures:

This is the tribal knowledge that traditionally lives only in human experts’ heads — now captured in a queryable, analyzable structure.

Why Neo4j is the Perfect Fit

Here’s where Neo4j’s property graph model shines. Let’s look at a financial services context graph:

The Data Model

The Relationships (The Magic of Graphs)

This is where relational databases struggle a bit, while graphs shine:

In a relational database, tracing a causal chain like “what decisions led to this account freeze?” requires:

In Neo4j, it’s a two lines of code:

Context Graph Demo: AI-Powered Decision Tracing

The Context Graph Demo is a complete working application that demonstrates these concepts. It’s built with:

The AI Agent Tools

The agent has access to purpose-built tools that leverage the context graph:

A Real Workflow: Credit Line Increase

Here’s what happens when a user asks:

”Should we approve a credit limit increase for Jessica Norris? She’s requesting a $25,000 limit increase.”

The AI agent immediately begins querying the context graph:

Step 1: Customer Search (search_customer)

The agent finds Jessica Norris and populates the graph visualization with her complete profile:

Step 2: Decision History (get_customer_decisions)

The context graph reveals critical past decisions:

Step 3: Precedent Search (find_precedents)

The agent searches for similar credit limit decisions using hybrid vector search — combining semantic similarity (text embeddings) with structural similarity (FastRP graph embeddings).

Step 4: Policy Lookup (get_policy)

Retrieves applicable policies like “High-Value Transaction Review” and “KYC Refresh Policy.”

The Agent’s Recommendation:

Based on the context graph analysis, the agent returns:

⚠️ Recommendation: REJECT or ESCALATE FOR SENIOR REVIEW Key Risk Factors: Past fraud flag (April 2025) with velocity check failure Multiple compliance rejections on record High-risk tier margin account Employer associated with elevated country riskGiven the documented fraud incident and compliance pattern, I recommend either REJECT or ESCALATE with additional due diligence requirements.

The graph visualization shows 31 nodes and 30 relationships — Jessica’s complete context including her accounts, transactions, past decisions, the employees who made those decisions, and the policies that were applied.

This is the power of context graphs: The agent didn’t just check a credit score. It traced the full decision history, understood the causal relationships between past events, and made a recommendation grounded in institutional knowledge.

Graph Data Science: The Secret Weapon

Neo4j Graph Data Science (GDS) provides algorithms that are fundamentally impossible in relational databases:

Node Embeddings With FastRP

Node embedding algorithms compute low-dimensional vector representations of nodes in a graph. FastRP is a node embedding algorithm that generates 128-dimensional embeddings that capture each node’s structural position in the graph — not based on properties, but on relationship patterns. It is much faster than node2vec with equivalent accuracy and is available in the GDS library.

These embeddings enable questions like: “Find decisions that happened in similar contexts” — where “similar” means similar graph structure, not similar text.

Louvain Community Detection

Community detection algorithms are used to evaluate how groups of nodes are clustered or partitioned, as well as their tendency to strengthen or break apart. Louvain automatically clusters decisions that are densely connected through causal and influence relationships:

This surfaces patterns like: “These 15 trading exceptions all trace back to the same policy gap.”

Node Similarity for Fraud Detection

Similarity algorithms compute the similarity of pairs of nodes based on their neighborhoods or their properties. By comparing the neighborhood structure of accounts, we can find accounts that behave like known fraud cases:

This detects patterns that would be invisible to rule-based systems.

Hybrid Vector Search: Semantic + Structural

The demo implements a dual embedding strategy, reasoning_embedding using OpenAI text embedding model and fastrp_embedding using Neo4j FastRP algorithm. The text embedding captures semantic similarity of decision reasoning text while the FastRP node embedding captures the structural similarity in graph topology.

When searching for precedents, both are combined:

This finds decisions that are both semantically similar (similar reasoning text) and structurally similar (similar position in the decision graph).

Try It Yourself

The Context Graph Demo is open source and available on GitHub. To run it locally you’ll need:

Quick Start Demo

Try this single prompt to see everything in action:

This will trigger customer search, fraud detection, precedent lookup, policy retrieval, and graph visualization — all in one conversational interaction.

Why Property Graphs Are A Natural Fit For Context Graphs

Property graphs are the natural substrate for context graphs. Causal chains, precedent links, and policy applications map directly to relationships — no recursive CTEs or complex self-joins required. And GDS algorithms like FastRP, Louvain, and Node Similarity power insights that are fundamentally impossible in relational databases.

For enterprise AI, this unlocks:

The tribal knowledge that takes decades to accumulate in human experts’ heads can now be captured, queried, and leveraged by AI systems.

References & Further Reading

The concept of context graphs has been gaining significant attention in the enterprise AI space. Here are the key resources that informed this post:

The Original Thesis

The seminal piece arguing that enterprise value is shifting from “systems of record” (Salesforce, Workday, SAP) to “systems of agents.” The new crown jewel isn’t the data itself — it’s the context graph: a living record of decision traces stitched across entities and time, where precedent becomes searchable.

The Reality Check

Dharmesh calls the idea “elegant and intellectually compelling” but offers a reality check: most companies are nowhere near ready for context graphs. “We’re barely at the point where semi-autonomous agents are getting deployed for some key use cases.” While the theory is sound, the timeline may be optimistic — most companies are still struggling with basic data unification.

The Two Clocks Problem

  • What Are Context Graphs, Really? — Subramanya N A deep dive into the “state clock vs. event clock” distinction: “We’ve built trillion-dollar infrastructure for the state clock: what is true right now. But we have almost no infrastructure for the event clock: what happened, in what order, and with what reasoning.”

Tools Used in This Demo

— -

Level Up with Graph Data Science

Context graphs aren’t just a better way to store data — they’re a better way to capture institutional knowledge. And in the age of AI agents, that knowledge is the key to reliable, explainable, enterprise-grade decisions.

--

--

Image

Image

Published in Neo4j Developer Blog

Developer content about graph databases, Neo4j, Cypher, data science, graph analytics, GraphQL, and more

Image

Image

Written by William Lyon

🤠 Code Cowboy @neo4j | lyonwj.com

No responses yet

Help

Status

About

Careers

Press

Blog

Privacy

Rules

Terms

Text to speech

Hacker News

相關文章

  1. AI的兆級美元機遇:上下文圖譜

    4 個月前

  2. 從數據塊到受管上下文:為 AI 代理重新架構數據

    3 個月前

  3. 可查詢的上下文圖譜用於審核 AI 決策

    4 個月前

  4. 打造千萬節點AI記憶體系:架構、失敗與寶貴經驗

    4 個月前

  5. AI更酷的兆級美元機會:氛圍圖譜

    3 個月前