Graph Reasoning with neo4j-cli

Introduction

Your tools are scripts your agent runs. But sometimes you - or the agent - just want to ask the graph a question without writing a tool.

Advanced learners: Skip to the finale.

Everyone else: This shows the neo4j-cli your agent already has, used directly for ad-hoc reasoning across both graphs.

One command, any query

The Codespace ships neo4j-cli (the agent installed its skills in setup). It reads the same .env, so there is nothing to wire:

shell
Ask the graph directly
neo4j-cli query "MATCH (s:Section)-[:LINKS_TO]->(tgt) RETURN coalesce(tgt.displayName, tgt.uri) AS target, count(*) AS links ORDER BY links DESC LIMIT 5"

This is what your agent runs under the hood when you ask it an open question. Try asking your agent "which section or document is linked to by the most other sections?" and watch the neo4j-cli call it makes.

Introspect the shape

When the agent meets an unfamiliar graph, the first move is to read its schema:

shell
What’s in here?
neo4j-cli query ":schema"

You will see both graphs at once: the document containment (Library, Folder, Document, Section) and the connections metadata (Database, Schema, Table, Column) that neocarta built. Two shapes, one database - the agent reads the schema to know which to traverse.

Reason across both graphs

Because both graphs live in the same Neo4j, one query can span them. A part number is not a graph node - it lives in section text on the document side and as a part_number column on the warehouse side. So one query can find both at once: the warehouse tables that carry a part_number key, plus the library sections whose text mentions a given part string.

shell
The document graph and the warehouse metadata, side by side
neo4j-cli query "MATCH (t:Table)-[:HAS_COLUMN]->(c:Column {name: 'part_number'}) RETURN t.name AS warehouseTable ORDER BY warehouseTable"
shell
Find a part string in the library text (it is text, not a node)
neo4j-cli query "CALL db.index.fulltext.queryNodes('content_search', 'IC-2042') YIELD node, score RETURN node.uri AS section ORDER BY score DESC LIMIT 5"

Ad-hoc reasoning like this is the connective tissue between the shaped tools - the move an agent makes when a question does not fit a pre-built script.

Summary

In this optional lesson, you used neo4j-cli directly:

  • Ad-hoc queries - the same call your agent makes for open questions

  • :schema - read an unfamiliar graph’s shape before traversing it

  • Cross-graph reasoning - documents and connections metadata in one query

In the finale, the agent combines its shaped tools with reasoning like this.

Chatbot

How can I help you today?

Data Model

Your data model will appear here.