Home / Companies / Neo4j / Blog / Post Details
Content Deep Dive

Hey LLM, you’re using OPTIONAL MATCH wrong. Here’s the Cypher that actually works.

Blog post from Neo4j

Post Details
Company
Date Published
Author
Adam Cowley
Word Count
1,750
Company Posts That Month
21
Language
English
Hacker News Points
-
Post removed?
No
Summary

The blog post by Adam Cowley critiques the frequent misuse of the OPTIONAL MATCH clause in Cypher queries, particularly by large language models (LLMs), which can lead to inefficiencies like row multiplication and a lack of clear output structure. He highlights that while LLMs can generate executable Cypher, they often produce suboptimal queries for complex data retrieval. Cowley suggests replacing OPTIONAL MATCH with more efficient Cypher patterns such as list comprehensions and COLLECT {} subqueries, which avoid unnecessary row multiplication and provide clearer, more performant code. He also emphasizes the importance of understanding when OPTIONAL MATCH is truly necessary, advocating for native graph patterns that express intentions more directly. For developers who wish to refine their skills, he recommends GraphAcademy's free courses on Cypher that cover essential building blocks, subqueries, and query optimization techniques.

Trends Found in this Post
Trend Post Mentions Total Month Mentions Posts Companies MoM
LLM 8 6,078 960 218 +18%
Developer Experience 1 482 254 106 +18%
Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.