Cypher Query Language (CQL) is a declarative, ASCII-art-inspired language for querying and updating property graphs. Its core syntax uses parentheses () for nodes, arrows --> for relationships, and square brackets [] for relationship details, allowing users to visually describe the graph patterns they wish to find, create, or modify. As a declarative language, users specify what data they want, not how to retrieve it, leaving the query optimization and execution to the underlying graph database engine.
Glossary
Cypher Query Language

What is Cypher Query Language?
Cypher is a declarative graph query language developed for the Neo4j graph database, designed to intuitively express complex graph patterns for data retrieval and manipulation.
Cypher supports standard CRUD operations (CREATE, READ, UPDATE, DELETE), complex filtering, aggregation, and pathfinding. It is integral to enterprise knowledge graphs for its ability to intuitively traverse connected data. While initially created for Neo4j, its openCypher variant has influenced the GQL international standard initiative. For optimization, Cypher compiles queries into execution plans that leverage techniques like index-free adjacency, predicate pushdown, and cost-based optimization to ensure efficient traversal of large-scale graphs.
Key Features of Cypher
Cypher is a declarative graph query language, developed for Neo4j, that uses an ASCII-art syntax to specify patterns for matching, creating, updating, and deleting nodes and relationships in a property graph.
ASCII-Art Pattern Matching
Cypher's most distinctive feature is its use of ASCII-art to visually represent graph patterns. Nodes are depicted with parentheses (), relationships with arrows --> or <--, and properties with curly braces {}. This syntax makes complex graph traversals intuitive to read and write.
- Example:
MATCH (p:Person)-[:LIVES_IN]->(c:City {name:'London'}) RETURN p.name - The pattern
(p:Person)-[:LIVES_IN]->(c:City)directly mirrors the visual structure of the graph, connecting aPersonnode to aCitynode via aLIVES_INrelationship.
Declarative Syntax
Cypher is a declarative language, meaning you specify what data you want, not how to retrieve it. The query optimizer determines the most efficient execution plan (scan, index, join order). This separates query logic from execution mechanics, improving developer productivity and allowing the database engine to apply advanced optimizations like predicate pushdown and cost-based optimization.
- You declare patterns (
MATCH), filters (WHERE), and results (RETURN). - The engine handles traversal algorithms, index selection, and join ordering.
Clause-Based Structure
Cypher queries are composed of distinct, chainable clauses, each serving a specific purpose in the query pipeline. This modular structure promotes readability and logical flow.
Core clauses include:
MATCH: Describes the graph pattern to find.WHERE: Adds constraints to filter patterns.RETURN: Specifies what data to output.CREATE/MERGE: Creates new graph elements or ensures they exist.SET/REMOVE: Updates properties and labels.DELETE: Removes elements.WITH: Pipes results between query parts, enabling complex multi-step operations.
Property Graph Model Native
Cypher is natively designed for the labeled property graph (LPG) model. This model's core components—nodes, relationships, labels, and properties—are first-class citizens in the language.
- Nodes:
(:Person {name: 'Alice', age: 30}) - Relationships: Have direction, a type (e.g.,
:KNOWS), and can also hold properties[:KNOWS {since: 2019}]. - Labels (e.g.,
Person,Movie) group nodes and enable schema-like constraints and indexing. - This native alignment allows Cypher to leverage storage optimizations like index-free adjacency for ultra-fast traversals.
Expressiveness for Complex Patterns
Cypher excels at expressing complex, multi-hop graph patterns and path queries concisely. It provides powerful operators for variable-length paths, optional patterns, and path filtering.
Key pattern features:
- Variable-length Paths:
(a)-[:FRIEND_OF*1..5]->(b)finds paths of 1 to 5FRIEND_OFhops. - Shortest Path: Built-in
shortestPath()function for finding optimal routes. - Optional Matching:
OPTIONAL MATCHreturnsnullfor missing parts, acting like an outer join. - Path Variables: Assign a path to a variable for later use:
p = (a)-[*]->(b).
Integration with Graph Algorithms
Cypher seamlessly integrates with graph analytics, allowing queries to invoke built-in graph algorithms and use their results for further filtering or aggregation. This blurs the line between transactional querying and analytical processing.
- Examples:
MATCH (p:Person) RETURN p.name, centrality.pageRank(p) - Algorithms like PageRank, community detection (Louvain), and shortest path (Dijkstra) can be called directly within a
RETURNorWHEREclause. - This enables powerful insights, such as finding influential entities or clustered communities, within a single query.
Cypher vs. Other Graph Query Languages
A technical comparison of declarative graph query languages, focusing on syntax, model support, and optimization paradigms.
| Feature / Metric | Cypher (Neo4j) | Gremlin (Apache TinkerPop) | SPARQL 1.1 (W3C) |
|---|---|---|---|
Primary Data Model | Labeled Property Graph (LPG) | Property Graph (via TinkerPop) | RDF Triplestore |
Query Paradigm | Declarative (ASCII-art patterns) | Imperative / Functional traversal | Declarative (triple patterns) |
Core Optimization Strategy | Cost-Based Optimization (CBO) with heuristic rules | Traversal strategy optimization | Heuristic Optimization with some CBO extensions |
Native Storage Principle | Index-Free Adjacency | Varies by implementation (e.g., JanusGraph) | Triple/Quad indexing (PSO, POS, etc.) |
Join Ordering Optimization | |||
Predicate Pushdown Support | |||
Approximate Query Processing (AQP) Integration | Via plugins and sampling functions | Limited; depends on underlying engine | Via SPARQL 1.1 subqueries and SAMPLE |
Adaptive Query Processing (AQP) Support | In development / experimental | ||
Vectorized Execution | |||
Just-In-Time (JIT) Compilation | For certain operators in Neo4j 5+ | ||
Standardized Cardinality Estimation | |||
Primary Use Case | Business analytics, pattern matching on LPGs | Graph algorithm exploration, complex pathfinding | Semantic web integration, ontology querying |
Typical Latency for 3-hop Traversal | < 10 ms | 10-100 ms (highly implementation-dependent) | 50-500 ms (depends on triple index complexity) |
Common Cypher Query Examples
Cypher is a declarative graph query language for Neo4j that uses an intuitive ASCII-art syntax to find patterns. These examples demonstrate its core operations for matching, creating, updating, and analyzing property graphs.
Basic Pattern Matching (MATCH)
The MATCH clause is used to find patterns in the graph. It is the primary mechanism for reading data.
- Find a person named 'Alice':
MATCH (p:Person {name: 'Alice'}) RETURN p - Find Alice's friends:
MATCH (p:Person {name: 'Alice'})-[:FRIEND_OF]->(friend) RETURN friend.name - Find patterns of variable length: Use
*for variable-length traversals.MATCH (p:Person)-[:FRIEND_OF*1..3]->(fof) RETURN DISTINCT fof.namefinds friends up to 3 hops away.
Creating Nodes and Relationships (CREATE)
The CREATE clause is used to insert new nodes and relationships into the graph.
- Create a node with a label and properties:
CREATE (p:Person {name: 'Bob', age: 30}) - Create a relationship between existing nodes: First find the nodes, then create the link.
codeMATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:WORKS_WITH {since: 2020}]->(b)
- Create a full pattern in one statement:
CREATE (c:Company {name: 'Acme'})<-[:WORKS_AT]-(p:Person {name: 'Charlie'})
Updating Properties (SET) and Merging (MERGE)
SET updates properties on nodes or relationships. MERGE ensures a pattern exists, creating it if it doesn't (a 'get or create' operation).
- Update a property:
MATCH (p:Person {name: 'Alice'}) SET p.age = 31 - Merge a node (create if not exists):
MERGE (p:Person {name: 'David'}) ON CREATE SET p.created = timestamp() - Merge a relationship: This ensures the connection exists without creating duplicate nodes.
codeMATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) MERGE (a)-[:FRIEND_OF]->(b)
Filtering and Aggregation (WHERE, WITH, RETURN)
Combine WHERE for filtering, WITH for piping intermediate results, and RETURN for final projection and aggregation.
- Filter with WHERE:
MATCH (p:Person) WHERE p.age > 25 RETURN p.name - Aggregate results:
MATCH (p:Person)-[:WORKS_AT]->(c:Company) RETURN c.name, count(p) AS employeeCount - Chain operations with WITH:
WITHis like a pipeline. This finds people, filters, then counts:
codeMATCH (p:Person) WITH p WHERE p.age >= 18 RETURN count(p) AS adults
Path Finding and Shortest Path
Cypher has built-in functions for finding paths between nodes, which is a core strength of graph databases.
- Find any path:
MATCH path = (a:Person {name: 'Alice'})-[:FRIEND_OF|WORKS_WITH*..5]-(b:Person {name: 'Zoe'}) RETURN path - Find the shortest path: Use the
shortestPath()function. This finds the fewest relationships connecting two nodes.
codeMATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Zoe'}) MATCH p = shortestPath((a)-[*..15]-(b)) RETURN p
- Find all shortest paths: Use
allShortestPaths()to find all paths tied for the shortest length.
Deleting Elements (DELETE, DETACH DELETE)
DELETE removes nodes or relationships. DETACH DELETE removes a node and all its connected relationships.
- Delete a relationship:
MATCH (a:Person {name: 'Alice'})-[r:FRIEND_OF]->(b:Person {name: 'Bob'}) DELETE r - Delete a node (must have no relationships):
MATCH (p:Person {name: 'Charlie'}) DELETE p - Force delete a node and its relationships:
MATCH (p:Person {name: 'David'}) DETACH DELETE p - Delete all data:
MATCH (n) DETACH DELETE n- Use with extreme caution.
Frequently Asked Questions
Cypher is the declarative graph query language for Neo4j, designed for intuitive pattern matching and manipulation of property graphs. These FAQs address its core mechanics, optimization, and role in enterprise systems.
Cypher is a declarative graph query language, originally developed for the Neo4j graph database, that uses an intuitive ASCII-art syntax to specify patterns for matching, creating, updating, and deleting nodes and relationships in a property graph. Unlike imperative languages, you describe what data you want, not how to retrieve it, leaving the optimization and execution to the database engine. Its core abstraction is the Labeled Property Graph (LPG), where nodes (circles) and relationships (arrows) can have labels and properties. A basic pattern like (p:Person)-[:LIVES_IN]->(c:City) reads naturally as "a Person node, labeled Person, with a LIVES_IN relationship to a City node." Cypher is central to enterprise knowledge graphs for its ability to express complex, connected queries concisely.
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.
Related Terms
Cypher operates within a broader ecosystem of graph technologies and optimization strategies. These related concepts define its operational context and performance characteristics.
Property Graph Model
The property graph model is the foundational data structure for which Cypher is designed. It consists of:
- Nodes (vertices) representing entities, which can have labels (types) and properties (key-value pairs).
- Relationships (edges) connecting nodes, which are always directed, have a single type, and can also contain properties.
- This model's flexibility and intuitive mapping to real-world data make it the dominant paradigm for enterprise knowledge graphs, directly enabling Cypher's expressive pattern-matching syntax.
Gremlin Traversal
Gremlin is a functional, imperative graph traversal language and virtual machine within the Apache TinkerPop framework. It serves as a primary alternative and complement to declarative Cypher.
- Imperative vs. Declarative: Where Cypher declares what pattern to find, Gremlin specifies how to walk the graph step-by-step.
- Machine Portability: Gremlin queries can run across any TinkerPop-enabled graph system (e.g., JanusGraph, Amazon Neptune).
- Use Case: Often used for complex, procedural graph algorithms and analytics where fine-grained control over the traversal path is required.
SPARQL 1.1
SPARQL 1.1 is the W3C-standardized query language for RDF triplestores, representing a different semantic web paradigm compared to Cypher's property graphs.
- Data Model: Queries over triples (subject-predicate-object) rather than labeled property graphs.
- Capabilities: Supports sophisticated graph pattern matching, aggregation, subqueries, and update operations.
- Interoperability: Designed for the open web of linked data, whereas Cypher is often used for closed, enterprise-domain knowledge graphs. The choice between them is fundamentally a choice between RDF and LPG data models.
Index-Free Adjacency
Index-free adjacency is a native graph storage principle that enables Cypher's fast traversals. In a natively stored graph database like Neo4j:
- Each node maintains direct physical pointers to its connected relationships (edges).
- Traversing from one node to its neighbors is a constant-time operation, akin to a pointer dereference in RAM, without requiring a global index lookup.
- This is the architectural foundation that makes Cypher path queries (
()-[:KNOWS*2..5]->()) efficient, as the engine can 'walk' the stored graph structure directly.
Query Plan & Explain
A query plan is the sequence of low-level operations (e.g., NodeByLabelScan, Expand, Filter) generated by the Cypher query planner and optimizer to execute a high-level MATCH clause. Using the EXPLAIN or PROFILE keywords reveals this plan.
- Planner: Translates Cypher into an initial logical plan.
- Optimizer: Applies rules (heuristic optimization) and cost estimates (cost-based optimization) to transform the plan into a more efficient form (e.g., selecting indexes, reordering patterns).
- Analysis: The
EXPLAINoutput is critical for database engineers to diagnose performance bottlenecks and understand how a Cypher statement will be executed.
Graph Traversal
Graph traversal is the core computational operation underlying any Cypher pattern match. It is the process of systematically visiting nodes and edges in a graph.
- Pathfinding: Cypher's variable-length paths (
*) implement algorithms like depth-limited depth-first search. - Traversal Direction: Relationships in patterns are directional (
->,<-), guiding the traversal walk. - Foundation: While Cypher is declarative, its runtime engine performs traversals to locate subgraphs that satisfy the specified patterns. Understanding traversal complexity is key to writing performant queries.

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