DEV Community

Cover image for Graph RAG on the database you already run: meet Drivine
Jasper Blues
Jasper Blues

Posted on Edited on

Graph RAG on the database you already run: meet Drivine

If you want graph RAG, you usually get told to stand up a graph database first. Drivine takes the other road: bring the graph to the database you already run.

Here's the four-and-a-half-minute version (with captions):

What Drivine is

Drivine is an open-source graph database client for TypeScript, Python and the JVM. It comes as three libraries:

  • Drivine for Node.js and TypeScript: npm install @liberation-data/drivine, with a NestJS module, or without Nest.
  • drivine-python: pip install drivine. It's async first, with a sync API generated from the async one.
  • drivine4j for Kotlin and Java: org.drivine:drivine4j, with Spring Boot support and a code-generated DSL.

All three share one storage format. A graph written by any of them is read, stamped and checked the same way by the others, so a Python service and a Kotlin service can work on the same store.

Compose views, not models

A person can play many roles. So instead of one big model that has to serve every use case, you declare a view for each one:

  • @NodeFragment maps one node.
  • @GraphView composes fragments, and the relationships between them, from a @Root.

Drivine writes the statement that loads the whole view, with everything related to it, in one round trip. Saves are one statement too. There's no lazy loading and no session cache to keep warm.

On top of that sits a typed query DSL: filters, ordering, keyset paging and index advice. Its references come from your own classes, or from code generated from them (KSP on the JVM, stubs in Python).

When you'd rather write the query yourself, the persistence manager takes plain Cypher.

Cypher on every store

This is the part I'm proudest of. Drivine supports:

  • Neo4j, Memgraph, FalkorDB and Amazon Neptune, which run your Cypher as written;
  • Postgres, Oracle and SQLite, where Drivine compiles your Cypher to SQL. It works over two tables, one of nodes and one of relationships, and gives back the same rows.
MATCH (p:Person)-[:KNOWS]->(friend:Person)
WHERE p.name = $name
RETURN friend.name AS name
ORDER BY name
Enter fullscreen mode Exit fullscreen mode

The same statement runs on a graph engine or on the Postgres you already have in production. The compiler is checked against a shared Cypher spec, which pins the rows each statement gives on Neo4j, Postgres, Oracle and SQLite. All three libraries run the same spec. (SQLite is drivine4j's for now.)

That's what "graph RAG on any database" means: you build the AI app's knowledge graph in the database your team already operates, backs up and trusts. Vector search comes along too, through pgvector on Postgres.

Try it

  • Docs and quick starts: drivine.org. They say you can be up and running in five minutes.
  • Star or file an issue on GitHub: TypeScript · Python · JVM

Drivine is a community project by Liberation Data, and drivine4j is the graph client behind Embabel, agentic AI for the JVM. I'd love to hear what you build with it, and which database you'd run it on.

Top comments (0)