An open API service indexing awesome lists of open source software.

https://github.com/deepleaper/opc-deepbrain

Pure local self-learning knowledge base. No cloud, no cost, your data stays on your machine.
https://github.com/deepleaper/opc-deepbrain

ai knowledge-base local-first ollama python self-learning sqlite

Last synced: 17 days ago
JSON representation

Pure local self-learning knowledge base. No cloud, no cost, your data stays on your machine.

Awesome Lists containing this project

README

          

> โš ๏ธ **DEPRECATED**: OPC DeepBrain has been merged into [OPC Agent](https://github.com/Deepleaper/opc-agent) v1.0.0+.
> Install pip install opc-agent to get both the Agent and DeepBrain in a single package.
> This repository is archived for reference only.

# ๐Ÿง  OPC DeepBrain

### Self-Evolving Knowledge Engine for AI Agents โ€” 6-Layer Memory That Grows With You

### AI Agent ่‡ช่ฟ›ๅŒ–็Ÿฅ่ฏ†ๅผ•ๆ“Ž โ€” 6 ๅฑ‚่ฎฐๅฟ†๏ผŒ่ถŠ็”จ่ถŠ่ชๆ˜Ž

[![PyPI version](https://img.shields.io/pypi/v/opc-deepbrain.svg)](https://pypi.org/project/opc-deepbrain/)
[![Downloads](https://img.shields.io/pypi/dm/opc-deepbrain.svg)](https://pypi.org/project/opc-deepbrain/)
[![GitHub stars](https://img.shields.io/github/stars/deepleaper/opc-deepbrain.svg)](https://github.com/deepleaper/opc-deepbrain/stargazers)
[![License](https://img.shields.io/badge/License-BSL--1.1-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://python.org)
[![Dependencies](https://img.shields.io/badge/Dependencies-0-green.svg)](#)

[Website](https://www.deepleaper.com) ยท [Quick Start](#-quick-start) ยท [API Reference](#-api-reference) ยท [vs Mem0](#-comparison)

---

## ๐Ÿ’ก Why DeepBrain?

Memory solutions like Mem0 store facts. **DeepBrain evolves knowledge.**

| Problem | Mem0 / Others | DeepBrain |
|---------|--------------|-----------|
| Memory model | Flat key-value | 6-layer evolving hierarchy |
| Quality control | None | 4-Gate validation system |
| Knowledge growth | Manual CRUD | Auto-promotion through layers |
| Dependencies | Redis, Qdrant, OpenAIโ€ฆ | **Zero** (stdlib only) |
| Storage | Cloud vectors | SQLite (100% local) |
| Self-awareness | โŒ | โœ… Meta-knowledge layer |

**DeepBrain** is a standalone, embeddable knowledge engine that gives any AI agent **long-term, self-evolving memory** โ€” in 3 lines of code, with zero dependencies.

## โœจ Key Features

- ๐Ÿ—๏ธ **6-Layer Memory Architecture** โ€” From flash memory to meta-knowledge, just like the human brain
- ๐Ÿšช **4-Gate Quality Control** โ€” Every piece of knowledge passes Relevance โ†’ Novelty โ†’ Consistency โ†’ Utility gates
- ๐Ÿ“ฆ **Zero Dependencies** โ€” Pure Python stdlib. No numpy, no torch, no API keys
- ๐Ÿ’พ **100% Local** โ€” SQLite storage. Your knowledge never leaves your machine
- ๐Ÿ”Œ **Embeddable** โ€” Drop into any Python agent framework in 3 lines
- ๐Ÿ”„ **Auto-Evolution** โ€” Knowledge automatically promotes, consolidates, and archives

## ๐Ÿš€ Quick Start

```bash
pip install opc-deepbrain
```

```python
from deepbrain import DeepBrain

# Initialize
brain = DeepBrain("./my_brain.db")

# Learn
brain.learn("User prefers concise, technical answers", source="conversation")

# Recall
results = brain.search("What communication style does the user prefer?")
print(results[0]["content"]) # โ†’ "User prefers concise, technical answers"
```

**That's it.** No API keys. No config. No cloud. 3 lines to persistent, evolving memory.

## ๐Ÿ—๏ธ 6-Layer Memory Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Layer 5: ๐Ÿ”ฎ Meta-Knowledge โ”‚
โ”‚ "I know that I know X well, but Y is uncertain"โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 4: ๐Ÿ—„๏ธ Archived โ”‚
โ”‚ Historical reference, low-access but preserved โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 3: ๐Ÿ—๏ธ Consolidated โ”‚
โ”‚ Cross-session patterns, validated over time โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 2: ๐Ÿ“š Long-Term โ”‚
โ”‚ Validated knowledge, frequently accessed โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 1: ๐Ÿ“ Short-Term โ”‚
โ”‚ Recent interactions, hours to days โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Layer 0: โšก Flash Memory โ”‚
โ”‚ Current session buffer, minutes โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ†‘ Auto-promotion based on relevance,
frequency, and validation scores
```

### How Knowledge Evolves

1. **Ingestion** โ†’ New knowledge enters Layer 0 (Flash)
2. **4-Gate Check** โ†’ Relevance, Novelty, Consistency, Utility scoring
3. **Promotion** โ†’ High-quality knowledge moves up layers over time
4. **Consolidation** โ†’ Related facts merge into coherent understanding
5. **Meta-Learning** โ†’ The system learns its own knowledge strengths/gaps

## ๐Ÿšช 4-Gate Quality Control

Every piece of knowledge must pass through 4 gates:

| Gate | Purpose | Question Asked |
|------|---------|---------------|
| ๐ŸŽฏ **Relevance** | Is this useful? | Does this relate to active contexts? |
| ๐Ÿ†• **Novelty** | Is this new? | Do we already know this? |
| โœ… **Consistency** | Does this fit? | Does it contradict existing knowledge? |
| ๐Ÿ”ง **Utility** | Is this actionable? | Can this improve future responses? |

## ๐Ÿ“– API Reference

### Core API

```python
from deepbrain import DeepBrain

brain = DeepBrain(db_path="./brain.db")

# Learn โ€” store knowledge
brain.learn(
content="FastAPI is preferred over Flask for new projects",
source="architecture-review",
namespace="tech-decisions"
)

# Recall โ€” retrieve relevant knowledge
results = brain.search(
query="Which web framework should we use?",
top_k=5
)

# Search โ€” keyword search
results = brain.search("FastAPI", namespace="tech-decisions")

# Stats โ€” memory statistics
stats = brain.stats()
print(f"Total entries: {stats['total']}")
print(f"By layer: {stats['by_namespace']}")

# Evolve โ€” trigger manual evolution cycle
brain.evolve()

```

### Embedding in Your Agent

```python
# Works with any agent framework
class MyAgent:
def __init__(self):
self.brain = DeepBrain("./agent_brain.db")

def chat(self, user_message):
# Recall relevant context
context = self.brain.search(user_message, top_k=3)

# Generate response (your LLM call here)
response = self.llm.generate(user_message, context=context)

# Learn from the interaction
self.brain.learn(
f"User asked about: {user_message}",
source="conversation"
)

return response
```

## โš–๏ธ Comparison / ๅฏนๆฏ”

| Feature | **OPC DeepBrain** | Mem0 | ChromaDB | Pinecone |
|---------|:-:|:-:|:-:|:-:|
| Memory Model | 6-layer evolving | Flat store | Vector store | Vector store |
| Quality Control | 4-Gate system | โŒ | โŒ | โŒ |
| Auto-Evolution | โœ… | โŒ | โŒ | โŒ |
| Meta-Knowledge | โœ… | โŒ | โŒ | โŒ |
| Dependencies | **0** | 5+ | 3+ | 2+ |
| Storage | SQLite (local) | Redis + Qdrant | Local/Cloud | Cloud only |
| Cloud Required | โŒ | โš ๏ธ Optional | โš ๏ธ Optional | โœ… Yes |
| Pricing | **Free** | Free/Paid | Free/Paid | Paid |
| Self-Evolving | โœ… | โŒ | โŒ | โŒ |
| Python stdlib only | โœ… | โŒ | โŒ | โŒ |

## ๐Ÿ”Œ Integrations

DeepBrain powers memory in:
- [OPC Agent](https://github.com/deepleaper/opc-agent) โ€” Local AI agent
- [Leaper Agent](https://github.com/deepleaper/leaper-agent) โ€” Global agent framework
- [Leaper Agent CN](https://github.com/deepleaper/leaper-agent-cn) โ€” China-optimized agent
- **Your project** โ€” `pip install opc-deepbrain` and go

## ๐Ÿ“„ License

[BSL-1.1](LICENSE) โ€” see LICENSE for details.

## ๐Ÿค Contributing

We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md).

๐Ÿ“ง Contact: [tech@deepleaper.com](mailto:tech@deepleaper.com)

---

**Built with โค๏ธ by [Deepleaper Technology / ่ทƒ็›Ÿ็ง‘ๆŠ€](https://www.deepleaper.com)**

*Give your AI agent a brain that evolves.*