MCPcopy
hub / github.com/SuanmoSuanyangTechnology/MemoryBear

github.com/SuanmoSuanyangTechnology/MemoryBear @v0.3.9 sqlite

repository ↗ · DeepWiki ↗ · release v0.3.9 ↗
12,022 symbols 53,262 edges 1,533 files 5,283 documented · 44%
README

MemoryBear Hero Banner

MemoryBear — Empowering AI with Human-Like Memory

Next-Generation AI Memory Management System · Perceive · Extract · Associate · Forget

License Python FastAPI Neo4j Gitee Sync

中文 | English

Quick Start · Installation · Core Features · Architecture · Benchmarks · Papers


Overview

MemoryBear is a next-generation AI memory system developed by RedBear AI. Its core breakthrough lies in moving beyond the limitations of traditional "static knowledge storage". Inspired by the cognitive mechanisms of biological brains, MemoryBear builds an intelligent knowledge-processing framework that spans the full lifecycle of perception → extraction → association → forgetting.

Unlike traditional memory tools that treat knowledge as static data to be retrieved, MemoryBear emulates the hippocampus's memory encoding, the neocortex's knowledge consolidation, and synaptic pruning-based forgetting — enabling knowledge to dynamically evolve with life-like properties. This shifts the relationship between AI and users from passive lookup to proactive cognitive assistance.

Papers

Paper Description
📄 Memory Bear AI: A Breakthrough from Memory to Cognition MemoryBear core technical report
📄 Memory Bear AI Memory Science Engine for Multimodal Affective Intelligence Technical report on multimodal affective intelligence memory engine
📄 A-MBER: Affective Memory Benchmark for Emotion Recognition Affective memory benchmark dataset

Why MemoryBear

Knowledge Forgetting in Single Models

  • Context window limits: Mainstream LLMs have 8k–32k token windows. In long conversations, early messages are pushed out, causing responses to lose historical context
  • Static knowledge gap: Training data is a static snapshot — it cannot absorb personalized information (preferences, history) from live interactions
  • Recency bias: Transformer self-attention weakens on long-range dependencies, overweighting recent input and ignoring earlier critical information

Memory Gaps in Multi-Agent Collaboration

  • Data silos: Different agents (consulting, after-sales, recommendation) maintain isolated memories, forcing users to repeat information
  • Inconsistent dialogue state: When switching agents, user intent and history labels are not fully passed along, causing service discontinuities
  • Decision conflicts: Agents with partial memory can produce contradictory responses (e.g., recommending products a user is allergic to)

Semantic Ambiguity in Reasoning

  • Domain jargon, colloquial expressions, and context-dependent references are not accurately encoded, leading to semantic drift in memory interpretation
  • Cross-language memory associations fail in multilingual or dialect-rich scenarios

Why MemoryBear


Core Features

MemoryBear Core Features

Memory Extraction Engine

Performs semantic-level parsing of unstructured conversations and documents to extract:

  • Core declarative information: Strips redundant modifiers, preserving subject-action-object logic
  • Structured triples: Automatically extracts entity relationships (e.g., MemoryBear → core function → knowledge extraction) as atomic units for graph storage
  • Temporal anchoring: Automatically extracts and tags timestamps, enabling time-based knowledge tracing
  • Intelligent summarization: Customizable length (50–500 words) and focus; generates concise summaries of 10-page documents in under 3 seconds

Graph Storage (Neo4j)

Graph-first architecture integrated with Neo4j, overcoming the weak relational modeling of traditional databases:

  • Supports millions of entities and tens of millions of relational edges
  • Covers 12 core relationship types: hierarchical, causal, temporal, logical, and more
  • Extracted triples sync directly to Neo4j, automatically building the initial knowledge graph
  • Interactive graph visualization with "machine-generated + human-optimized" collaborative management

Hybrid Search

Keyword retrieval + semantic vector retrieval dual-engine fusion:

  • Keyword search powered by Elasticsearch for millisecond-level exact matching of structured information
  • Semantic vector search via BERT embeddings, recognizing synonyms, near-synonyms, and implicit intent
  • Semantic retrieval expands the candidate space; keyword retrieval then performs precise filtering
  • Retrieval accuracy reaches 92%, improving 35% over single-mode retrieval

Memory Forgetting Engine

Inspired by the brain's synaptic pruning mechanism, using a dual-dimension model of memory strength and time decay:

  • Each knowledge item is assigned an initial memory strength, updated dynamically by usage frequency and association activity
  • When strength falls below threshold, knowledge enters a dormancy → decay → clearance three-stage lifecycle
  • Redundant knowledge maintained below 8%, reducing waste by over 60% compared to systems without forgetting

Self-Reflection Engine

Scheduled daily reflection process, mimicking human review and retrospection:

  • Consistency checks: Detects logical conflicts across related knowledge, flags suspicious records for human review
  • Value assessment: Evaluates invocation frequency and association contribution; reinforces high-value knowledge, accelerates decay of low-value knowledge
  • Association optimization: Adjusts relationship weights based on recent usage, strengthening high-frequency association paths

FastAPI Service Layer

Unified service architecture exposing two API surfaces:

API Type Path Prefix Auth Purpose
Management API /api JWT System config, permissions, log queries
Service API /v1 API Key Knowledge extraction, graph ops, search, forgetting control
  • Average response latency below 50ms, single instance sustaining 1000 QPS
  • Auto-generated Swagger documentation
  • Docker-ready, compatible with enterprise microservice ecosystems (CRM, OA, R&D management)

Architecture

MemoryBear System Architecture

Celery Three-Queue Async Architecture:

Queue Worker Type Concurrency Purpose
memory_tasks threads 100 Memory read/write (asyncio-friendly)
document_tasks prefork 4 Document parsing (CPU-bound)
periodic_tasks prefork 2 Scheduled tasks, reflection engine

Benchmarks

Evaluation metrics include F1 score (F1), BLEU-1 (B1), and LLM-as-a-Judge score (J) — higher values indicate better performance.

MemoryBear consistently outperforms competing systems including Mem0, Zep, and LangMem across all four task categories:

Benchmark Results

Vector version (non-graph): Achieves substantially improved retrieval efficiency while maintaining high accuracy. Overall accuracy surpasses the best existing full-text retrieval methods (72.90 ± 0.19%), while maintaining low latency at both p50 and p95 for Search Latency and Total Latency.

Vector Version Metrics

Graph version: Integrating the knowledge graph architecture pushes overall accuracy to a new benchmark (75.00 ± 0.20%), delivering performance metrics that significantly surpass all other methods.

Graph Version Metrics


Quick Start

Docker Compose (Recommended)

Prerequisites: Docker Desktop installed.

# 1. Clone the repository
git clone https://github.com/SuanmoSuanyangTechnology/MemoryBear.git
cd MemoryBear/api

# 2. Start base services (PostgreSQL / Neo4j / Redis / Elasticsearch)
# Pull and start these images via Docker Desktop first (see Installation section 3.2)

# 3. Configure environment variables
cp env.example .env
# Edit .env with your database connections and LLM API keys

# 4. Initialize the database
pip install uv && uv sync
alembic upgrade head

# 5. Start API + Celery Workers + Beat scheduler
docker-compose up -d

# 6. Initialize the system and get the admin account
curl -X POST http://127.0.0.1:8002/api/setup

Note: docker-compose.yml includes the API service and Celery Workers only. Base services (PostgreSQL, Neo4j, Redis, Elasticsearch) must be started separately.

Port info: Docker Compose defaults to port 8002; manual startup defaults to port 8000. The installation guide below uses manual startup (8000) as the example.

After startup: - API docs: http://localhost:8002/docs - Frontend: http://localhost:3000 (after starting the web app)

Default admin credentials: - Account: admin@example.com - Password: admin_password

Manual Start

Quick commands below — see Installation for detailed steps.

# Backend
cd api
pip install uv && uv sync
alembic upgrade head
uv run -m app.main

# Frontend (new terminal)
cd web
npm install && npm run dev

Installation

1. Environment Requirements

Component Version Purpose
Python 3.12+ Backend runtime
Node.js 20.19+ or 22.12+ Frontend runtime
PostgreSQL 13+ Primary database
Neo4j 4.4+ Knowledge graph storage
Redis 6.0+ Cache and message queue
Elasticsearch 8.x Hybrid search engine

2. Get the Project

git clone https://github.com/SuanmoSuanyangTechnology/MemoryBear.git

Directory Structure

3. Backend API Service

3.1 Install Python Dependencies

# Install uv package manager
pip install uv

# Switch to the API directory
cd api

# Install dependencies
uv sync

# Activate virtual environment
# Windows (PowerShell, inside /api)
.venv\Scripts\Activate.ps1
# Windows (cmd, inside /api)
.venv\Scripts\activate.bat
# macOS / Linux
source .venv/bin/activate

3.2 Install Base Services (Docker Images)

Download Docker Desktop and pull the required images.

PostgreSQL — search → select → pull

PostgreSQL Pull

PostgreSQL Container

PostgreSQL Running

Neo4j — pull the same way. When creating the container, map two required ports and set an initial password: - 7474: Neo4j Browser - 7687: Bolt protocol

Neo4j Container

Neo4j Running

Redis — same steps as above.

Elasticsearch

Pull the Elasticsearch 8.x image and create a container, mapping ports 9200 (HTTP API) and 9300 (cluster communication). For initial setup, disable security to simplify configuration:

docker run -d --name elasticsearch \
  -p 9200:9200 -p 9300:9300 \
  -e "discovery.type=single-node" \
  -e "xpack.security.enabled=false" \
  elasticsearch:8.15.0

3.3 Configure Environment Variables

cp env.example .env

Fill in the core configuration in .env:

# Neo4j Graph Database
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your-password

# PostgreSQL Database
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your-password
DB_NAME=redbear-mem

# Set to true on first startup to auto-migrate the database
DB_AUTO_UPGRADE=true

# Redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=1

# Celery
REDIS_DB_CELERY_BROKER=1
REDIS_DB_CELERY_BACKEND=2

# Elasticsearch
ELASTICSEARCH_HOST=127.0.0.1
ELASTICSEARCH_PORT=9200

# JWT Secret Key (generate with: openssl rand -hex 32)
SECRET_KEY=your-secret-key-here

3.4 Initialize th

Extension points exported contracts — how you extend this code

UploadImagesProps (Interface)
Props interface for UploadImages component
web/src/components/Upload/UploadImages.tsx
UploadImagesRef (Interface)
Ref methods exposed to parent component
web/src/components/Upload/UploadImages.tsx
ApiResponse (Interface)
API response structure with pagination metadata
web/src/components/PageScrollList/index.tsx
PageScrollListProps (Interface)
Props interface for PageScrollList component
web/src/components/PageScrollList/index.tsx
AreaLineChartProps (Interface)
* Props for the AreaLineChart component * * @interface AreaLineChartProps * @property {string} xAxisKey - Key name i
web/src/components/Charts/AreaLineChart.tsx

Core symbols most depended-on inside this repo

get
called by 2761
api/app/core/rag/utils/redis_conn.py
get
called by 2443
api/app/services/conversation_state_manager.py
info
called by 1816
api/app/core/rag/utils/redis_conn.py
get
called by 829
api/app/core/workflow/engine/variable_pool.py
filter
called by 794
api/app/core/logging_config.py
append
called by 713
api/app/core/workflow/nodes/operators.py
append
called by 622
api/app/utils/tmp_session.py
join
called by 621
api/app/core/rag/deepdoc/vision/table_structure_recognizer.py

Shape

Method 4,581
Function 4,499
Class 1,633
Interface 771
Route 538

Languages

Python76%
TypeScript24%

Modules by API surface

api/app/services/workflow_service.py165 symbols
api/app/core/workflow/nodes/operators.py93 symbols
api/app/controllers/app_controller.py89 symbols
api/app/schemas/app_schema.py88 symbols
api/app/tasks.py80 symbols
web/src/api/memory.ts76 symbols
web/src/api/application.ts69 symbols
api/app/services/app_service.py69 symbols
api/app/services/draft_run_service.py65 symbols
api/app/core/rag/deepdoc/vision/operators.py61 symbols
web/src/api/knowledgeBase.ts58 symbols
api/app/core/rag/deepdoc/parser/pdf_parser.py56 symbols

Dependencies from manifests, versioned

@antv/layout1.2.14-beta.8 · 1×
@antv/x63.0.1 · 1×
@antv/x6-react-shape3.0.1 · 1×
@codemirror/lang-cpp6.0.3 · 1×
@codemirror/lang-java6.0.2 · 1×
@codemirror/lang-javascript6.2.4 · 1×
@codemirror/lang-json6.0.2 · 1×
@codemirror/lang-python6.2.1 · 1×
@codemirror/lang-rust6.0.2 · 1×
@codemirror/state6.5.4 · 1×
@codemirror/theme-one-dark6.1.3 · 1×
@codemirror/view6.39.12 · 1×

Datastores touched

dbnameDatabase · 1 repos

For agents

$ claude mcp add MemoryBear \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact