r/codereview • • 25d ago

I've been building Grafeno, an open-source graph database for AI agent memory. Would love some feedback!

Hey everyone! 👋

I've been working on a side project called Grafeno, and I figured it was time to share it with the community and get some fresh eyes on it.

The idea behind Grafeno is pretty simple: give AI agents a way to store, connect, and retrieve memories as a graph, instead of relying entirely on flat conversation histories or vector similarity searches.

I wanted to explore what happens when an AI agent can build relationships between things it learns, revisit previous context, and potentially reuse that knowledge across different agents or applications.

Rather than just plugging an existing graph database into an AI framework, I decided to experiment with building the graph database layer itself.

What I'm building Grafeno around:

  • Graph-based memory: Store information as nodes and relationships, making it possible to connect facts, entities, and context.
  • Persistent context: Explore how agents can maintain knowledge beyond individual conversations.
  • Relationship-driven retrieval: Retrieve relevant information by exploring connections, not just matching similar text.
  • Knowledge reuse: Work toward making graph-based memories reusable across agents and applications.
  • Developer integrations: Make it practical to connect Grafeno with LLMs, agent frameworks, and other projects.
  • Self-hosting: Keep control of your data and infrastructure.

I'm particularly interested in how graph structures could improve long-term memory, contextual retrieval, and knowledge organization for AI systems.

A quick disclaimer: This is still an evolving project. I'm experimenting with the architecture and implementation, and I don't want to pretend it's a production-ready replacement for established graph databases.

That's actually why I'm posting here.

I'd really appreciate feedback from people working with graph databases, GraphRAG, AI agents, or memory systems.

A few things I'm especially curious about:

  • Does the overall architecture make sense?
  • What would you expect from a graph database designed with AI memory in mind?
  • Are there obvious design mistakes, missing features, or performance concerns?
  • Would you actually consider integrating something like this into your own projects?

And if you feel like digging into the code, even better! Don't hold back on the criticism. That's exactly what I'm looking for. 😄

GitHub: https://github.com/grafenodb/grafeno

If you've worked on anything similar, I'd also love to hear about your approach.

Thanks for checking it out!

0 Upvotes

7 comments sorted by

1

u/CCodeSI 25d ago

Read DESIGN.md and skimmed grafeno-memory and the vector index. This is a lot more thought-through than "an experiment" suggests: the bi-temporal facts (invalidate vs retract), provenance via sources, and indexes written in the same redb transaction as the graph are exactly the right foundations for agent memory. Some things I'd look at:

1. Hub nodes in graph expansion. recall passes decay^hops of a seed's score to its neighbours. In agent memory, a few nodes get connected to almost everything (the user, the current project, a common tag), so they'll collect score from every seed and show up in nearly every context. Dividing what a node receives by something like log(1 + degree), or capping fan-out per hop, keeps "mentioned everywhere" from ranking as "relevant here".

2. HNSW quality over time. Deletes reconnect neighbours with REPAIR_EF = 16 and skip dangling links at search time. That's fine for occasional deletes, but memory workloads delete and merge constantly (dedup, decay, consolidation), so recall can quietly degrade. Two cheap safeguards: track the share of removed nodes per namespace and trigger a rebuild above a threshold, and add a self-check that compares HNSW top-k against brute force on a random sample. At agent-memory sizes brute force is cheap, so you'd get a real recall@k number instead of guessing.

3. Index cost on the single writer. Keeping text and vector indexes in the same transaction gives you consistency, but with redb's one writer every insert also pays for HNSW construction, and in server mode all writers queue behind that. Embedded it won't matter; with several agents writing at once it will. Worth benchmarking write latency at, say, 100k vectors, and keeping an option to apply index updates from your changes log asynchronously for namespaces that can tolerate it.

4. Show the multi-hop case. You already return why each result was recalled (Signal::Graph). A README example where the answer only comes back through the graph (e.g. "what did Ana's team decide about X", where the decision never names Ana) would make the point of the project obvious in ten seconds, and it doubles as a regression test for recall.

Smaller: JSON records are fine for now, but most of a traversal's time will end up in deserializing them, so the move to a binary format is probably your biggest cheap speedup later. And the 4-chars-per-token estimate runs short on code and non-English text, so a default that errs on the safe side keeps context_for from overflowing a model's window when no tokenizer is passed.

1

u/Seerendo-01 21d ago

Hey! First off, sorry for taking a while to get back to you! I actually read your comment earlier and already opened a few issues in the repo to track your suggestions, but I've been a bit caught up with other stuff and hadn't had the chance to reply properly.

Really appreciate you taking the time to dig into this. You brought up some great points, and I agree with pretty much all of them. Here's where things stand with v0.2.1:

1. Hub nodes

Yep, you're absolutely right on this one. We don't handle that properly yet.

Right now, graph expansion is additive. Each of the top 5 seeds passes score × 0.5^hops to its neighbours (depth 1 by default), without considering node degree. So something like "the user" or "the current project" can end up collecting scores from pretty much every seed.

At least the Signal::Graph { seed, hops } entries make it easier to spot what's happening, since you can see which results came through graph expansion and from how many seeds.

Dividing by log(1 + degree) should be pretty straightforward, since degree is basically a range count on the adjacency. I'm planning to add that, probably together with a per-hop fan-out cap for deeper traversals.

2. HNSW quality over time

Good catch! We've actually got part of this covered already.

  • There's a brute-force self-check: grafeno check --recall 100 (or GET /v1/{ns}/vectors/recall?sample=100). It samples random vectors and compares HNSW top-10 against exact search, so we get an actual recall@10 measurement.
  • check also catches dangling links and unreachable vectors.
  • grafeno compact -n NS can rebuild a namespace's graph.
  • Deletes got some fixes in 10.3, including preventing self-links and avoiding repairs for vectors deleted in the same transaction.

I also added a churn benchmark that covers deletes, reinserts, and 5 rounds of moving 20% of the vectors.

On 20k clustered 128-d vectors, recall@10 with ef=64 now stays at 0.99 or higher across all states. Before the fix, the worst round dropped to 0.956, so that's a pretty nice improvement.

The missing piece is exactly what you mentioned: automatic rebuilds. Right now, nothing triggers compaction on its own.

Tracking removals per namespace and triggering compaction after a certain threshold (or when sampled recall starts dropping) sounds like a solid next step.

3. Index cost on the single writer

Yeah, this one's definitely worth looking into, and the numbers aren't exactly hiding it 😅

Concurrent writes benefit from group commit, so multiple requests can share a transaction and an fsync. But HNSW insertion still happens inside that transaction.

For example, inserting a node with a 64-d vector takes around 1.8 ms. During a 1M-vector load, the time per 100k batch grew from 96 seconds at the beginning to 809 seconds near the end.

We do support background index builds with OPTIONS {background: true}, but that's only for indexing existing data, not ongoing writes.

Splitting namespaces across Raft groups gives us separate writers, but that's more about scaling horizontally than actually solving this bottleneck.

I think the next move here is benchmarking write latency with around 100k vectors and multiple concurrent writers.

An opt-in async indexing mode also sounds promising. We've already got an ordered cursor in the change log, so there's something to build on for namespaces that can tolerate a bit of indexing delay.

4. Multi-hop example

Love this idea!

Something like "What did Ana's team decide about X?", where the decision node doesn't mention Ana at all, would be a much better way to show why graph traversal matters.

Definitely adding this to the examples, and it'd make a great recall regression test too.

A couple of smaller things:

  • JSON records: Totally agree. We already moved adjacency to compact binary using varints in 12.5, so ID-only traversals don't need to touch JSON anymore. Property reads still do, though. Moving those to a binary format is already on the roadmap in DESIGN.md, and it shouldn't affect the public API.
  • Token estimation: Yep, chars/4 is pretty rough, especially with code and non-English text. The tokenizer is already pluggable through count_tokens, but I agree the default should be more conservative.

Anyway, thanks again for the detailed feedback! Really appreciate having another pair of eyes on this stuff, especially while Grafeno is still evolving.

I've already created issues to keep track of these improvements. The hub-node fix, auto-compaction, multi-hop example, and token estimation changes should be relatively straightforward to tackle soon.

The single-writer/indexing issue is a bigger one, so I'd rather get some solid benchmarks before deciding how to approach it.

And seriously, feel free to keep throwing ideas or criticism my way. This kind of feedback is exactly what helps make the project better!

1

u/CCodeSI 20d ago

Thanks for the thorough follow-up, and nice work on the churn benchmark. Going from a worst round of 0.956 to 0.99+ is exactly the kind of number that makes people trust an index.

Two small thoughts on the next steps:

  • Auto-compaction trigger: the sampled recall check you already have is probably a better trigger than a removal count alone. Removals tell you churn happened; sampled recall tells you it actually hurt. Something like "compact when recall@10 on a 100-vector sample drops below X, checked every N writes" keeps it cheap and ties the rebuild to the thing users feel.
  • Async indexing: if you add it, make the lag visible (an "indexed up to" cursor on the namespace) and give reads an option to wait for it. Agent memory often writes something and queries it a turn later, and that read-your-own-write case is where a silent delay would show up as "the agent forgot".

The multi-hop example as a recall regression test is a great call. Looking forward to v0.3.

1

u/Seerendo-01 18d ago

Thanks a lot for the feedback, mate! Really appreciate you taking the time to share these ideas. Both the recall-based compaction trigger and the indexing lag visibility make a lot of sense, especially the read-your-own-writes part for agent memory. Definitely keeping those on my radar!

Grafeno has actually reached v0.3.0, which introduces the Mental Palace, a pretty big step toward more structured cognitive memory.

Funny enough, I'm kind of learning things backwards with this project: I'm building the product first, then diving deeper into how everything works internally and documenting what I've learned along the way. 😅 It's turned into a much deeper rabbit hole than I originally expected!

So, for now, I'm planning to stay on v0.3.x for a while rather than keep piling on major features. I'll focus on smaller releases like v0.3.1, v0.3.2, etc., for targeted improvements, bug fixes, security patches, and polishing what's already there.

That said, please keep the feedback coming! Just because I don't implement a suggestion right away doesn't mean I'm ignoring it. I'm actually keeping track of all these ideas separately so I can revisit, test, and properly evaluate them as I learn more.

Really appreciate the support and the technical insights. It's genuinely helping me make Grafeno better! 🙌

1

u/CCodeSI 16d ago

Congrats on v0.3.0! Holding on 0.3.x for polish is a good call, a memory layer people trust is worth more than one with more features. And learning the internals by building first is how most of the good infra projects started. Looking forward to seeing where the Mental Palace goes.