The Cypher Query Language is a declarative graph query language developed for Neo4j that uses an intuitive, ASCII-art syntax to express graph patterns for matching, creating, updating, and deleting nodes and relationships. Its core strength lies in its ability to visually map the structure of a query to the shape of the data in the graph, making complex traversals and pattern matching highly readable. Unlike imperative languages, Cypher describes what to retrieve, not how to retrieve it, allowing the underlying graph database engine to optimize execution.
Glossary
Cypher Query Language

What is Cypher Query Language?
Cypher is a declarative, ASCII-art-inspired query language designed specifically for the property graph model, enabling intuitive and efficient querying and manipulation of graph data.
Cypher operates on the property graph model, where entities are nodes with labels and key-value properties, connected by directed, typed relationships which can also hold properties. Its syntax centers on clauses like MATCH (for pattern matching), WHERE (for filtering), RETURN (for projecting results), and CREATE/MERGE (for writing data). As a domain-specific language, it is optimized for graph operations like variable-length path finding and recursive traversals, which are cumbersome in SQL. While initially proprietary to Neo4j, an open-source project, openCypher, aims to establish it as a standard, with implementations in other systems like Apache AGE.
Key Features of Cypher
Cypher is a declarative graph query language developed for Neo4j, designed for efficient querying and updating of property graphs using an intuitive ASCII-art syntax for pattern matching.
ASCII-Art Pattern Matching
Cypher's most distinctive feature is its use of ASCII-art syntax to visually represent graph patterns. Nodes are depicted with parentheses (), relationships with arrows --> or --, and properties within curly braces {}. This makes complex graph traversals intuitive to write and read.
- Example:
MATCH (p:Person)-[:LIVES_IN]->(c:City {name: 'Berlin'}) 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
Like SQL, Cypher is a declarative language. You specify what data to find (the pattern), not how to traverse the graph. The Cypher query planner and optimizer determine the most efficient execution path, leveraging indexes and graph statistics.
- Key clauses follow a logical flow:
MATCH(find patterns),WHERE(filter results),RETURN(project data). - This abstraction allows developers to focus on the data model and business logic, while the database engine handles performance optimization.
Property Graph Model Native
Cypher is natively designed for the property graph model, which consists of:
- Nodes (vertices) with labels (e.g.,
:Person,:Product) and key-value properties. - Relationships (edges) with a type (e.g.,
:PURCHASED,:WORKS_FOR) and direction, which can also have properties. - This model is more flexible for many enterprise use cases than the RDF triple model, allowing attributes to be directly attached to both entities and connections.
Clauses for Reading & Writing
Cypher provides a comprehensive set of clauses for full CRUD (Create, Read, Update, Delete) operations on the graph.
- Read Clauses:
MATCH,OPTIONAL MATCH,WHERE,RETURN,ORDER BY,LIMIT. - Write Clauses:
CREATE(nodes/relationships),MERGE(create or match),SET(update properties),DELETE/DETACH DELETE(remove elements),REMOVE(delete labels/properties). - Combining Operations: Read and write clauses can be combined in a single query, enabling complex transactional operations like finding a pattern and creating new connected data.
Path Finding & Variable-Length Relationships
Cypher excels at expressing complex traversals and pathfinding queries using a concise syntax for variable-length relationships.
- Use
*to match paths of arbitrary length:(:Person)-[:KNOWS*]->(:Person). - Specify a range:
[:KNOWS*2..5]finds paths between 2 and 5 hops long. - The
shortestPath()andallShortestPaths()functions provide optimized algorithms for common graph problems, directly within the query language.
Aggregation & List Comprehensions
Cypher supports powerful aggregation functions and operations on collections, similar to features in modern programming languages.
- Aggregation: Functions like
COUNT(),COLLECT(),SUM(), andAVG()work withGROUP BYsemantics. - List & Map Projection: Create lists and maps directly in
RETURN:RETURN p.name, [ (p)-[:HAS_SKILL]->(s) | s.name ] AS skills. - Pattern Comprehensions: A compact syntax for filtering and projecting within a sub-pattern, enabling complex nested queries without multiple
MATCHclauses.
Cypher vs. SPARQL: A Comparison
A technical comparison of the declarative query languages for property graphs (Cypher) and RDF graphs (SPARQL), highlighting their core paradigms, syntax, and ecosystem fit.
| Feature / Metric | Cypher (Neo4j) | SPARQL (W3C Standard) |
|---|---|---|
Primary Data Model | Property Graph (Nodes, Relationships, Properties) | RDF Graph (Subject-Predicate-Object Triples) |
Core Query Paradigm | ASCII-art pattern matching (e.g., | Graph pattern matching via triple patterns (e.g., |
Schema & Validation | Optional, user-defined via constraints & indexes. No formal semantics. | Defined via RDFS or OWL ontologies. SHACL for shape-based validation. |
Built-in Reasoning | ||
Standardization Body | OpenCypher (de facto), ISO/GQL (in progress) | World Wide Web Consortium (W3C) Recommendation |
Primary Use Case | Interactive querying & analytics on connected, attributed data. | Semantic web integration, linked data querying, & ontology-based reasoning. |
Path Query Syntax | Variable-length relationships: | Property Paths: |
Federated Query Support | Via APOC procedures or Neo4j Fabric (vendor-specific). | Native |
Update Operations |
|
|
Result Transformation |
|
|
Common Cypher Query Examples
Cypher is a declarative graph query language for Neo4j, using an intuitive ASCII-art syntax to find patterns in property graphs. Below are foundational and practical query examples.
Find Nodes by Label
The most basic query retrieves all nodes of a specific type (label). Use MATCH with parentheses and a colon.
Example: MATCH (p:Person) RETURN p
- Returns all nodes labeled
Person. - The
RETURNclause specifies what data to output. - You can limit results:
MATCH (p:Person) RETURN p LIMIT 10.
Traverse Relationships
Cypher excels at finding connected data. Use arrows (--> or <--) to traverse relationships, specifying their type in square brackets.
Example: MATCH (p:Person)-[:WORKS_FOR]->(c:Company) RETURN p.name, c.name
- Finds all
Personnodes connected to aCompanynode via aWORKS_FORrelationship. - The direction of the arrow matters;
-[:WORKS_FOR]->means the relationship goes from Person to Company. - Returns the names of the people and their employers.
Filter with WHERE
The WHERE clause filters results based on node/relationship properties, similar to SQL.
Example: MATCH (p:Person) WHERE p.age > 30 AND p.name STARTS WITH 'A' RETURN p
- Filters
Personnodes where theageproperty is greater than 30 and thenameproperty starts with 'A'. - Can use operators:
=,<>,<,>,CONTAINS,ENDS WITH. WHEREis often used with pattern matching:MATCH (p)-[:LIKES]->(m:Movie) WHERE m.year = 2023 RETURN p.name.
Create Nodes and Relationships
The CREATE clause inserts new graph elements. Use parentheses for nodes and brackets for relationships.
Example: CREATE (alice:Person {name: 'Alice', age: 30}), (bob:Person {name: 'Bob'}), (alice)-[:KNOWS {since: 2020}]->(bob)
- Creates two
Personnodes with property sets ({...}). - Creates a
KNOWSrelationship fromalicetobobwith asinceproperty. - Tip: Use
MERGEinstead ofCREATEto avoid duplicates, as it checks for existence first.
Variable-Length Paths
Find paths of uncertain depth using the * operator. Essential for hierarchical or network data.
Examples:
MATCH (p:Person)-[:FRIEND_OF*1..3]->(fof:Person) RETURN p, fof- Finds friends-of-friends, traversing 1 to 3
FRIEND_OFhops.
- Finds friends-of-friends, traversing 1 to 3
MATCH path = (c:Company)<-[:WORKS_FOR*]-(e:Employee)- Finds all employees connected to a company at any depth (unbounded).
- The
pathvariable captures the entire sequence of nodes and relationships.
Aggregate and Group Data
Use aggregation functions (COUNT, SUM, AVG, COLLECT) with RETURN and GROUP BY logic.
Example: MATCH (p:Person)-[:REVIEWED]->(m:Movie) RETURN m.title, AVG(p.rating) AS avg_rating, COUNT(*) AS reviews ORDER BY avg_rating DESC
- For each movie, calculates the average rating and counts the number of reviews.
- Groups results implicitly by the non-aggregated column (
m.title). ORDER BYsorts the final results.COLLECT(p.name)would create a list of reviewer names.
Frequently Asked Questions
Cypher is the declarative graph query language developed for Neo4j. It uses an intuitive ASCII-art syntax for pattern matching, making it the primary tool for interacting with property graph databases.
Cypher is a declarative, ASCII-art-inspired query language specifically designed for querying and updating property graph databases, most notably Neo4j. It allows users to express complex graph patterns in a human-readable syntax that visually resembles the structure of the graph itself. Unlike imperative languages, you describe what data you want to find or manipulate, not how to traverse the graph, leaving query optimization to the database engine. Its core strength lies in its intuitive pattern matching for nodes, relationships, and their properties, making it the standard language for developers working with labeled property graphs.
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 languages and models for representing and querying structured knowledge. These related concepts define the landscape of semantic data management.
Graph Query Optimization
Graph Query Optimization refers to the techniques used by graph database engines to efficiently execute declarative queries like those written in Cypher. This involves:
- Cost-Based Planners: Analyzing statistics about the graph (e.g., node degree, label selectivity) to choose the most efficient execution plan.
- Index Utilization: Leveraging indexes on node labels, relationship types, or property values to avoid full graph scans.
- Join Strategy Selection: Deciding the optimal order and method for matching multiple patterns in a query, which is critical for performance in connected data.
Graph Pattern Matching
Graph Pattern Matching is the core computational task performed by Cypher. It involves finding all subgraphs within a larger property graph that conform to a specified pattern.
- Cypher Syntax: Patterns are expressed intuitively using parentheses for nodes
(), arrows for relationships-->, and square brackets for details[:KNOWS]. - Example: The pattern
(p:Person)-[:LIVES_IN]->(c:City)matches all person nodes connected to city nodes via aLIVES_INrelationship. - This declarative approach abstracts away the procedural traversal logic, allowing developers to focus on what data they want, not how to retrieve it.

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