Cypher is a declarative query language designed specifically for the property graph model, enabling users to express graph traversal patterns using ASCII-art syntax. Rather than specifying how to retrieve data, users declare what patterns to match, allowing the query engine to optimize execution. Its syntax represents nodes with parentheses () and directed relationships with arrows -->, making complex multi-hop queries visually intuitive.
Glossary
Cypher

What is Cypher?
Cypher is a declarative, pattern-matching query language originally developed by Neo4j for efficiently querying and modifying property graph databases.
Originally developed by Neo4j, Cypher has evolved into an open standard through the openCypher project, with adoption across multiple graph database vendors. It supports graph projection, aggregation, and subgraph extraction, making it essential for constructing and querying legal knowledge graphs where entities like statutes, citations, and parties must be traversed with high precision.
Key Features of Cypher
Cypher is a declarative, pattern-matching query language originally developed by Neo4j for efficiently querying and modifying property graph databases. Its ASCII-art syntax makes graph traversal intuitive and expressive.
Declarative Pattern Matching
Cypher uses an ASCII-art syntax to express graph patterns visually. Instead of writing procedural traversal logic, you describe the structure you want to find, and the query engine optimizes the retrieval.
- Nodes are represented with parentheses:
(p:Person) - Relationships are drawn with arrows:
-[r:KNOWS]-> - A complete pattern looks like:
(a:Person)-[:KNOWS]->(b:Person)-[:LIVES_IN]->(c:City)
This declarative approach separates what to retrieve from how to retrieve it, allowing the Cypher planner to use cost-based optimization for efficient execution.
Property Graph Native Operations
Cypher is purpose-built for the Property Graph Model, where both nodes and relationships can hold arbitrary key-value properties. This enables rich, expressive queries that filter on metadata directly within traversal patterns.
- Node properties:
MATCH (c:Case {jurisdiction: 'Federal'}) - Relationship properties:
MATCH (a)-[r:CITES {weight: 'majority'}]->(b) - Variable-length paths:
MATCH (a)-[:APPEALS_TO*2..5]->(b)finds chains of 2 to 5 appeals
For legal knowledge graphs, this allows modeling citation networks with metadata like court level, date, and treatment status directly on edges.
CRUD and Graph Mutation
Unlike read-only query languages, Cypher supports full Create, Read, Update, Delete (CRUD) operations on graph structures. This makes it suitable for both analytical queries and transactional graph construction.
- CREATE:
CREATE (s:Statute {name: 'CFAA', section: '1030'}) - MERGE: Ensures a pattern exists without duplication—critical for idempotent knowledge graph construction
- SET/REMOVE: Modify properties on existing nodes and relationships
- DETACH DELETE: Remove nodes along with all their incident relationships
This mutability is essential for building and maintaining evolving legal knowledge graphs that must incorporate new case law and statutory amendments.
Graph Projections and Aggregation
Cypher supports aggregation functions and list comprehensions that enable complex analytical queries over graph structures without requiring external processing.
- Aggregation:
count(),collect(),avg(),min(),max()operate over matched subgraphs - List comprehension:
[x IN nodes(path) WHERE x:Precedent | x.name]filters and transforms inline - Path functions:
shortestPath(),allShortestPaths()find optimal routes through legal citation networks - WITH clause: Enables pipeline-style query composition, passing intermediate results between query segments
For legal reasoning, this enables queries like "find the most-cited precedent within a 3-hop radius of this statute" in a single expression.
Schema Constraints and Indexing
Cypher includes DDL-style commands for enforcing data integrity and optimizing query performance through explicit indexing and constraint creation.
- Uniqueness constraints:
CREATE CONSTRAINT FOR (c:Case) REQUIRE c.citation IS UNIQUE - Node key constraints: Ensure a combination of properties uniquely identifies a node
- Existence constraints: Require specific properties on nodes or relationships
- Index types: B-tree, full-text, and vector indexes for hybrid semantic + structural search
These features are critical for legal knowledge graphs where citation integrity and entity disambiguation are non-negotiable requirements.
Subqueries and Query Composition
Modern Cypher (openCypher 9+) supports subqueries through CALL blocks, enabling modular query design and complex multi-stage graph analytics within a single statement.
- CALL subqueries: Execute a nested query and union results with the outer scope
- Post-union processing: Apply additional filters and aggregations after combining subquery results
- Existential subqueries: Test for pattern existence without returning data:
EXISTS { MATCH (a)-[:OVERRULES]->(b) }
This composability allows legal engineers to build modular reasoning pipelines—for example, first identifying relevant precedents, then filtering by jurisdictional authority, then ranking by citation frequency.
Cypher vs. SPARQL vs. SQL for Graph Traversal
Comparative analysis of declarative query languages for traversing graph-structured data, focusing on variable-length path expressions and recursive join capabilities essential for legal knowledge graph construction.
| Feature | Cypher | SPARQL | SQL (Recursive CTE) |
|---|---|---|---|
Primary Data Model | Property Graph (labeled nodes, typed relationships, key-value properties) | RDF Triples (subject-predicate-object, URI-based identifiers) | Relational Tables (rows, columns, foreign key constraints) |
Variable-Length Path Traversal | |||
Native Path-Finding Syntax | MATCH (a)-[*1..5]->(b) | a :prop/:prop+ b (property paths) | WITH RECURSIVE ... UNION ALL (manual recursion) |
Shortest Path Built-in | |||
Relationship Directionality | Explicit (->, <-, --) | Implicit (property path direction) | Not applicable (join logic) |
Named Relationship Types | |||
Inference/Reasoning Support | |||
W3C Standardized | |||
Typical Traversal Depth Performance | O(1) per hop (index-free adjacency) | O(log n) per hop (indexed joins) | O(n) per recursion level (iterative joins) |
Schema Flexibility | Optional schema (labels and property types) | Schema-optional (OWL constraints if desired) | Strict schema required (DDL) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, technical answers to common questions about Cypher, the declarative graph query language for property graph databases.
Cypher is a declarative, pattern-matching query language originally developed by Neo4j for efficiently querying and modifying property graph databases. Unlike imperative languages that specify how to retrieve data, Cypher allows users to describe what data they want using ASCII-art-like graph patterns. The language works by matching these visual patterns against the stored graph structure. A query engine's cost-based optimizer then determines the most efficient traversal strategy, selecting appropriate indexes and join algorithms. Cypher's syntax is designed to be intuitive: nodes are represented by parentheses (), relationships by square brackets [] with directional arrows -->, and properties by curly braces {}. For example, (a:Person)-[:KNOWS]->(b:Person) matches all pairs of people connected by a KNOWS relationship. This pattern-matching paradigm makes complex graph traversals—like finding the shortest path or identifying subgraph isomorphisms—expressible in concise, readable queries.
Related Terms
Mastering Cypher requires understanding its place within the broader landscape of graph databases, semantic standards, and analytical techniques. These related concepts define the infrastructure and logic that Cypher queries interact with.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us