Inferensys

Glossary

Cypher Query Language

A declarative, pattern-matching graph query language originally developed by Neo4j for the property graph model, now an open standard (openCypher) for expressing efficient graph traversals.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
DECLARATIVE GRAPH QUERYING

What is Cypher Query Language?

Cypher is a declarative, pattern-matching query language for the property graph model, enabling intuitive and efficient traversal of highly connected data.

Cypher is a declarative query language originally developed by Neo4j for the property graph model, now standardized as openCypher. Its syntax uses ASCII-art patterns like (node)-[RELATIONSHIP]->(node) to visually represent graph traversals, making complex pathfinding queries readable and expressive without requiring explicit join logic.

Unlike SPARQL for RDF, Cypher is optimized for the labeled property graph structure where both nodes and relationships can hold arbitrary key-value properties. The language supports clauses like MATCH, WHERE, and RETURN to filter and project results, enabling developers to efficiently query multi-hop connections, such as finding the shortest path between two entities in a knowledge graph.

QUERY LANGUAGE

Key Features of Cypher

Cypher is a declarative, pattern-matching query language for property graphs. Its ASCII-art syntax makes graph traversals intuitive and expressive.

01

Declarative Pattern Matching

Cypher uses an ASCII-art syntax where nodes are represented by parentheses () and relationships by arrows --> or <--. This allows developers to describe the structure of the data they want rather than the procedural steps to retrieve it.

  • Node syntax: (variable:Label {key: 'value'})
  • Relationship syntax: -[variable:TYPE]->
  • Example: MATCH (p:Patient)-[:HAS_CONDITION]->(d:Disease {code: 'E11.9'}) RETURN p.name

The query engine's cost-based optimizer determines the most efficient traversal strategy, freeing the user from manual index hinting.

02

Native Property Graph Model

Unlike RDF query languages that operate on triples, Cypher is purpose-built for the labeled property graph model. Every node and relationship can store an arbitrary set of key-value properties.

  • Nodes carry multiple labels for polymorphic typing
  • Relationships have a single type but can hold properties like since, confidence, or dosage
  • This allows rich, domain-specific modeling without the need for reification or intermediate nodes

This model aligns naturally with healthcare data, where a Patient node connects to a Medication node via a :TAKES relationship that carries start_date and dose properties.

03

Variable-Length Path Traversals

Cypher excels at expressing recursive graph traversals of unknown depth using variable-length relationship patterns. This is critical for traversing hierarchies like medical ontologies or organizational structures.

  • Syntax: -[:TYPE*min..max]->
  • Example: MATCH path = (c:Concept {code: 'SNOMED:73211009'})-[:IS_A*1..5]->(ancestor:Concept) RETURN path
  • The * quantifier finds all paths within the specified bounds
  • Built-in functions like shortestPath() and allShortestPaths() optimize common traversal patterns

This capability enables efficient subsumption reasoning over taxonomies without recursive application code.

04

Clauses for Reading, Writing, and Aggregation

Cypher provides a comprehensive set of clauses that compose into powerful data manipulation pipelines, similar to SQL but optimized for graph-shaped data.

  • MATCH: Specifies the graph pattern to search for
  • WHERE: Filters results with predicates and boolean logic
  • RETURN: Projects, aggregates, and aliases output columns
  • CREATE / MERGE: Inserts nodes and relationships; MERGE ensures idempotency
  • WITH: Chains query parts, passing results between clauses like a pipe
  • UNWIND: Expands a list into individual rows

Example aggregation: MATCH (d:Disease)<-[:HAS_CONDITION]-(p:Patient) RETURN d.name, count(p) AS patient_count ORDER BY patient_count DESC

05

openCypher Standardization

Originally developed by Neo4j, Cypher has evolved into openCypher, an open standard with a formal grammar and specification. This enables interoperability across multiple graph database vendors.

  • The openCypher project provides a reference parser, TCK (Technology Compatibility Kit), and grammar specification
  • Implementations exist beyond Neo4j, including Amazon Neptune, Memgraph, RedisGraph, and Apache Spark via Cypher for Apache Spark
  • A subset of Cypher has been mapped to GQL (ISO/IEC 39075), the new international standard graph query language
  • This standardization protects against vendor lock-in and promotes skill portability
06

Graph Projections and Graph Data Science

Cypher integrates with the Graph Data Science (GDS) library to create in-memory graph projections for high-performance analytical workloads. This bridges transactional queries with advanced algorithms.

  • Catalog projection: CALL gds.graph.project('myGraph', 'Patient', {RELATED: {orientation: 'UNDIRECTED'}})
  • Supports centrality algorithms (PageRank, Betweenness), community detection (Louvain, Label Propagation), and pathfinding (Dijkstra, A*)
  • Enables node embedding generation and graph neural network training directly from Cypher
  • Results can be written back to the graph as new node properties for downstream querying

This unification of querying and data science eliminates the need for complex ETL pipelines to external analytical tools.

CYPHER QUERY LANGUAGE

Frequently Asked Questions

Clear, concise answers to the most common technical questions about Cypher, the declarative graph query language for property graph databases.

Cypher is a declarative, pattern-matching graph query language originally developed by Neo4j for the property graph model, now standardized as openCypher. It works by allowing users to describe the visual pattern of nodes and relationships they want to match in the graph, rather than specifying the exact join algorithms required. The query engine's cost-based optimizer then compiles this ASCII-art-like pattern into an efficient execution plan, performing graph traversals that are inherently index-free and relationship-centric. This declarative approach abstracts away the complexity of pointer chasing and join logic, enabling developers to express complex traversals like variable-length paths and shortest-path calculations with concise, readable syntax.

QUERY LANGUAGE COMPARISON

Cypher vs. SPARQL vs. SQL

A technical comparison of declarative query languages for property graphs, RDF triplestores, and relational databases.

FeatureCypherSPARQLSQL

Data Model

Property Graph (nodes, relationships, properties)

RDF Triples (subject-predicate-object)

Relational Tables (rows, columns, joins)

Standardization

openCypher (open standard)

W3C Recommendation

ISO/IEC 9075

Pattern Matching

ASCII-art graph patterns

Graph patterns with triple syntax

Table joins and subqueries

Schema Flexibility

Schema-optional

Schema-optional

Schema-mandatory

Primary Clause

MATCH

SELECT

SELECT

Traversal Depth

Variable-length paths (*1..)

Property paths (*, +)

Recursive CTEs

Aggregation

COUNT, COLLECT, avg, sum

COUNT, GROUP_CONCAT, AVG, SUM

COUNT, GROUP BY, AVG, SUM

Return Format

Tabular or graph elements

Tabular or RDF graphs

Tabular only

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.