Hands-On LadybugDB Cypher
- A Comprehensive, Example-Driven Guide to Graph Querying with LadybugDB
Getting Started
What Is a Graph? — The Mental Model You Already Have
Graphs vs. Relational Databases — Why Tables Struggle with Connections
- The JOIN tax
- The “relationship table explosion”
- When relational is still the right choice
Graphs vs. Document Databases — Why Nesting Isn’t Connecting
- The problems with embedding relationships
- Side-by-side comparison
- When document databases are still the right choice
The Labeled Property Graph Model — Why Developers Love It
- The four building blocks
- Why LPG maps naturally to object-oriented code
- LPG vs. RDF — why LPG won developer hearts
- The takeaway
- 🏋️ Exercises
Chapter 0: Why LadybugDB Is a Great First Graph Database
- Zero infrastructure, instant feedback
- Schema-first teaches you to think in graphs
- Full Cypher — not a subset
- Columnar storage means fast even on a laptop
- Interoperability — connect to what you already know
- Built-in visualization
- Open source and free
- The bottom line
- 🏋️ Exercises
Chapter 0.1: Installing LadybugDB
- Command Line (CLI Shell)
- Python
- Node.js
- Rust
- Java
- Go
- C/C++
- Nightly builds
- On-disk vs. in-memory
- 🏋️ Exercises
Chapter 0.2: Ladybug Explorer — Visualize and Explore Your Graph
- Installing and launching
- The four panels
- AI-assisted query generation
- Launch options reference
- Recommended workflow for this book
- 🏋 ️ Exercises
Part I: Foundations
Chapter 1: Introduction to LadybugDB and Cypher
- What is LadybugDB?
- Cypher at a glance
- Our running example: The Agent Network
- Setting up LadybugDB
- 🏋️ Exercises
Chapter 2: Cypher Syntax Fundamentals
- Statements, clauses, and terminators
- Multi-line statements
- Comments
- Case insensitivity
- Naming rules
- Escaping reserved words
- Unicode support
- Parameters
- Reserved keywords
- Putting it all together: anatomy of a well-written query
- 🏋️ Exercises
Chapter 3: Data Types
- Numeric types
- Boolean
- String
- UUID
- NULL
- Temporal types
- SERIAL — auto-incrementing IDs
- Composite types
- BLOB
- JSON
- Logical graph types
- 🏋️ Exercises
Part II: Defining Your Graph
Chapter 4: Data Definition Language (DDL) — Creating the Schema
- Creating node tables
- Creating relationship tables
- Altering tables
- Dropping tables
- Typed graphs vs. open type graphs
- 🏋️ Exercises
Part III: Populating the Graph
Chapter 5: Creating Data — INSERT Operations
- Inserting nodes
- Inserting relationships
- General CREATE semantics
- MERGE — “get or create”
- CREATE TABLE AS — bulk creation from queries
- 🏋️ Exercises
Part IV: Querying the Graph
Chapter 6: MATCH — Pattern Matching
- Matching nodes
- Matching relationships
- Matching multiple patterns
- Equality predicates as syntactic sugar
- 🏋️ Exercises
Chapter 7: OPTIONAL MATCH
- 🏋️ Exercises
Chapter 8: WHERE — Filtering Results
- Boolean operators
- Comparison operators
- String functions in WHERE
- NULL handling in WHERE
- List membership with IN
- WHERE subquery on a relationship
- 🏋️ Exercises
Chapter 9: RETURN — Projecting Results
- Returning properties
- Return all properties with
* - RETURN *
- DISTINCT
- Group by and aggregations
- 🏋️ Exercises
Chapter 10: ORDER BY, SKIP, and LIMIT
- ORDER BY
- SKIP
- LIMIT
- Pagination pattern
- 🏋️ Exercises
Chapter 11: WITH — Intermediate Projections
- WITH for aggregation then filtering
- WITH for top-k
- Chaining WITH multiple times
- 🏋️ Exercises
Chapter 12: UNION
- UNION (removes duplicates)
- UNION ALL (keeps duplicates)
- 🏋️ Exercises
Chapter 13: UNWIND — Exploding Lists
- Basic usage
- Creating multiple nodes from a list
- UNWIND with WHERE (requires WITH)
- UNWIND nested lists
- 🏋️ Exercises
Chapter 14: Recursive Relationships and Path Queries
- Variable-length paths
- Walk, trail, and acyclic semantics
- Filtering inside recursive patterns
- Projecting intermediate properties
- Shortest path
- 🏋️ Exercises
Chapter 15: Named Paths
- Basic named path
- Extracting nodes and relationships
- Multiple named paths
- 🏋️ Exercises
Part V: Modifying the Graph
Chapter 16: SET — Updating Properties
- Update a node property
- Set to NULL (remove a value)
- Update a relationship property
- Bulk update
- RETURN after update
- 🏋️ Exercises
Chapter 17: DELETE — Removing Data
- Delete a node
- DETACH DELETE
- Delete a relationship
- Delete everything
- 🏋️ Exercises
Part VI: Advanced Query Features
Chapter 18: Subqueries — EXISTS and COUNT
- EXISTS
- COUNT subquery
- 🏋️ Exercises
Chapter 19: Expressions, Operators and Functions
- CASE expression
- Comparison operators
- Logical operators
- Numeric operators
- String operators and functions
- Date and timestamp operators
- NULL operators
- List operators
- Aggregate functions
- Casting
- Node and relationship functions
- 🏋️ Exercises
Chapter 20: Macros
- 🏋️ Exercises
Chapter 21: Transactions
- Basic transaction syntax
- Rolling back
- Transaction isolation
- 🏋️ Exercises
Part VII: Real-World Patterns
Chapter 22: Putting It All Together — Complex Queries
- Query 1: Full agent inventory with company and tools
- Query 2: Agents certified by TrustChain with their capabilities
- Query 3: Companies with legal agreements — network view
- Query 4: Find all cooperation chains from Atlas
- Query 5: Companies whose certified agents cooperate
- Query 6: Agent task load — who is overloaded?
- Query 7: Shortest cooperation path between Cipher and Dash
- Query 8: Companies reachable through legal agreements from TrustChain
- Query 9: CASE-based agent status report
- Query 10: Using UNWIND to batch-assign agents to a new task
- Query 11: Schema evolution — adding a new dimension
- Query 12: WITH pipeline — average reputation by company, then filter
- 🏋️ Exercises
Chapter 23: Typed Graphs vs. Neo4j — A Detailed Comparison
- Philosophical difference
- Why this matters for agent ecosystems
- Semantic differences
- Typed graph as ontology
- Open type graphs — best of both worlds
- 🏋️ Exercises
Chapter 24: LOAD FROM and External Data
- 🏋️ Exercises
Chapter 25: Attach/Detach External Databases
- 🏋️ Exercises
Chapter 26: The Social Graph Memory — Our Running Example Explained
- What is a social graph memory?
- Why “memory” and not just “database”?
- The social graph memory as the foundation for agentic AI
- Relationship to knowledge graphs and RAG
- 🏋️ Exercises
Chapter 27: Why Modern AI Needs Graphs
- The problem: AI systems work with strings, not things
- Vector RAG: good, but not enough
- GraphRAG: the convergence of graphs and AI
- Why graphs specifically?
- Agentic AI: where graphs become essential
- The future: graphs as the backbone of AI systems
- Connecting back to our example
- 🏋️ Exercises
Part VIII: Reference
Appendix A: Complete Schema for the Agent Network Example
Appendix B: Quick Reference — Cypher Clauses
Appendix C: Quick Reference — Data Types
Appendix D: Quick Reference — Key Differences from Neo4j
About This Book
Appendix E: Exercise Solutions
- Graph Fundamentals Solutions
- Chapter 0 Solutions
- Chapter 0.1 Solutions
- Chapter 0.2 Solutions
- Chapter 1 Solutions
- Chapter 2 Solutions
- Chapter 3 Solutions
- Chapter 4 Solutions
- Chapter 5 Solutions
- Chapter 6 Solutions
- Chapter 7 Solutions
- Chapter 8 Solutions
- Chapter 9 Solutions
- Chapter 10 Solutions
- Chapter 11 Solutions
- Chapter 12 Solutions
- Chapter 13 Solutions
- Chapter 14 Solutions
- Chapter 15 Solutions
- Chapter 16 Solutions
- Chapter 17 Solutions
- Chapter 18 Solutions
- Chapter 19 Solutions
- Chapter 20 Solutions
- Chapter 21 Solutions
- Chapter 22 Solutions
- Chapter 23 Solutions
- Chapter 24 Solutions
- Chapter 25 Solutions
- Chapter 26 Solutions
- Chapter 27 Solutions