Inferensys

Glossary

Cypher

Cypher is a declarative query language for property graph databases that uses ASCII-art pattern matching to express traversals and data manipulation operations.
Knowledge engineer constructing knowledge base on laptop, document hierarchy visible, casual office setup.
DECLARATIVE GRAPH QUERY LANGUAGE

What is Cypher?

Cypher is a declarative query language for property graphs, originally developed by Neo4j and now an open standard (openCypher), that uses ASCII-art pattern matching to express traversals and data manipulation.

Cypher is a declarative graph query language designed specifically for interacting with labeled property graphs. Its syntax relies on ASCII-art patterns—such as (node)-[RELATIONSHIP]->(node)—to visually represent graph traversals, making complex pathfinding queries intuitive to write and read. Originally proprietary to the Neo4j database, it has since been standardized as openCypher and adopted by other graph systems like Apache Age and RedisGraph.

Unlike the W3C standard SPARQL for RDF triple stores, Cypher is optimized for the property graph model where both nodes and relationships can hold arbitrary key-value attributes. It supports graph analytics, data modification (CREATE, MERGE, DELETE), and multi-hop pattern matching. The language's design prioritizes human readability for expressing entity resolution and link prediction tasks, making it a cornerstone of modern knowledge graph construction and GraphRAG pipelines.

GRAPH QUERY LANGUAGE

Key Features of Cypher

Cypher is a declarative, pattern-matching query language that enables developers to express complex graph traversals using intuitive ASCII-art syntax, making it the standard for querying property graph databases.

01

Declarative Pattern Matching

Cypher uses ASCII-art syntax to visually represent graph patterns, making queries intuitive and readable. Instead of describing how to traverse, you declare what pattern to find.

  • Nodes are represented with parentheses: (node:Label)
  • Relationships use arrows and brackets: -[rel:TYPE]->
  • Patterns compose naturally: (a:Person)-[:KNOWS]->(b:Person)
  • The engine optimizes traversal behind the scenes

This declarative approach separates query intent from execution strategy, allowing the query planner to choose optimal traversal algorithms.

02

Graph-Specific Clauses

Cypher provides specialized clauses designed for graph operations that go far beyond SQL's relational capabilities.

  • MATCH: Finds patterns in the graph using index lookups and traversal
  • MERGE: Creates patterns only if they don't exist, preventing duplicates
  • CREATE: Adds nodes and relationships atomically
  • DETACH DELETE: Removes nodes and all connected relationships safely
  • CALL: Invokes procedures for graph algorithms like PageRank or community detection

Variable-length path queries like (a)-[*2..5]->(b) find paths of any length between nodes, enabling friend-of-friend queries natively.

03

Open Standard & Multi-Vendor

Originally developed for Neo4j, Cypher became an open standard through the openCypher project in 2015, enabling adoption across the graph ecosystem.

  • GQL (Graph Query Language): ISO/IEC 39075:2024 standard heavily influenced by Cypher
  • Cypher for Apache Spark: Enables graph queries on distributed data
  • Cypher for Gremlin: Bridges property graph and RDF/SPARQL worlds
  • Amazon Neptune, Memgraph, RedisGraph, and AgensGraph all support Cypher

This standardization ensures query portability and prevents vendor lock-in for enterprise knowledge graph deployments.

04

Aggregation & Path Functions

Cypher includes built-in functions for computing metrics over graph structures, essential for analytics and feature engineering.

  • collect(): Gathers matched entities into lists for aggregation
  • count(), avg(), sum(): Standard statistical operations on node properties
  • shortestPath(): Finds the minimum-hop path between two nodes using bidirectional BFS
  • allShortestPaths(): Returns all paths with the minimum length
  • path length(): Computes the number of hops in a matched path

These functions enable complex analytical queries like finding central nodes or computing graph-level statistics directly in the query language.

05

Schema Flexibility with Optional Constraints

Cypher operates on the labeled property graph model, which provides schema flexibility while supporting optional constraints for data integrity.

  • Nodes and relationships can have arbitrary key-value properties without predefined schemas
  • UNIQUE constraints enforce property uniqueness on labeled nodes
  • EXISTENCE constraints require specific properties on nodes or relationships
  • NODE KEY constraints define composite keys for entity identity
  • Relationship type constraints restrict which node labels can connect

This balance enables agile graph modeling for evolving knowledge graphs while maintaining data quality where needed.

06

Subqueries & Post-Union Processing

Modern Cypher supports subqueries for modular query composition and complex multi-part analysis.

  • CALL subquery: Executes a nested query and unions results with the outer query
  • EXISTS subquery: Tests pattern existence for conditional logic
  • COUNT subquery: Evaluates pattern cardinality inline
  • Post-UNION processing: Applies additional filtering and aggregation after combining results

These features enable sophisticated graph analytics like comparing subgraph densities or computing conditional traversals within a single query execution.

GRAPH VS. RELATIONAL QUERY PARADIGMS

Cypher vs. SPARQL vs. SQL

A comparative analysis of the declarative query languages used for property graphs, RDF triple stores, and relational databases, highlighting their distinct data models and traversal mechanisms.

FeatureCypherSPARQLSQL

Primary Data Model

Labeled Property Graph

RDF Triple Store

Relational Tables

Standardization Body

ISO/GQL (openCypher)

W3C

ISO/IEC 9075

Core Atomic Structure

Nodes, Relationships, Properties

Subject-Predicate-Object Triples

Rows and Columns

Pattern Matching Syntax

ASCII-art graph patterns

Graph patterns in WHERE clause

Table expressions in FROM clause

Native Recursive Traversal

Variable-Length Path Queries

Schema Flexibility

Schema-optional

Schema-optional

Schema-mandatory

Join Mechanism

Relationship traversal

Triple pattern join

Foreign key JOIN

Index-Free Adjacency

CYPHER QUERY LANGUAGE

Frequently Asked Questions

Clear, technical answers to the most common questions about the Cypher graph query language, covering syntax, use cases, and architectural considerations.

Cypher is a declarative graph query language originally developed by Neo4j for querying property graph databases, now standardized as an open specification (openCypher) and adopted across multiple graph systems. It works by using ASCII-art pattern matching to describe graph structures visually within the query syntax. A node is represented by parentheses (), a directed relationship by -[]->, and properties by curly braces {}. The query engine parses this pattern, compiles it into an execution plan, and traverses the graph to find matching subgraphs. Unlike SQL's table joins, Cypher's pattern matching directly leverages index-free adjacency, where each node physically stores pointers to its neighbors, enabling constant-time relationship traversal regardless of dataset size. This makes Cypher exceptionally efficient for path-finding queries and multi-hop relationship analysis that would require expensive recursive joins in relational databases.

Prasad Kumkar

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.