Skip to content
Arkur745Public

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

MemArk

License: MIT Python: 3.10+ Paper Number Integrity

MemArk (package memark, formerly marketed as "MemEngine") is a research-grade memory architecture for LLM agents. Instead of treating conversation history as a flat list of text chunks to search over, it organizes memory into a hierarchical graph (episodic events → summaries → concepts), retrieves by spreading activation outward from relevant concepts rather than by pure similarity search, and lets old, unused memories decay and go dormant instead of accumulating forever. The goal is a retriever that keeps an LLM agent's context window small and clean over long sessions, at a cost the project measures and reports rather than hides.


Results: the honest tradeoff

MemArk trades recall for context quality, and the gap does not close with a better encoder. On two official multi-hop QA benchmarks (HotpotQA, 2WikiMultihopQA; N=500 each, all-MiniLM-L6-v2 embeddings), against a flat Vector RAG baseline and HippoRAG:

Metric MemArk (FULL_MEMARK) Vector RAG HippoRAG
Context Compression Ratio (2Wiki) 96.42% 81.64% 35.08%
Contamination Leakage Ratio (2Wiki) 10.00% 43.16% 28.68%
Evidence Chain Completion (2Wiki)¹ 0.192 0.000 0.216
Supporting Fact Recall (2Wiki) 0.422 0.596 0.911
Supporting Fact Recall (HotpotQA) 0.369 0.575 0.812

¹ A meaningful share of MemArk's ECC score reflects Wikidata structure the 2WikiMultihopQA benchmark provides directly, aligned with what ECC measures — not general mesh density. See §1.5/§4.5 of the paper for the full caveat.

In plain terms: MemArk keeps far more of the prompt window clean and free of irrelevant or contaminating text, and is the only method that completes multi-hop evidence chains at all on 2WikiMultihopQA (0.192 vs. 0.000) — but it recalls noticeably fewer of the individual supporting facts than a well-embedded flat vector index or HippoRAG. This isn't an encoder problem: an embedding ablation in the paper shows MemArk's relational retrieval is governed by graph topology fixed at ingestion time, largely insensitive to embedding quality, while flat retrieval is almost entirely determined by it. A separate controlled comparison against LightRAG's reference implementation confirms the same pattern: MemArk contains contamination significantly better (p < 0.001), LightRAG recalls more while compressing far less.

MemArk is not presented as a general-purpose upgrade over dense or graph retrieval — it's an engineered substrate for settings where prompt purity and bounded token budgets matter more than maximizing raw recall. Full statistics, confidence intervals, and every ablation are in the paper.


Architecture

graph TD
    Agent["Cognitive Agent<br/>(memark/agent/cognitive_agent.py)"]
    Agent --> GMM["GraphMemoryManager"]
    GMM --> Neo4j[("Neo4j — graph relations<br/>(optional)")]
    GMM --> Vec[("Qdrant / FAISS — dense vectors<br/>(optional)")]
    GMM --> AE["ActivationEngine<br/>(spreading activation)"]
    AE --> LTDE["LongTermDecayEngine<br/>(salience decay & dormancy)"]
    AE --> DP["DeliberativePlanner<br/>(graph-native planning)"]
Loading
  • Tripartite hierarchy: raw episodic events are consolidated into summaries, which cluster into concept hubs — retrieval seeds on concepts and expands downward.
  • Bounded spreading activation: retrieval energy propagates outward from seed concepts through the graph, decaying with distance and gated by an allowed-concept firewall, rather than ranking every node against the query directly.
  • Salience decay & dormancy: nodes lose salience over time at class-specific rates and go dormant below a threshold, so the graph doesn't grow unbounded — dormant nodes re-activate instantly if a relevant cue reappears.
  • Zero-dependency by default: GraphMemoryManager() with no arguments runs entirely in-memory (NetworkX + local cosine similarity). Neo4j and Qdrant are optional backends that mirror the in-memory state when configured; their absence is a supported fallback, not an error path.

Full subsystem breakdowns: docs/architecture/.


Quick start

git clone https://github.com/Arkur745/MemEngine.git
cd MemEngine
pip install -r requirements.txt        # or: conda env create -f environment.yml
python examples/minimal_example.py

This runs entirely in memory — no Neo4j, Qdrant, or API keys required. It registers two episodic memories, links them into a concept/summary hierarchy, runs a decay cycle, and spreads activation outward from a seed node:

import os, sys
sys.path.insert(0, os.path.abspath("memark"))  # see note below

from engine.core.graph_manager import GraphMemoryManager
from engine.storage.memory_repository import MemoryRepository
from engine.consolidation.long_term_decay_engine import LongTermDecayEngine
from engine.retrieval.activation_engine import ActivationEngine

manager = GraphMemoryManager(neo4j_repository=None, vector_search=None)
repository = MemoryRepository(manager)

node_id = manager.create_node(node_type="episodic", summary="...", metadata={"content": "..."})
decay_stats = LongTermDecayEngine(repository).run_decay_cycle()
activation = ActivationEngine(repository).propagate_activation(start_node=repository.get_node(node_id))

The import root is engine.*/agent.*/llm.*, not memark.*, because pyproject.toml maps memark/ itself as the package directory — so it's memark/ that needs to be on sys.path, not the repo root; every script in examples/ does this same sys.path.insert at the top for that reason.

To reproduce the benchmark numbers above, compile the paper, or run the deterministic architecture-ablation suite, see README_REPRODUCE.md — it covers the full pipeline end to end, including the guardrail scripts that keep the paper's numbers honest (see below).


Repository structure

memark/         Core package: agent/, engine/, llm/, visualization/
benchmarks/     Benchmark harness, HotpotQA/2WikiMultihopQA loaders, results, baselines
docs/           Architecture docs, ADRs, diagrams, and the evaluation audit trail
paper/          LaTeX source for the accompanying paper
examples/       Minimal runnable usage examples
tests/          pytest suite
tools/          Streamlit demo app (tools/app.py)
scripts/        Paper-integrity guardrail scripts (see below)
configs/        Default and benchmark configuration JSON
datasets/       Downloaded benchmark data (gitignored, fetched automatically)
assets/         Publication-ready figures (color + print-safe grayscale)
archive/        Superseded or one-off scripts, kept for history rather than deleted

The paper

MemArk: An Ecological Retrieval Architecture for Long-Context Agent Systems

Manuscript available on request; arXiv posting pending. The LaTeX source is not part of this repository. Every result and figure the paper reports is independently reproducible from this repo's own benchmark pipeline — see README_REPRODUCE.md for how to regenerate the numbers, tables, and figures directly from benchmarks/ and assets/.


On rigor: docs/eval_audit.md

This project's evaluation pipeline went through a full internal audit, documented in docs/eval_audit.md. Several of the numbers originally reported did not survive independent re-verification, and the paper's central claim was rewritten as a result — the honest recall tradeoff described above is that rewrite. Rather than erase that process, it's kept as a permanent, public, phase-by-phase record: what was wrong, how it was found, and what replaced it.

That record is backed by an automated guardrail that runs in CI on every push (the badge at the top of this file is it): benchmarks/checks/verify_figures_use_real_data.py confirms every figure-generating function reads from benchmarks/results/** rather than plotting a hand-typed array, and scripts/check_stale_numbers.py blocklists every value already known to be fabricated or superseded, so one can't quietly reappear. (Two other checks in the same suite, check_paper_matches_results.py and check_latex_refs.py, compare against a compiled manuscript; since the paper's LaTeX source isn't part of this repository, they currently have nothing to check against and pass trivially rather than verifying anything — noted here rather than left to look more active than it is.) We'd rather show you the audit trail than pretend the first draft was right.


License

MIT — see LICENSE.

Contributions welcome — see CONTRIBUTING.md. This project follows CODE_OF_CONDUCT.md.

Citing this work

If you use MemArk in research, please cite via CITATION.cff:

@article{anonymous2026memark,
  title={MemArk: An Ecological Retrieval Architecture for Long-Context Agent Systems},
  author={Anonymous Author(s)},
  journal={arXiv preprint arXiv:2607.xxxxx},
  year={2026}
}

(The paper is currently under review; the arXiv identifier above is a placeholder until one is assigned.)

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages