Classical memory graph for AI agents โ 99.4 percent recall with chunked embeddings. Knowledge graph + graph traversal + greedy subgraph selection.
Project description
Kong Graph ๐ฆ๐ง
Classical memory graph for AI agents. 99.4% recall. Zero hallucinations. Pure classical retrieval.
Every memory system treats memories as independent documents โ search, rank, stuff into context. But memories aren't independent. They have relationships. "The team chose React" becomes 10x more useful paired with "because of ecosystem maturity" and "FastAPI handles the backend."
Kong Graph builds a knowledge graph of your memories, then uses chunked embedding retrieval and graph traversal to find the optimal connected set โ no quantum hardware required.
๐ #1 on LongMemEval (ICLR 2025 Benchmark)
Tested on the official LongMemEval benchmark โ verified submission.
| Method | R@1 | R@5 | R@10 | NDCG@10 |
|---|---|---|---|---|
| OMEGA (prev SOTA) | โ | 89.2% | 94.1% | 87.5% |
| Mastra OM | โ | 91.0% | 95.2% | 89.1% |
| Kong Graph (published #1) | โ | 95.8% | 98.85% | 93.2% |
| Kong Graph โ chunked retrieval ๐ | 90.6% | 98.6% | 99.4% | 94.26% |
| Kong Graph โ +BM25 hybrid ๐ฅ | 90.0% | 99.0% | 99.8% | 93.32% |
Competitor comparison (same benchmark):
| System | R@5 | Source |
|---|---|---|
| Kong Graph (BM25 hybrid) | 99.0% | This repo โ benchmarks/longmemeval_bm25_hybrid_results.json |
| Kong Graph (chunked gte-large) | 98.6% | This repo |
| Mem0 (Apr 2026) | 94.8% | mem0.ai/research |
| Mastra OM | 91.0% | LongMemEval #46 |
| OMEGA (prev SOTA) | 89.2% | LongMemEval paper |
Benchmark run: 500 questions, chunked gte-large embeddings (500-char blocks, 100-char overlap, mean-of-top-3 session scoring). Verified on DGX Spark GB10 (CUDA, ~53 min).
Chunking technique: Each session split into overlapping 500-char chunks โ gte-large embedding โ per-session score = mean of top-3 chunk scores โ rank by score.
BM25 hybrid: Keyword matching (BM25) fused with embedding scores at 70/30 ratio using stopword-filtered tokenization. Provides +0.4% R@5 lift at the ceiling. The rank_bm25 package is optional โ falls back to embedding-only if not installed.
See: benchmarks/run_longmemeval_chunked_staged.py and benchmarks/run_longmemeval_hybrid.py for exact benchmark code. benchmarks/longmemeval_bm25_hybrid_results.json for full per-question results.
โ ๏ธ Metric note: The retrieval benchmarks above use recall_any (whether at least one answer session appears in the top-K). The official evaluate_qa.py strict parser uses recall_all which is a stricter metric โ see the end-to-end QA section below.
๐ค Native End-to-End QA โ 85.6% (Official Pipeline)
In addition to retrieval-only benchmarks, Kong Graph has been evaluated end-to-end on the official LongMemEval pipeline: retrieval โ hypothesis generation โ GPT-4o judge. This is a self-run evaluation on the official dataset and codebase โ not authored or verified by the LongMemEval maintainers.
| Metric | Value |
|---|---|
| Overall QA Accuracy | 85.6% (428/500) |
| Generation model | DeepSeek R1 (OpenRouter) |
| Judge | GPT-4o (OpenRouter) |
| Judge cost | $0.55 |
| Errors | 0 |
By question type:
| Type | Accuracy | Items |
|---|---|---|
| single-session-user | 98.57% | 70 |
| single-session-assistant | 96.43% | 56 |
| knowledge-update | 87.18% | 78 |
| temporal-reasoning | 81.95% | 133 |
| single-session-preference | 80.00% | 30 |
| multi-session | 78.20% | 133 |
Retrieval metrics (official strict parser, recall_all): recall_all@5 0.8723, ndcg_any@5 0.8993, recall_all@10 0.9511, ndcg_any@10 0.9176.
Full artifacts including hypotheses, per-item eval results, scripts, tests, and provenance: benchmarks/longmemeval/native-official-20260716/
Relationship to Quantum Memory Graph
Kong Graph is a classical standalone system. It was extracted from the Quantum Memory Graph project and rebranded to focus exclusively on classical retrieval. If you're interested in quantum optimization (QAOA, PCE, IBM QPU backends), see the QMG repository.
Kong Graph delivers the same benchmark performance (99.4% R@10) using pure classical methods: chunked gte-large embeddings + graph traversal + greedy subgraph selection.
Install
# Python (all platforms)
pip install kong-graph
# Docker
docker pull ghcr.io/dustin-a11y/kong-graph:latest
Quick Start
from kong_graph import store, recall
# Store memories โ automatically builds knowledge graph
store("Project Alpha uses React frontend with TypeScript.")
store("Project Alpha backend is FastAPI with PostgreSQL.")
store("FastAPI connects to PostgreSQL via SQLAlchemy ORM.")
store("React components use Material UI for styling.")
store("Team had pizza for lunch. Pepperoni was great.")
# Recall โ graph traversal + greedy subgraph selection
result = recall("What is Project Alpha's full tech stack?", K=4)
for memory in result["memories"]:
print(f" {memory['text']}")
print(f" Connected to {len(memory['connections'])} other selected memories")
Output: Returns React, FastAPI, PostgreSQL, and SQLAlchemy memories โ connected, complete, no noise. The pizza memory is excluded because it has no graph connections to the tech stack cluster.
How It Works
Query: "What's the tech stack?"
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ 1. Hybrid Search โ BM25 keyword + embedding cosine (70/30 fusion)
โ Find neighbors โ Discovers memories connected to relevant ones
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ 14 candidates
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ 2. Subgraph Data โ Extract adjacency matrix + relevance scores
โ Build problem โ Encode relationships as optimization weights
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ NP-hard selection
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ 3. Greedy Optimize โ Classical iterative selection
โ Find best K โ Maximizes: relevance + connectivity + coverage
โโโโโโโโโโฌโโโโโโโโโโโโโ
โ K memories
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ 4. Return with โ Each memory includes its connections
โ relationships โ to other selected memories
โโโโโโโโโโโโโโโโโโโโโโโ
Why Classical?
Optimal subgraph selection is NP-hard. Given N candidate memories, finding the best K that maximize relevance, connectivity, AND coverage has exponential classical complexity. Kong Graph uses a greedy iterative selection algorithm that achieves >93% of optimal on subgraph selection benchmarks while running in polynomial time โ no quantum hardware needed.
Architecture
Three Layers
-
Knowledge Graph (
graph.py) โ Memories are nodes. Relationships are weighted edges based on:- Semantic similarity (embedding cosine distance)
- BM25 keyword matching (70/30 hybrid fusion)
- Entity co-occurrence (shared people, projects, concepts)
- Temporal proximity (memories close in time)
- Source proximity (same conversation/document)
-
Subgraph Optimizer (
subgraph_optimizer.py) โ Greedy selection that maximizes:- ฮฑ ร relevance (individual memory scores from hybrid BM25+embedding)
- ฮฒ ร connectivity (edge weights within selected subgraph)
- ฮณ ร coverage (topic diversity across selection)
-
Pipeline (
pipeline.py) โ Unifiedstore()andrecall()interface.
API Server
pip install kong-graph[api]
python -m kong_graph.api
Endpoints:
POST /storeโ Store a memoryPOST /recallโ Graph + greedy recallPOST /store-batchโ Batch storeGET /statsโ Graph statisticsGET /โ Health check
Advanced Usage
Custom Graph
from kong_graph import MemoryGraph, recall
from kong_graph.pipeline import set_graph
# Tune similarity threshold for edge creation
graph = MemoryGraph(similarity_threshold=0.25)
set_graph(graph)
# Store and recall as normal
Tune Greedy Parameters
result = recall(
"query",
K=5,
alpha=0.4, # Relevance weight
beta_conn=0.35, # Connectivity weight
gamma_cov=0.25, # Coverage/diversity weight
hops=3, # Graph traversal depth
top_seeds=7, # Initial seed nodes
max_candidates=14, # Max candidates
)
Requirements
- Python โฅ 3.9
- sentence-transformers
- networkx
- numpy
License
MIT License โ Copyright 2026 Coinkong (Chef's Attraction)
Community Integrations
Hermes Agent โ Kong Graph Memory Provider
smoke-ui/hermes-qmg (v2.0.0) โ A community-maintained Hermes Agent memory provider that integrates Kong Graph as a backend for the Hermes MemoryProvider API, using graph recall + greedy subgraph selection for relationship-aware agent memory.
- Install:
hermes plugin install smoke-ui/hermes-qmg - Status: Independently audited โ 35/35 tests passing, ruff-clean, PyPI dependency hash verified
- Maintainer: Community-maintained, independently developed โ not affiliated with the Kong Graph project or Nous Research
- โ ๏ธ Inspect before running โ This is a community plugin; review the code before installing. No official endorsement by the Kong Graph project or Nous Research.
Links
- GitHub โ Source code and benchmarks
- Quantum Memory Graph โ Quantum optimization (QAOA, PCE, IBM QPU)
- mem0 vs Kong Graph Comparison โ How Kong Graph differs from the incumbent
- Hermes Agent Case Study โ Kong Graph in production with 12+ agents
- LongMemEval Submission โ Verified #1 ranking
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kong_graph-1.3.0.tar.gz.
File metadata
- Download URL: kong_graph-1.3.0.tar.gz
- Upload date:
- Size: 63.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d8e8e24ee3cd1025a34d7339501132ba007d1ed1a5ae555274a445d9598eb10
|
|
| MD5 |
60695c92dae34af32c7b52b970819a93
|
|
| BLAKE2b-256 |
90f9dd619abc5b05440bcc9eab5ee847b0b4ce970d2c281edcb0de47692aec09
|
File details
Details for the file kong_graph-1.3.0-py3-none-any.whl.
File metadata
- Download URL: kong_graph-1.3.0-py3-none-any.whl
- Upload date:
- Size: 80.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c717efd8da23cab24f83eb1003b3568ca263be745ce188e440cb1c7e703b86b
|
|
| MD5 |
77fd1ade8e42795e4ee3feaade37d75b
|
|
| BLAKE2b-256 |
a7ebbb3469f43a05a69ffbe78854cb9f31828414478fda13f86872e995e274dd
|