liveBook · Manning

Text2cypher

As explained in Essential GraphRAG

Text2cypher is a technique that converts natural-language questions into Cypher queries for graph-database retrieval.

Text2cypher converts natural-language questions into Cypher queries for structured graph-database retrieval. It complements similarity search when questions require traversal, aggregation, or other database-specific operations. section 4.2 section 5.1.1

Improve generated queries with:

  • Provide the graph schema and terminology mappings so the model can select valid properties and relationships. section 4.3.1
  • Add knowledge-graph-specific few-shot question-and-query pairs when the model repeats schema mistakes. section 4.3.1
  • Use specialized retrievers when generic text2cypher repeatedly fails on a narrow class of questions. section 5.1.1

Traversal instead of a property lookup

For a question about a movie’s production country, replace a query that reads m.country with a traversal from Movie to Country through PRODUCED_IN, returning c.name. section 4.3.1

Listing 4.1 Cypher query
MATCH (:Reviewer)-[r:REVIEWED]->(m:Movie)<-[:DIRECTED]-(:Director {name: 'Steven Spielberg'})
RETURN m.title, AVG(r.score) AS avg_rating
ORDER BY avg_rating DESC
LIMIT 3

Aggregates reviewer scores for Spielberg’s movies, orders them, and returns the top three. section 4.2

How Essential GraphRAG covers it

How deep it goes
Covers retrieval roles, prompting, and model choices, but defers a complete implementation workflow.
Examples
Uses movie-country traversal and Spielberg movie-rating aggregation as concrete Cypher examples.
What it assumes
Assumes a defined knowledge-graph schema and Cypher familiarity while teaching schema-error correction through examples.
What you can do after
Apply it via prompts, schema guidance, and few-shot examples to generate graph queries for user questions.
How it connects
Connects RAG, similarity search, graph databases, few-shot learning, and retriever agents.

Related concepts

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