Skip to content

Natural-language-to-Cypher querying

Definition

Natural-language-to-Cypher is the pattern where an LLM, given relevant graph context retrieved for a user's plain-language question, generates a precise Cypher query plus a human-readable explanation — so the graph's exactness is available without anyone learning the query language.

Explanation

Graph queryability is only as useful as the number of people who can write traversals, and Cypher fluency is the adoption barrier. The pattern removes it with a two-step pipeline: retrieve the graph elements (nodes, edges, schema fragments) relevant to the question, then let the model compose the query against that retrieved context and explain what it does. Questions like 'which functions are most frequently called in this module?' or 'are there any unused methods?' compile to exact traversals. The division of labour is the interesting part: the LLM handles the fuzzy translation from intent to query, the graph engine handles the answer — so correctness rests on the deterministic traversal, not on the model's recall of the codebase, and the generated query is inspectable before it runs. The pattern generalises beyond code graphs to any structured store with a query language; code graphs are simply where the source demonstrates it.

Key Properties

  • Two steps: retrieve relevant graph context, then generate query + explanation
  • The LLM translates intent; the graph engine computes the answer
  • Generated queries are inspectable artifacts, auditable before execution
  • Generalises to any queryable structured store

Relationships

  • Code knowledge graph — is the access layer that makes that graph usable by people who cannot write Cypher

Applications

Making a code or data graph self-serve for a whole team; auditing model-generated queries instead of trusting model-generated answers.

Sources

  • https://www.falkordb.com/blog/code-graph/

See Also