How flowelement-ai/m_flow works
1. Repository shape
- This is a Python-first memory/RAG platform with multiple entrypoints: the m_flow library/package, a FastAPI backend, a CLI (mflow), a Next.js frontend (m_flow-frontend), an MCP server (m_flow-mcp), and optional distributed workers (mflow_workers).
- The backend is the system of record; the frontend and MCP server are thin clients over it.
2. Core domain model
- The central knowledge structure is a cone graph: Episode → Facet → FacetPoint → Entity.
- Episodes are the primary retrieval bundle; Facets and FacetPoints hold progressively finer evidence; Entities bridge memory across episodes.
- There is also a separate procedural memory track for reusable workflows, preferences, and rules.
3. Ingestion path
- Input can come from files, text, documents, web URLs, audio/image assets, or examples/scripts.
- Ingestion flows through shared loaders and chunkers, document classification, optional coreference resolution, then memory-building pipelines that create graph nodes/edges and embeddings.
- The pipeline is designed around dataset-scoped memory, so content is routed into the correct tenant/dataset before persistence.
4. Memory construction
- Episodic memory is built in m_flow/memory/episodic, which handles sentence splitting, routing, normalization, entity matching, facet refinement, and writing graph objects.
- Procedural memory is built separately in m_flow/memory/procedural, with governance, safety, versioning, validation, and repair steps.
- These are not just different views of the same data; they are separate processing pipelines with different extraction logic and storage semantics.
5. Retrieval path
- Queries enter through the search/retrieval layers and are routed to one of several modes: episodic, procedural, triplet completion, lexical, or Cypher.
- The key architecture is graph-routed bundle search: vector or lexical search finds candidate anchors, then graph propagation scores the strongest evidence path through the cone graph.
- Final answers are assembled from the returned memory bundle, typically by an LLM layer using retrieved context.
6. Persistence and infrastructure abstraction
- Storage is intentionally pluggable. There are adapters for:
- Graph DBs: Kùzu, Neo4j, Neptune
- Vector DBs: LanceDB, ChromaDB, pgvector, Milvus, Pinecone
- Cache: filesystem or Redis
- Relational persistence: SQLAlchemy-backed DBs for auth, pipeline state, and metadata
- This means the architecture is built around backend interfaces rather than one fixed database.
7. Backend API surface
- The FastAPI backend is organized by domain routers: add, memorize, ingest, search, graph, datasets, users/auth, settings, pipeline, maintenance, prune, playground, procedural, responses, and sync.
- This makes the backend a hub that exposes operational memory workflows, not just query endpoints.
- The API also supports health, config, UI bootstrapping, and multi-step pipeline orchestration.
8. Auth, tenants, and dataset boundaries
- m_flow/auth implements users, roles, tenants, permissions, and dataset-level ACLs.
- Access control is enforced around dataset operations and search/ingest flows, so memory is partitioned by principal + tenant + dataset rather than being globally shared.
- This is a major architectural boundary because it determines what data can be ingested, retrieved, or deleted by a caller.
9. Async execution and distributed work
- Long-running work is handled by the pipeline system in m_flow/pipeline, which tracks runs, tasks, concurrency, progress, and remote dispatch.
- mflow_workers provides separate worker processes for queued graph persistence / memory-node saving, with Modal support and queue-based execution.
- This separates request/response API handling from heavy ingestion and persistence workloads.
10. Frontend
- m_flow-frontend is a Next.js app that acts as the operator console: dashboard, memorize/ingest pages, retrieval views, graph visualization, settings, user management, setup wizard, and playground.
- It uses a client API layer, React Query/provider wrappers, and websocket-driven UI pieces for live progress and task feedback.
- The frontend does not own business logic; it visualizes and drives backend workflows.
11. MCP server and external integrations
- m_flow-mcp exposes memory operations through the Model Context Protocol, so IDEs/agents can call the system as tools.
- Core dependencies like LLM providers, embeddings, and storage backends are abstracted behind adapter layers, allowing OpenAI/Anthropic/Mistral/Ollama-style integrations without changing the core memory pipeline.
- Face-recognition-based routing is an optional external integration used by the Playground to map conversation streams to the right dataset.
12. Cross-cutting system services
- Configuration is env-driven and supported by templates, presets, migrations (alembic), and Docker/Helm packaging.
- Shared utilities cover logging, tracing, rate limiting, file storage, loaders, chunking, and observability, all of which support the main ingestion/retrieval loops.
- The repo also includes extensive tests/examples, which reflect the architecture’s emphasis on multi-backend support, retrieval correctness, and deployment portability.
Main entry points: api Backend API · episodic Episodic Memory · procedural Procedural Memory · retrieval Retrieval
Components 18
App Surfaces
User-facing and integration entrypoints.
- m_flow · Main library and system entrypoint for memory, retrieval, and platform services.
m_flow - Frontend · Operator console for ingest, search, graph visualization, settings, setup, and user management.
m_flow-frontend - MCP Server · Model Context Protocol surface for agent and IDE integrations.
m_flow-mcp - Workers · Queued persistence workers for graph and memory-node saving.
mflow_workers
Backend API
FastAPI routers and operational service endpoints.
- Backend API · Operational hub exposing ingest, search, graph, datasets, users, and maintenance workflows.
m_flow/api - Auth · Users, roles, tenants, permissions, and dataset-scoped access control.
m_flow/auth - Pipeline · Run/task tracking, concurrency, progress, and remote dispatch for long-running work.
m_flow/pipeline - Search API · Search methods, access-control-aware query handling, and result logging.
m_flow/search
Core Memory
Domain models and memory construction pipelines.
- Episodic Memory · Builds cone-graph memory from text and documents: routing, normalization, entities, facets, and writes.
m_flow/memory/episodic - Procedural Memory · Separately governs reusable procedures with safety, validation, versioning, and repair.
m_flow/memory/procedural - Domain Model · Episode, Facet, FacetPoint, Entity, Procedure, and related memory entities.
m_flow/core/domain/models - Ingestion · Shared loaders, document classification, chunking, web scraping, and dataset routing.
m_flow/ingestion - Coreference · Optional coreference resolution and normalization before memory building.
m_flow/preprocessing/coreference
Retrieval
Query routing, ranking, and answer assembly.
- Retrieval · Search orchestration across episodic, procedural, lexical, triplet, and Cypher modes.
m_flow/retrieval
Infrastructure
Pluggable storage, LLM, loaders, and shared services.
- Storage · Graph persistence, episode metadata, node indexing, pruning, and data deletion.
m_flow/storage - Adapters · Pluggable graph, vector, cache, relational, and dataset database adapters.
m_flow/adapters - LLM Layer · Provider abstractions, prompts, tokenizers, extraction, and rate limiting for model calls.
m_flow/llm - Shared Infra · Loaders, file storage, chunking engines, tracing, logging, cache, and observability.
m_flow/shared
Connections 27
- Backend API → Auth: enforces · Applies principal, tenant, role, and dataset boundaries.
- Backend API → Pipeline: orchestrates · Starts and monitors long-running ingestion and maintenance runs.
- Backend API → Ingestion: ingests via · Accepts files, text, URLs, and media for dataset-scoped processing.
- Backend API → Search API: serves · Exposes query and retrieval endpoints to clients.
- Backend API → Episodic Memory: builds · Routes memorization requests into episodic memory construction.
- Backend API → Procedural Memory: extracts · Supports procedural extraction and upkeep workflows.
- Search API → Retrieval: uses · Delegates ranking and bundle assembly to retrieval engine.
- Retrieval → Episodic Memory: queries · Performs graph-routed bundle search over episodic memory.
- Retrieval → Procedural Memory: queries · Handles procedural recall and trigger-based injection.
- Episodic Memory → Domain Model: writes · Creates Episode, Facet, FacetPoint, Entity, and edges.
- Procedural Memory → Domain Model: writes · Stores procedures, steps, context packs, and versions.
- Ingestion → Coreference: optionally uses · Runs coreference and normalization before memory extraction.
- Ingestion → Shared Infra: loads with · Uses shared loaders, chunkers, file storage, and scraping utilities.
- Episodic Memory → Storage: persists through · Writes graph objects, metadata, and indices.
- Procedural Memory → Storage: persists through · Writes validated procedural artifacts and state.
- Storage → Adapters: abstracts over · Uses pluggable graph, vector, cache, and relational backends.
- Retrieval → Adapters: searches via · Depends on vector and graph backends for candidate discovery and traversal.
- LLM Layer → Episodic Memory: extracts for · Supports sentence splitting, entity matching, facet refinement, and summarization.
- LLM Layer → Procedural Memory: extracts for · Supports governance, validation, repair, and procedure compilation.
- Frontend → Backend API: calls · Uses backend APIs and websocket feedback for operator workflows.
- MCP Server → Backend API: proxies · Wraps backend memory operations as MCP tools.
- Workers → Storage: persists · Handles queued graph persistence and memory-node saving.
- Workers → Pipeline: executes · Consumes remote or queued tasks from pipeline orchestration.
- m_flow → Backend API: contains · Library package includes the backend application surface.
- m_flow → Retrieval: contains · Core query and answer assembly logic lives in the package.
- m_flow → Episodic Memory: contains · Episodic memory pipeline is part of the core package.
- m_flow → Procedural Memory: contains · Procedural memory pipeline is part of the core package.