MemoryBear README

The project's README from github.com/SuanmoSuanyangTechnology/MemoryBear. As one markdown file: README.md.

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

Memory Gaps in Multi-Agent Collaboration

Semantic Ambiguity in Reasoning

Why MemoryBear

Core Features

MemoryBear Core Features

Memory Extraction Engine

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

Graph Storage (Neo4j)

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

Keyword retrieval + semantic vector retrieval dual-engine fusion:

Memory Forgetting Engine

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

Self-Reflection Engine

Scheduled daily reflection process, mimicking human review and retrospection:

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

Architecture

MemoryBear System Architecture

Celery Multi-Queue Async Architecture (7 worker types in docker-compose):

Queue Worker Type Concurrency Purpose
memory_tasks threads 100 Memory read/write (asyncio-friendly)
memory_fast_tasks threads 32 High-frequency fast writes (dedicated queue to avoid mutual blocking)
document_tasks prefork 4 Document parsing (CPU-bound)
periodic_tasks prefork 2 Scheduled tasks, reflection engine, various scanners
workflow_trigger_tasks prefork 2 Workflow scheduled triggers
subscription_state_tasks prefork 4 Subscription state transitions (Enterprise)
subscription_email_tasks prefork 4 Subscription expiry reminder emails (Enterprise)

Additional task queues such as graphrag_tasks, reflection_tasks, and memory_heavy_tasks (GraphRAG construction, second-layer reflection/deduplication, forgetting and insight generation, and other heavy-compute tasks) work together with the standalone task scheduler celery_task_scheduler and Celery Beat.


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

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, Celery Workers, the standalone task scheduler (celery_task_scheduler), and the sandbox service. 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:

Default admin credentials:

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 (3.13+ not supported) 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:

Important: You must also add the environment variable NEO4J_PLUGINS=["apoc"] to install the APOC plugin (a hard dependency of the backend graph engine; not included in the official image by default). If configuring this via the Docker Desktop GUI is inconvenient, create the container from the command line instead:

docker run -d --name memorybear-neo4j \
  -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/<initial password, at least 8 chars> \
  -e NEO4J_PLUGINS='["apoc"]' \
  neo4j:5
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
REDIS_PASSWORD=

# 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 the PostgreSQL Database

The database connection is read automatically from the DB_* environment variables in .env (migrations/env.py builds the connection string dynamically) — no need to modify alembic.ini.

Apply all migrations to create the full schema:

alembic upgrade head

Tip: When DB_AUTO_UPGRADE=true is set in .env, the API service automatically runs alembic upgrade head on startup. Migration scripts are located in api/migrations/versions/ — make sure that directory contains migration files before running the command.

Alembic Migration Database Tables

3.5 Start the API Service

uv run -m app.main

Access API documentation at http://localhost:8000/docs

API Docs

3.6 Start Celery Workers (Optional, for async tasks)

# Memory worker (thread pool, asyncio-friendly, high concurrency)
celery -A app.celery_worker.celery_app worker -E --loglevel=info --pool=threads --concurrency=100 --queues=memory_tasks -n memory_worker@%h

# Fast-write worker (thread pool, dedicated queue to avoid blocking normal writes)
celery -A app.celery_worker.celery_app worker -E --loglevel=info --pool=threads --concurrency=32 --queues=memory_fast_tasks -n memory_fast_worker@%h

# Document parsing worker (prefork, CPU-bound)
celery -A app.celery_worker.celery_app worker -E --loglevel=info --pool=prefork --concurrency=4 --queues=document_tasks --max-tasks-per-child=100 -n document_worker@%h

# Periodic tasks worker (reflection engine, various scanners)
celery -A app.celery_worker.celery_app worker -E --loglevel=info --pool=prefork --concurrency=2 --queues=periodic_tasks --max-tasks-per-child=50 -n periodic_worker@%h

# Workflow trigger worker
celery -A app.celery_worker.celery_app worker -E --loglevel=info --pool=prefork --concurrency=2 --queues=workflow_trigger_tasks --max-tasks-per-child=50 -n workflow_trigger_worker@%h

# Beat scheduler
celery -A app.celery_worker.celery_app beat --loglevel=info

# Task scheduler service (enqueue rate limiting and admission control)
python -m app.celery_task_scheduler

Tip: The above are the core workers. For a full deployment (including GraphRAG, subscription/notification, and other Enterprise-edition queue workers), docker-compose up -d is recommended.

4. Frontend Web Application

4.1 Install Dependencies

cd web
npm install

Note: In a corporate intranet, run npm run install:private to install the private component @redbear/memory-brick (use npm run install:private:dev in development). On the public internet, the script auto-detects the environment and skips silently, without affecting startup.

4.2 Update API Proxy Configuration

Edit web/vite.config.ts and point the /api proxy target to the backend API service (the frontend dev server runs on port 5175 by default):

proxy: {
  '/api': {
    target: 'http://127.0.0.1:8000',  // Backend API address — change to your actual deployment address
    changeOrigin: true,
  },
}

4.3 Start the Frontend Service

npm run dev
Frontend Start Frontend UI

5. Initialize the System

# Initialize the database and obtain the super admin account
curl -X POST http://127.0.0.1:8000/api/setup

Super admin credentials:

6. Full Startup Checklist

Step 1  Clone the repository
Step 2  Start base services (PostgreSQL / Neo4j / Redis / Elasticsearch)
Step 3  Configure .env environment variables
Step 4  Run alembic upgrade head to initialize the database
Step 5  uv run -m app.main to start the backend API
Step 6  npm run dev to start the frontend
Step 7  curl -X POST http://127.0.0.1:8000/api/setup to initialize the system
Step 8  Log in to the frontend with the admin account

Tech Stack

| Layer | Technol

MemoryBear (SuanmoSuanyangTechnology/MemoryBear)

Searching Database…

What is this?MemoryBear is an AI memory system that gives AI agents human-like memory: instead of just storing knowledge statically, it perceives, extracts, associates and forgets information over time.
Is this a library I import, or a full service I deploy?It's a self-hosted backend service, not a library: a FastAPI server plus Celery workers and a separate web frontend, exposing a management API (/api) and a service API (/v1) that other apps call.
How do I get it running?Easiest path is Docker Compose: install Docker Desktop, start the base services (PostgreSQL, Neo4j, Redis, Elasticsearch) separately, then run docker-compose up -d for the API, Celery workers, scheduler and sandbox. A fully manual step-by-step install is also documented.
What infrastructure do I need before installing it?Python 3.12 (3.13+ isn't supported yet) and Node.js 20.19+/22.12+ for the frontend, plus PostgreSQL 13+, Neo4j 4.4+, Redis 6.0+, and Elasticsearch 8.x as backing services.
Any install pitfalls I should watch for?Neo4j needs the APOC plugin enabled manually via the NEO4J_PLUGINS=["apoc"] environment variable — it's a hard dependency of the graph engine that isn't included in the official Neo4j image by default.
How does MemoryBear compare to Mem0, Zep or LangMem?In the reported benchmarks, MemoryBear's graph version reaches about 75% overall accuracy, beating Mem0, Zep and LangMem across all tested task categories; even its non-graph vector version already outperforms the best full-text retrieval baseline (around 72.9%).
How does the forgetting mechanism actually work?Each piece of knowledge gets a memory-strength score that rises with usage and decays over time; once it drops below a threshold the item passes through dormancy, decay and clearance stages, keeping redundant knowledge under 8% of the total.
What are the default login credentials after setup?The seeded super-admin account is [email protected] with password adminpassword.
What powers the hybrid search?It fuses Elasticsearch keyword matching with BERT-based semantic vector search, which the project reports gives 92% retrieval accuracy, about 35% higher than either method alone.
What are similar projects?m_flow, utopia, MemOS, LightRAG, flowsint, FalkorDB, -AI-, semantica
Size
123.7 MB
Stars
7.7K
Age
1y
Commits · 90 Days