Skip to main content

Kong Graph 🦍🧠

PyPI version PyPI downloads LongMemEval License: MIT Python 3.9+

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

  1. 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)
  2. 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)
  3. Pipeline (pipeline.py) — Unified store() and recall() interface.

API Server

pip install kong-graph[api]
python -m kong_graph.api

Endpoints:

  • POST /store — Store a memory
  • POST /recall — Graph + greedy recall
  • POST /store-batch — Batch store
  • GET /stats — Graph statistics
  • GET / — 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.

Metadata

Release files for kong-graph 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kong-graph 1.3.0
File Size Uploaded Provenance Actions
kong_graph-1.3.0.tar.gz 63.2 kB Without provenance Details for kong_graph-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kong-graph 1.3.0
File Interpreter ABI Platform Actions
kong_graph-1.3.0-py3-none-any.whl Python 3 none any Details for kong_graph-1.3.0-py3-none-any.whl

Total release size: 144.1 kB

Release files / kong_graph-1.3.0.tar.gz

Download URL kong_graph-1.3.0.tar.gz
Size 63.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9d8e8e24ee3cd1025a34d7339501132ba007d1ed1a5ae555274a445d9598eb10
BLAKE2b-256 checksum
How to use checksums
90f9dd619abc5b05440bcc9eab5ee847b0b4ce970d2c281edcb0de47692aec09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / kong_graph-1.3.0-py3-none-any.whl

Download URL kong_graph-1.3.0-py3-none-any.whl
Size 80.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c717efd8da23cab24f83eb1003b3568ca263be745ce188e440cb1c7e703b86b
BLAKE2b-256 checksum
How to use checksums
a7ebbb3469f43a05a69ffbe78854cb9f31828414478fda13f86872e995e274dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for kong-graph 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page