liveBook · Manning

Cypher

As explained in Data Analysis with LLMs

A Cypher query is a declarative statement written in Cypher that requests or manipulates graph data.

Cypher is a declarative query language for finding and manipulating graph data. A natural-language question can be translated into Cypher, then executed by a graph database such as Neo4j. section 5.1 section 5.4.3

Simple Cypher queries combine two core operations:

  • MATCH describes a node-and-relationship pattern to find and assigns matched elements to variables. section 5.4.3
  • RETURN specifies the properties or calculated values produced from the matched pattern. section 5.4.3
  • Patterns can constrain node labels, properties, relationship types, and relationship direction. section 5.4.3

Finding movies starring Tom Cruise

MATCH (p:Person {name: 'Tom Cruise'})-[:ACTED_IN]->(m:Movie) RETURN m.title The pattern finds a Person with the specified name, follows an ACTED_IN relationship to a Movie, and returns each movie title. Replacing the returned title with count(*) counts the matching movies. section 5.4.3

A language model needs the natural-language question, the target language, and the database structure—such as node labels, relationship types, and property keys—to generate a useful Cypher query. Generated queries still require checking because translation is not guaranteed to be correct. section 5.1 section 5.4.4

Figure 5.1 A natural language query interface translates questions in natural language into formal queries, taking into account the data structure. Formal queries are then processed on data by a specia- lized tool, generating a query result.
figure

Follow the workflow from a natural-language question to a structure-aware Cypher query and then to a specialized query result. section 5.1

How Data Analysis with LLMs covers it

How deep it goes
Explains MATCH, RETURN, labels, properties, relationships, and direction through simple examples, while deferring full language coverage.
Examples
Demonstrates Person and Movie nodes, ACTED_IN relationships, Tom Cruise filtering, returned titles, and result counting.
What it assumes
Assumes a graph schema containing labels, relationships, and properties, while teaching basic Cypher syntax from simple patterns.
What you can do after
Evaluate/understand simple Cypher queries and inspect queries generated from natural-language questions.
How it connects
Connects graph databases, Neo4j, language models, prompts, data structure, and SQL-based structured-data analysis.

Also explained in

Compare how 4 books explain Cypher →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Analysis with LLMs. The section links point to the parts of the book it draws on.