$ show SuanmoSuanyangTechnology/MemoryBear
MemoryBear is a production-oriented, multi-tenant AI agent platform whose core differentiator is a cognitive-inspired persistent memory system for LLM applications. The code — not the README — shows a full SaaS stack: a FastAPI backend (~60 domain controllers), a React/TypeScript admin console, an identity/auth service, an API gateway, a dedicated RAG knowledge service, and a Rust seccomp sandbox for code execution. The memory subsystem is the heart: pipelines extract statements, triplets, entities, emotions, preferences, and implicit habits from conversations into a Neo4j knowledge graph (projected to Elasticsearch through a transactional outbox), with ACT-R-inspired forgetting/reinforcement scheduling, LLM reflection/dedup, BERT scene-boundary detection, and hybrid retrieval at query time. This is an application, not a data-research repo, although the memory-science algorithms (forgetting curves, emotion classification, value ranking) are shipped as product features rather than research artifacts.
The LLM identified 6 files worth highlighting for reuse:
Lease-based outbox consumer that projects Neo4j memory graph mutations into Elasticsearch with project-then-ack ordering, bounded in-place retries, lease-loss cancellation, and terminal failure states. It solves the dual-write problem between a transactional store and a search index without double-ES-write hazards. The consumer/repository/producer split is cleanly separated from domain logic and could be extracted into any event-driven service needing reliable at-least-once projections.
Backend-agnostic object storage interface with discriminated config types for local filesystem, S3, MinIO, and Aliyun OSS, plus bucket auto-creation and signed URL generation for local storage. It is published as a standalone package with a single factory entry point, making it directly reusable in any Python service that must support swappable file storage without leaking provider-specific APIs.
Standalone AST-based script that enforces import boundaries across Python packages: it scans forbidden root imports, flags import-time initialization of heavy clients (create_engine, boto3.client, redis.Redis, Elasticsearch), detects factory calls, and renders violations with precise file/line locations. A reusable architectural gate for any multi-package Python monorepo trying to prevent accidental layer violations in CI, not coupled to this repo's runtime code.
Per-runtime seccomp syscall allowlists for Python and Node.js code execution inside a Rust sandbox, paired with Landlock path restrictions and zygote-worker pooling. Building a correct syscall allowlist for a language runtime is notoriously hard (dynamic loaders, JIT, threads all require specific syscalls), and this isolated crate demonstrates that craft in a form that a security engineer could port to another sandbox project.
Composable permission policy classes (Superuser, Owner, Tenant, RoleBased, WorkspaceMember, SameTenantSuperuser, SelfAccess) that combine into authorization rules for a multi-tenant platform. The policy-permission separation is clean, self-contained, and unit-testable; it could be lifted into any multi-tenant API that needs declarative access control beyond simple role checks.
Delimiter-aware structured stream splitting that chunks documents while protecting image blocks, code fences, and table regions from being broken mid-structure. It is duplicated byte-for-byte in mem-knowledge/src/rag/, which confirms proven utility across services. The algorithm is non-obvious text-processing engineering — naive splitting destroys markdown/code/table integrity in RAG pipelines — and it is decoupled enough to drop into any chunking pipeline.