You’re building a knowledge graph. Maybe it’s for an AI agent’s memory, a recommendation engine, or a semantic search layer. The first instinct? Spin up Neo4j, configure a separate server, learn Cypher, manage another piece of infrastructure.

But what if you didn’t have to?

GraphDuck: Graph Modeling in DuckDB makes a bold claim: you can model sophisticated graph structures -- hypergraphs, ontologies, triple stores, even full AI agent memory systems -- inside DuckDB, without a separate graph database.

The Problem with Dedicated Graph Databases

Graph databases promise index-free adjacency and blazing traversals. But for most real-world knowledge graphs -- the ones powering your RAG pipeline, your agent’s episodic memory, your domain ontology -- you’re not traversing billions of edges in real time. You’re running analytical queries over structured relationships that fit comfortably in memory.

That means you’re paying the infrastructure tax of a separate database for a feature you rarely need.

Seven Ways a Duck Serves Graphs

The book demonstrates that graphs are fundamentally relations. SQL has always been able to represent them -- we just forgot how. Chapter 21 lays out seven distinct representations of graphs in pure SQL:

  1. 1.

    Adjacency tables -- the classic edge list with properties

  2. 2.

    RDF triples -- subject-predicate-object for semantic web compatibility

  3. 3.

    Named graphs -- partitioned subgraphs with provenance tracking

  4. 4.

    Bipartite edge-node pattern -- edges promoted to first-class entities

  5. 5.

    Hypergraphs -- n-ary relationships connecting arbitrary sets of nodes

  6. 6.

    Edges-as-resources -- edges that can themselves be endpoints of other edges

  7. 7.

    Datalog-style facts -- logic programming meets relational storage

Each of these works in DuckDB today, with recursive CTEs for traversal, window functions for analytics, and array operations for property bags. And with the DuckPGQ extension, you get SQL/PGQ standard syntax and Cypher queries on top.

One Database, One Schema, One Connection

Here’s what the GraphDuck approach gives you:

  • Hybrid search in one engine -- combine vector similarity (HNSW indexes) with graph traversals in a single query

  • No server to manage -- DuckDB is embeddable, runs in-process, perfect for AI agents and edge deployments

  • Privacy-first -- your knowledge graph stays local, no data leaving your machine

  • SQL you already know -- start with familiar queries, graduate to Cypher when pattern matching gets complex

  • Analytical power -- DuckDB’s columnar engine is built for the aggregations, joins, and set operations that dominate real graph workloads

What the Book Covers

GraphDuck takes you from zero to a complete graph-powered AI memory system across 21 chapters organized in six parts:

Part I -- Foundations. Directed graphs, adjacency lists, edge properties, recursive CTEs, graph algorithms, and an introduction to Cypher via DuckPGQ.

Part II -- Advanced Structures. Ontologies and taxonomies, subgraph extraction, hypergraphs for n-ary relationships, and metagraphs where edges become nodes.

Part III -- Knowledge Systems. Semantic spacetime graphs with temporal reasoning, RDF triple stores in SQL, and vector indexes for embedding-based retrieval.

Part IV -- AI Agent Memory. Memory design patterns, agentic memory architectures (episodic, semantic, procedural), and hybrid RAG pipelines with reciprocal rank fusion.

Part V -- Applications. Promise graphs for probabilistic relationships, bridging relational and graph worlds, data pipeline integration, and the complete GraphDuck Memory architecture.

Part VI -- Perspectives. A critical look at when you actually need a graph database (spoiler: less often than you think), with case studies and an honest comparison of embeddable alternatives.

Every chapter includes working, executable code examples -- pure SQL first, then DuckPGQ/Cypher, with Python integration throughout.

Who This Book Is For

  • Data engineers who want graph capabilities without graph database overhead

  • AI/ML engineers building RAG systems, agent memory, or knowledge-augmented applications

  • Full-stack developers adding semantic layers to their applications

  • Researchers exploring graph algorithms, knowledge representation, or hybrid retrieval

The Core Philosophy

Graphs are a model, not a database. SQL is sufficient. Embeddable wins. Schema is ontology.

You don’t need a specialized graph database. You need SQL, Python, and careful domain thinking. The duck handles the rest.


Get the book: GraphDuck: Graph Modeling in DuckDB on Leanpub

Originally published on Sovereign Agentic AI on Substack.