Skip to main content

M-flow builds semantic memory layers that help LLMs reason over your data with structured knowledge graphs.

Project description

M-flow

A memory engine that focuses on reasoning and association.

M-flow 是一款重构检索架构、侧重推理与联想的记忆引擎。

Quick Start · Architecture · 架构详解(中文) · Examples · OpenClaw Skill · Contact

Tests Python License


What is M-flow?

M-flow is not a vector database or a RAG framework. It is a cognitive memory engine — a system that doesn't just store text, but understands it, distilling incoming knowledge into structured layers and weaving them into the right place of a persistent architecture.

Where traditional retrieval matches queries by surface similarity, M-flow reasons through relationships — tracing connections, weighing context, and reaching answers the way cognition does.

Most AI memory systems fall into two categories:

  • Context Window — The model re-reads everything from scratch. Exhaustive, linear, forgetful.
  • Similarity Search — External memory exists, but retrieval is surface-level — matching by vector shape, blind to structure. Approximate, lossy.

M-flow introduces a third paradigm: a Cognitive Engine where memory becomes a mind. A query at any granularity finds a precise anchor, then expands outward — surfacing related context and associative content across different levels of detail.

How It Works

M-flow organizes knowledge into a four-level Cone Graph — a layered hierarchy from abstract summaries to atomic facts:

Level What it captures Query example
Episode A bounded semantic focus — an incident, decision process, or workflow "What happened with the tech stack decision?"
Facet One dimension of that Episode — a topical cross-section "What were the performance targets?"
FacetPoint An atomic assertion or fact derived from a Facet "Was the P99 target under 500ms?"
Entity A named thing — person, tool, metric — linked across all Episodes "Tell me about GPT-4o" → surfaces all related contexts

Retrieval is graph-routed: the system casts a wide net across all levels, projects hits into the knowledge graph, propagates cost along every possible path, and scores each Episode by its tightest chain of evidence. One strong path is enough — the way a single association triggers an entire memory.

For the full technical deep-dive, see Retrieval Architecture | 检索架构详解(中文)

Benchmark

Dataset: LoCoMo-10 (10 conversations, 1541 questions) · Retrieval: EpisodicRetriever · Answer LLM: gpt-5-mini · Judge LLM: gpt-4o-mini

System LLM-Judge Top-K
M-flow 81.8% 10
Cognee Cloud 79.4% 10
Zep Cloud 73.4% 10
Mem0ᵍ (published) 68.5%
Supermemory Cloud 64.4% 10
Cat Type M-flow
4 Single-hop 87.6%
2 Temporal 79.4%
1 Multi-hop 75.2%
3 Open-domain 58.3%

Category mapping per snap-research/locomo Issue #27. Full results, reproduction scripts, and methodology for all systems: mflow-benchmarks

Features

Episodic + Procedural memory Hierarchical recall for facts and step-by-step knowledge
5 retrieval modes Episodic, Procedural, Triplet Completion, Lexical, Cypher
50+ file formats PDFs, DOCX, HTML, Markdown, images, audio, and more
Multi-DB support LanceDB, Neo4j, PostgreSQL/pgvector, ChromaDB, KùzuDB, Pinecone
LLM-agnostic OpenAI, Anthropic, Mistral, Groq, Ollama, LLaMA-Index, LangChain
Precise summarization Preserves all factual details (dates, numbers, names) at the cost of lower compression — RAG context will be longer but more accurate
MCP server Expose memory as Model Context Protocol tools for any IDE
CLI & Web UI Interactive console, knowledge graph visualization, config wizard

Retrieval modes: Episodic is the primary retrieval mode — it uses graph-routed Bundle Search for best accuracy and is used in all benchmarks. Triplet Completion is a simpler vector-based mode suited for customization and secondary development. See Retrieval Architecture for details.

Quick Start

One-Command Setup (Docker)

git clone https://github.com/FlowElement-ai/m_flow.git && cd m_flow
./quickstart.sh

The script checks your environment, configures API keys interactively, and starts the full stack (backend + frontend). On Windows, use .\quickstart.ps1.

Install via pip

pip install mflow-ai         # or: uv pip install mflow-ai
export LLM_API_KEY="sk-..."

Install from Source

git clone https://github.com/FlowElement-ai/m_flow.git && cd m_flow
pip install -e .             # editable install for development

Run

import asyncio
import m_flow


async def main():
    await m_flow.add("M-flow builds persistent memory for AI agents.")
    await m_flow.memorize()

    results = await m_flow.search("How does M-flow work?")
    for r in results:
        print(r)


asyncio.run(main())

CLI

mflow add "M-flow builds persistent memory for AI agents."
mflow memorize
mflow search "How does M-flow work?"
mflow -ui          # Launch the local web console

Architecture Overview

┌───────────────┐     ┌───────────────┐     ┌───────────────┐
│  Data Input   │────▶│    Extract    │────▶│   Memorize    │
│  (50+ formats)│     │  (chunking,   │     │  (KG build,   │
│               │     │   parsing)    │     │  embeddings)  │
└───────────────┘     └───────────────┘     └───────┬───────┘
                                                    │
                      ┌───────────────┐     ┌───────▼───────┐
                      │    Search     │◀────│     Load      │
                      │  (graph-routed│     │   (graph +    │
                      │  bundle search│     │  vector DB)   │
                      └───────────────┘     └───────────────┘

Project Layout

m_flow/              Core Python library & API
├── api/             FastAPI routers (add, memorize, search, …)
├── cli/             Command-line interface (`mflow`)
├── adapters/        DB adapters (graph, vector, cache)
├── core/            Domain models (Episode, Facet, FacetPoint, …)
├── memory/          Memory processing (episodic, procedural)
├── retrieval/       Search & retrieval algorithms
├── pipeline/        Composable pipeline tasks & orchestration
├── auth/            Authentication & multi-tenancy
├── shared/          Logging, settings, cross-cutting utilities
└── tests/           Unit & integration tests

m_flow-frontend/     Next.js web console
m_flow-mcp/          Model Context Protocol server
mflow_workers/       Distributed execution helpers (Modal, workers)
examples/            Runnable example scripts
docs/                Architecture & design documents

Development

git clone https://github.com/FlowElement-ai/m_flow.git && cd m_flow
uv sync --dev --all-extras --reinstall

# Test
PYTHONPATH=. uv run pytest m_flow/tests/unit/ -v

# Lint
uv run ruff check . && uv run ruff format .

See CONTRIBUTING.md for the full contributor guide.

Deployment

Docker

docker compose up                       # Backend only
docker compose --profile ui up          # Backend + frontend
docker compose --profile neo4j up       # Backend + Neo4j

MCP Server

cd m_flow-mcp
uv sync --dev --all-extras
uv run python src/server.py --transport sse

Testing

PYTHONPATH=. pytest m_flow/tests/unit/ -v        # ~963 test cases
PYTHONPATH=. pytest m_flow/tests/integration/ -v  # Needs .env with API keys

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines, and our Code of Conduct for community standards.

License

M-flow is licensed under the Apache License 2.0.

Copyright 2026 Junting Hua

Licensed under the Apache License, Version 2.0.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mflow_ai-0.3.3.tar.gz (3.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mflow_ai-0.3.3-py3-none-any.whl (3.3 MB view details)

Uploaded Python 3

File details

Details for the file mflow_ai-0.3.3.tar.gz.

File metadata

  • Download URL: mflow_ai-0.3.3.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mflow_ai-0.3.3.tar.gz
Algorithm Hash digest
SHA256 284aadc48d0aa24a7ed782fb92717666adce94c51837bde130399e24528bbbbb
MD5 624a19a3ef4b33f910131d233d5a9bbb
BLAKE2b-256 a1c1f58a5c5c9de895027560ad801f3f00e64f189b9a7205d7d5308969b4e003

See more details on using hashes here.

File details

Details for the file mflow_ai-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: mflow_ai-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mflow_ai-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24720c857dfeed145162836a3ab7f8dcf70739781ccb868f146d2e1345c5736e
MD5 8d55e4ac9c2d044ddcc8ae2fca3f076f
BLAKE2b-256 c760afcd615f5631917ffe50b90a222e83f31400c6fef90bbbb64e34d9994436

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page