cuba-memorys 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cuba-memorys might be problematic. Click here for more details.
- cuba_memorys-0.3.0/PKG-INFO +405 -0
- cuba_memorys-0.3.0/README.md +386 -0
- cuba_memorys-0.3.0/pyproject.toml +36 -0
- cuba_memorys-0.3.0/rust/.cargo/audit.toml +23 -0
- cuba_memorys-0.3.0/rust/.dockerignore +24 -0
- cuba_memorys-0.3.0/rust/.gitignore +21 -0
- cuba_memorys-0.3.0/rust/Cargo.lock +3235 -0
- cuba_memorys-0.3.0/rust/Cargo.toml +66 -0
- cuba_memorys-0.3.0/rust/Dockerfile +81 -0
- cuba_memorys-0.3.0/rust/README.md +241 -0
- cuba_memorys-0.3.0/rust/deny.toml +68 -0
- cuba_memorys-0.3.0/rust/examples/bench_handlers.rs +140 -0
- cuba_memorys-0.3.0/rust/scripts/download_model.sh +43 -0
- cuba_memorys-0.3.0/rust/scripts/migrate_v3.sql +30 -0
- cuba_memorys-0.3.0/rust/src/cognitive/density.rs +75 -0
- cuba_memorys-0.3.0/rust/src/cognitive/dual_strength.rs +42 -0
- cuba_memorys-0.3.0/rust/src/cognitive/hebbian.rs +78 -0
- cuba_memorys-0.3.0/rust/src/cognitive/mod.rs +8 -0
- cuba_memorys-0.3.0/rust/src/cognitive/prediction_error.rs +220 -0
- cuba_memorys-0.3.0/rust/src/constants.rs +198 -0
- cuba_memorys-0.3.0/rust/src/db.rs +117 -0
- cuba_memorys-0.3.0/rust/src/embeddings/mod.rs +3 -0
- cuba_memorys-0.3.0/rust/src/embeddings/onnx.rs +358 -0
- cuba_memorys-0.3.0/rust/src/graph/centrality.rs +106 -0
- cuba_memorys-0.3.0/rust/src/graph/community.rs +319 -0
- cuba_memorys-0.3.0/rust/src/graph/mod.rs +5 -0
- cuba_memorys-0.3.0/rust/src/graph/pagerank.rs +137 -0
- cuba_memorys-0.3.0/rust/src/handlers/alarma.rs +66 -0
- cuba_memorys-0.3.0/rust/src/handlers/alma.rs +241 -0
- cuba_memorys-0.3.0/rust/src/handlers/cronica.rs +490 -0
- cuba_memorys-0.3.0/rust/src/handlers/decreto.rs +57 -0
- cuba_memorys-0.3.0/rust/src/handlers/eco.rs +135 -0
- cuba_memorys-0.3.0/rust/src/handlers/expediente.rs +138 -0
- cuba_memorys-0.3.0/rust/src/handlers/faro.rs +475 -0
- cuba_memorys-0.3.0/rust/src/handlers/forget.rs +109 -0
- cuba_memorys-0.3.0/rust/src/handlers/jornada.rs +48 -0
- cuba_memorys-0.3.0/rust/src/handlers/mod.rs +66 -0
- cuba_memorys-0.3.0/rust/src/handlers/puente.rs +289 -0
- cuba_memorys-0.3.0/rust/src/handlers/remedio.rs +55 -0
- cuba_memorys-0.3.0/rust/src/handlers/vigia.rs +273 -0
- cuba_memorys-0.3.0/rust/src/handlers/zafra.rs +134 -0
- cuba_memorys-0.3.0/rust/src/lib.rs +13 -0
- cuba_memorys-0.3.0/rust/src/main.rs +60 -0
- cuba_memorys-0.3.0/rust/src/protocol.rs +315 -0
- cuba_memorys-0.3.0/rust/src/schema.sql +119 -0
- cuba_memorys-0.3.0/rust/src/search/cache.rs +121 -0
- cuba_memorys-0.3.0/rust/src/search/confidence.rs +72 -0
- cuba_memorys-0.3.0/rust/src/search/mod.rs +5 -0
- cuba_memorys-0.3.0/rust/src/search/rrf.rs +161 -0
- cuba_memorys-0.3.0/rust/tests/e2e_all_tools.py +834 -0
- cuba_memorys-0.3.0/rust/tests/integration.rs +165 -0
- cuba_memorys-0.3.0/rust/tests/smoke_test.rs +192 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cuba-memorys
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Development Status :: 4 - Beta
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
8
|
+
Classifier: License :: Other/Proprietary License
|
|
9
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Summary: Persistent memory for AI agents — knowledge graph MCP server with Hebbian learning, RRF fusion search, GraphRAG, and anti-hallucination grounding. 13 tools, PostgreSQL, sub-millisecond handlers.
|
|
14
|
+
Keywords: mcp,memory,knowledge-graph,hebbian,ai-agent,anti-hallucination,pagerank,model-context-protocol
|
|
15
|
+
License: CC-BY-NC-4.0
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
18
|
+
|
|
19
|
+
<!-- mcp-name: io.github.LeandroPG19/cuba-memorys -->
|
|
20
|
+
# Cuba-Memorys
|
|
21
|
+
|
|
22
|
+
[](https://github.com/LeandroPG19/cuba-memorys/actions/workflows/ci.yml)
|
|
23
|
+
[](https://rust-lang.org)
|
|
24
|
+
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
|
25
|
+
[](https://github.com/LeandroPG19/cuba-memorys/releases/tag/v0.3.0)
|
|
26
|
+
[](https://postgresql.org)
|
|
27
|
+
[](https://modelcontextprotocol.io)
|
|
28
|
+
[](https://github.com/LeandroPG19/cuba-memorys)
|
|
29
|
+
[](https://github.com/LeandroPG19/cuba-memorys)
|
|
30
|
+
|
|
31
|
+
**Persistent memory for AI agents** — A Model Context Protocol (MCP) server that gives AI coding assistants long-term memory with a knowledge graph, neuroscience-inspired algorithms, and anti-hallucination grounding.
|
|
32
|
+
|
|
33
|
+
13 tools with Cuban soul. Sub-millisecond handlers. Mathematically rigorous.
|
|
34
|
+
|
|
35
|
+
> [!IMPORTANT]
|
|
36
|
+
> **v0.3.0** — Deep Research V3: exponential decay replaces FSRS-6, dead code/columns eliminated, zero tech debt. 51 tests, 0 clippy warnings, audited GO.
|
|
37
|
+
|
|
38
|
+
## Demo
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<img src="assets/demo.gif" alt="Cuba-Memorys MCP demo — AI agent session with knowledge graph, hybrid search, and graph analytics" width="700" />
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Why Cuba-Memorys?
|
|
47
|
+
|
|
48
|
+
AI agents forget everything between conversations. Cuba-Memorys solves this:
|
|
49
|
+
|
|
50
|
+
- **Exponential decay** — Memories fade realistically (halflife=30d), strengthen with access
|
|
51
|
+
- **Hebbian + BCM metaplasticity** — Self-normalizing importance via Oja's rule with EMA sliding threshold
|
|
52
|
+
- **Hybrid RRF fusion search** — pg_trgm + full-text + pgvector HNSW, with entropy-routed weighting (k=60)
|
|
53
|
+
- **Knowledge graph** — Entities, observations, typed relations with Leiden community detection
|
|
54
|
+
- **Anti-hallucination grounding** — Verify claims against stored knowledge with graduated confidence scoring
|
|
55
|
+
- **REM Sleep consolidation** — Autonomous background decay + PageRank after idle
|
|
56
|
+
- **Graph intelligence** — Personalized PageRank, Leiden communities, Brandes centrality, Shannon entropy
|
|
57
|
+
- **Error memory** — Never repeat the same mistake (anti-repetition guard)
|
|
58
|
+
|
|
59
|
+
### Comparison
|
|
60
|
+
|
|
61
|
+
| Feature | Cuba-Memorys | Basic Memory MCPs |
|
|
62
|
+
| ------- | :----------: | :---------------: |
|
|
63
|
+
| Knowledge graph with typed relations | Yes | No |
|
|
64
|
+
| Exponential importance decay | Yes | No |
|
|
65
|
+
| Hebbian learning + BCM metaplasticity | Yes | No |
|
|
66
|
+
| Hybrid entropy-routed RRF fusion | Yes | No |
|
|
67
|
+
| KG-neighbor query expansion | Yes | No |
|
|
68
|
+
| GraphRAG topological enrichment | Yes | No |
|
|
69
|
+
| Leiden community detection | Yes | No |
|
|
70
|
+
| Brandes betweenness centrality | Yes | No |
|
|
71
|
+
| Shannon entropy analytics | Yes | No |
|
|
72
|
+
| Adaptive prediction error gating | Yes | No |
|
|
73
|
+
| Anti-hallucination verification | Yes | No |
|
|
74
|
+
| Error pattern detection | Yes | No |
|
|
75
|
+
| Session-aware search boost | Yes | No |
|
|
76
|
+
| REM Sleep autonomous consolidation | Yes | No |
|
|
77
|
+
| Optional ONNX BGE embeddings | Yes | No |
|
|
78
|
+
| Write-time dedup gate | Yes | No |
|
|
79
|
+
| Contradiction auto-supersede | Yes | No |
|
|
80
|
+
| GDPR Right to Erasure | Yes | No |
|
|
81
|
+
| Graceful shutdown (SIGTERM/SIGINT) | Yes | No |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Quick Start
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git clone https://github.com/LeandroPG19/cuba-memorys.git
|
|
89
|
+
cd cuba-memorys
|
|
90
|
+
|
|
91
|
+
# Start PostgreSQL
|
|
92
|
+
docker compose up -d
|
|
93
|
+
|
|
94
|
+
# Build Rust binary
|
|
95
|
+
cd rust
|
|
96
|
+
cargo build --release
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Configure your AI editor (Claude Code, Cursor, Windsurf, etc.):
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"mcpServers": {
|
|
104
|
+
"cuba-memorys": {
|
|
105
|
+
"command": "/path/to/cuba-memorys/rust/target/release/cuba-memorys",
|
|
106
|
+
"env": {
|
|
107
|
+
"DATABASE_URL": "postgresql://cuba:memorys2026@127.0.0.1:5488/brain"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The server auto-creates the `brain` database and all tables on first run.
|
|
115
|
+
|
|
116
|
+
### Optional: ONNX Embeddings
|
|
117
|
+
|
|
118
|
+
For real BGE-small-en-v1.5 semantic embeddings instead of hash-based fallback:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
export ONNX_MODEL_PATH="$HOME/.cache/cuba-memorys/models"
|
|
122
|
+
export ORT_DYLIB_PATH="/path/to/libonnxruntime.so"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Without ONNX, the server uses deterministic hash-based embeddings — functional but without semantic understanding.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## The 13 Tools
|
|
130
|
+
|
|
131
|
+
Every tool is named after Cuban culture — memorable, professional, meaningful.
|
|
132
|
+
|
|
133
|
+
### Knowledge Graph
|
|
134
|
+
|
|
135
|
+
| Tool | Meaning | What it does |
|
|
136
|
+
|------|---------|-------------|
|
|
137
|
+
| `cuba_alma` | **Alma** — soul | CRUD entities. Types: `concept`, `project`, `technology`, `person`, `pattern`, `config`. Triggers Hebbian boost + access tracking. |
|
|
138
|
+
| `cuba_cronica` | **Cronica** — chronicle | Attach observations with **dedup gate**, **contradiction detection**, **Shannon density gating**, and **adaptive PE gating V5.1**. Supports `batch_add`. |
|
|
139
|
+
| `cuba_puente` | **Puente** — bridge | Typed relations (`uses`, `causes`, `implements`, `depends_on`, `related_to`). **Traverse** walks the graph. **Infer** discovers transitive paths. blake3 dedup. |
|
|
140
|
+
|
|
141
|
+
### Search & Verification
|
|
142
|
+
|
|
143
|
+
| Tool | Meaning | What it does |
|
|
144
|
+
|------|---------|-------------|
|
|
145
|
+
| `cuba_faro` | **Faro** — lighthouse | RRF fusion (k=60) with entropy routing and pgvector. KG-neighbor expansion for low recall. `verify` mode with source triangulation. Session-aware boost. |
|
|
146
|
+
|
|
147
|
+
### Error Memory
|
|
148
|
+
|
|
149
|
+
| Tool | Meaning | What it does |
|
|
150
|
+
|------|---------|-------------|
|
|
151
|
+
| `cuba_alarma` | **Alarma** — alarm | Report errors. Auto-detects patterns (>=3 similar = warning). |
|
|
152
|
+
| `cuba_remedio` | **Remedio** — remedy | Resolve errors with cross-reference to similar unresolved issues. |
|
|
153
|
+
| `cuba_expediente` | **Expediente** — case file | Search past errors. **Anti-repetition guard**: warns if similar approach failed before. |
|
|
154
|
+
|
|
155
|
+
### Sessions & Decisions
|
|
156
|
+
|
|
157
|
+
| Tool | Meaning | What it does |
|
|
158
|
+
|------|---------|-------------|
|
|
159
|
+
| `cuba_jornada` | **Jornada** — workday | Session tracking with goals and outcomes. Goals used for decay exemption and search boost. |
|
|
160
|
+
| `cuba_decreto` | **Decreto** — decree | Record architecture decisions with context, alternatives, rationale. |
|
|
161
|
+
|
|
162
|
+
### Memory Maintenance
|
|
163
|
+
|
|
164
|
+
| Tool | Meaning | What it does |
|
|
165
|
+
|------|---------|-------------|
|
|
166
|
+
| `cuba_zafra` | **Zafra** — sugar harvest | Consolidation: exponential decay (halflife=30d), prune, merge, summarize, pagerank, find_duplicates, export, stats. |
|
|
167
|
+
| `cuba_eco` | **Eco** — echo | RLHF feedback: positive (Oja boost), negative (decrease), correct (update with versioning). |
|
|
168
|
+
| `cuba_vigia` | **Vigia** — watchman | Analytics: summary, health (Shannon entropy), drift (chi-squared), Leiden communities, Brandes bridges. |
|
|
169
|
+
| `cuba_forget` | **Forget** — forget | GDPR Right to Erasure: cascading hard-delete of entity and ALL references. Irreversible. |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Architecture
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
cuba-memorys/
|
|
177
|
+
├── docker-compose.yml # Dedicated PostgreSQL 18 (port 5488)
|
|
178
|
+
├── rust/ # v0.3.0
|
|
179
|
+
│ ├── src/
|
|
180
|
+
│ │ ├── main.rs # mimalloc + graceful shutdown
|
|
181
|
+
│ │ ├── protocol.rs # JSON-RPC 2.0 + REM daemon (4h cycle)
|
|
182
|
+
│ │ ├── db.rs # sqlx PgPool (10 max, 600s idle, 1800s lifetime)
|
|
183
|
+
│ │ ├── schema.sql # 5 tables, 15+ indexes, HNSW
|
|
184
|
+
│ │ ├── constants.rs # Tool definitions, thresholds, enums
|
|
185
|
+
│ │ ├── handlers/ # 13 MCP tool handlers (1 file each)
|
|
186
|
+
│ │ ├── cognitive/ # Hebbian/BCM, access tracking, PE gating
|
|
187
|
+
│ │ ├── search/ # RRF fusion, confidence, LRU cache
|
|
188
|
+
│ │ ├── graph/ # Brandes centrality, Leiden, PageRank
|
|
189
|
+
│ │ └── embeddings/ # ONNX BGE-small (optional, spawn_blocking)
|
|
190
|
+
│ ├── scripts/
|
|
191
|
+
│ │ └── migrate_v3.sql # v2.x -> v0.3.0 column cleanup
|
|
192
|
+
│ └── tests/
|
|
193
|
+
└── src/cuba_memorys/ # Python legacy (v1.6.0)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Performance: Rust vs Python
|
|
197
|
+
|
|
198
|
+
| Metric | Python v1.6.0 | Rust v0.3.0 |
|
|
199
|
+
| ------ | :-----------: | :---------: |
|
|
200
|
+
| Binary size | ~50MB (venv) | **7.6MB** |
|
|
201
|
+
| Entity create | ~2ms | **498us** |
|
|
202
|
+
| Hybrid search | <5ms | **2.52ms** |
|
|
203
|
+
| Analytics | <2.5ms | **958us** |
|
|
204
|
+
| Memory usage | ~120MB | **~15MB** |
|
|
205
|
+
| Startup time | ~2s | **<100ms** |
|
|
206
|
+
| Dependencies | 12 Python packages | **0 runtime deps** |
|
|
207
|
+
|
|
208
|
+
### Database Schema
|
|
209
|
+
|
|
210
|
+
| Table | Purpose | Key Features |
|
|
211
|
+
|-------|---------|-------------|
|
|
212
|
+
| `brain_entities` | KG nodes | tsvector + pg_trgm + GIN indexes, importance, bcm_theta |
|
|
213
|
+
| `brain_observations` | Facts with provenance | 9 types, versioning, `vector(384)` (pgvector), exponential decay |
|
|
214
|
+
| `brain_relations` | Typed edges | 5 types, bidirectional, Hebbian strength, blake3 dedup |
|
|
215
|
+
| `brain_errors` | Error memory | JSONB context, synapse weight, pattern detection |
|
|
216
|
+
| `brain_sessions` | Working sessions | Goals (JSONB), outcome tracking, duration |
|
|
217
|
+
|
|
218
|
+
### Search Pipeline
|
|
219
|
+
|
|
220
|
+
**Reciprocal Rank Fusion (RRF, k=60)** with entropy-routed weighting:
|
|
221
|
+
|
|
222
|
+
| # | Signal | Source | Condition |
|
|
223
|
+
|---|--------|--------|-----------|
|
|
224
|
+
| 1 | Entities (ts_rank + trigrams + importance) | `brain_entities` | Always |
|
|
225
|
+
| 2 | Observations (ts_rank + trigrams + importance) | `brain_observations` | Always |
|
|
226
|
+
| 3 | Errors (ts_rank + trigrams + synapse_weight) | `brain_errors` | Always |
|
|
227
|
+
| 4 | **Vector cosine distance (HNSW)** | `brain_observations.embedding` | pgvector installed |
|
|
228
|
+
|
|
229
|
+
**Post-fusion pipeline:** Dedup -> KG-neighbor expansion -> Session boost -> GraphRAG enrichment -> Token-budget truncation -> Batch access tracking
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Mathematical Foundations
|
|
234
|
+
|
|
235
|
+
Built on peer-reviewed algorithms, not ad-hoc heuristics:
|
|
236
|
+
|
|
237
|
+
### Exponential Decay (V3)
|
|
238
|
+
```
|
|
239
|
+
importance_new = importance * exp(-0.693 * days_since_access / halflife)
|
|
240
|
+
```
|
|
241
|
+
halflife=30d by default. Decision/lesson observations are protected from decay. Importance directly affects search ranking (score*0.7 + importance*0.3).
|
|
242
|
+
|
|
243
|
+
### Hebbian + BCM — Oja (1982), Bienenstock-Cooper-Munro (1982)
|
|
244
|
+
```
|
|
245
|
+
Positive: importance += eta * throttle(access_count, theta_M)
|
|
246
|
+
BCM EMA: theta_M = max(10, (1-alpha)*theta_prev + alpha*access_count)
|
|
247
|
+
```
|
|
248
|
+
V3: theta_M persisted in `bcm_theta` column for true temporal smoothing.
|
|
249
|
+
|
|
250
|
+
### RRF Fusion — Cormack (2009)
|
|
251
|
+
```
|
|
252
|
+
RRF(d) = sum( w_i / (k + rank_i(d)) ) where k = 60
|
|
253
|
+
```
|
|
254
|
+
Entropy-routed weighting: keyword-dominant vs mixed vs semantic queries get different signal weights.
|
|
255
|
+
|
|
256
|
+
### Other Algorithms
|
|
257
|
+
|
|
258
|
+
| Algorithm | Reference | Used in |
|
|
259
|
+
|-----------|-----------|---------|
|
|
260
|
+
| **Leiden communities** | Traag et al. (Nature 2019) | `community.rs` -> `vigia.rs` |
|
|
261
|
+
| **Personalized PageRank** | Brin & Page (1998) | `pagerank.rs` -> `zafra.rs` |
|
|
262
|
+
| **Brandes centrality** | Brandes (2001) | `centrality.rs` -> `vigia.rs` |
|
|
263
|
+
| **Adaptive PE gating** | Friston (Nature 2023) | `prediction_error.rs` -> `cronica.rs` |
|
|
264
|
+
| **Shannon entropy** | Shannon (1948) | `density.rs` -> information gating |
|
|
265
|
+
| **Chi-squared drift** | Pearson (1900) | Error distribution change detection |
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Configuration
|
|
270
|
+
|
|
271
|
+
### Environment Variables
|
|
272
|
+
|
|
273
|
+
| Variable | Default | Description |
|
|
274
|
+
|----------|---------|-------------|
|
|
275
|
+
| `DATABASE_URL` | — | PostgreSQL connection string (**required**) |
|
|
276
|
+
| `ONNX_MODEL_PATH` | — | Path to BGE model directory (optional) |
|
|
277
|
+
| `ORT_DYLIB_PATH` | — | Path to libonnxruntime.so (optional) |
|
|
278
|
+
| `RUST_LOG` | `cuba_memorys=info` | Log level filter |
|
|
279
|
+
|
|
280
|
+
### Docker Compose
|
|
281
|
+
|
|
282
|
+
Dedicated PostgreSQL 18 Alpine:
|
|
283
|
+
|
|
284
|
+
- **Port**: 5488 (avoids conflicts with 5432/5433)
|
|
285
|
+
- **Resources**: 256MB RAM, 0.5 CPU
|
|
286
|
+
- **Restart**: always
|
|
287
|
+
- **Healthcheck**: `pg_isready` every 10s
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## How It Works
|
|
292
|
+
|
|
293
|
+
### 1. The agent learns from your project
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
Agent: FastAPI requires async def with response_model.
|
|
297
|
+
-> cuba_alma(create, "FastAPI", technology)
|
|
298
|
+
-> cuba_cronica(add, "FastAPI", "All endpoints must be async def with response_model")
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### 2. Error memory prevents repeated mistakes
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
Agent: IntegrityError: duplicate key on numero_parte.
|
|
305
|
+
-> cuba_alarma("IntegrityError", "duplicate key on numero_parte")
|
|
306
|
+
-> cuba_expediente: Similar error found! Solution: "Add SELECT EXISTS before INSERT"
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### 3. Anti-hallucination grounding
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
Agent: Let me verify before responding...
|
|
313
|
+
-> cuba_faro("FastAPI uses Django ORM", mode="verify")
|
|
314
|
+
-> confidence: 0.0, level: "unknown" — "No evidence. High hallucination risk."
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### 4. Memories decay naturally
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
Initial importance: 0.5 (new observation)
|
|
321
|
+
After 30d no access: 0.25 (halved by exponential decay)
|
|
322
|
+
After 60d no access: 0.125
|
|
323
|
+
Active access resets the clock — frequently used memories stay strong.
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### 5. Community intelligence
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
-> cuba_vigia(metric="communities")
|
|
330
|
+
-> Community 0 (4 members): [FastAPI, Pydantic, SQLAlchemy, PostgreSQL]
|
|
331
|
+
Summary: "Backend stack: async endpoints, V2 validation, 2.0 ORM..."
|
|
332
|
+
-> Community 1 (3 members): [React, Next.js, TypeScript]
|
|
333
|
+
Summary: "Frontend stack: React 19, App Router, strict types..."
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Security & Audit
|
|
339
|
+
|
|
340
|
+
**Internal Audit Verdict: GO** (2026-03-28)
|
|
341
|
+
|
|
342
|
+
| Check | Result |
|
|
343
|
+
|-------|:------:|
|
|
344
|
+
| SQL injection | All queries parameterized (sqlx bind) |
|
|
345
|
+
| SEC-002 wildcard injection | Fixed (POSITION-based) |
|
|
346
|
+
| CVEs in dependencies | 0 active (sqlx 0.8.6, tokio 1.50.0) |
|
|
347
|
+
| UTF-8 safety | `safe_truncate` on all string slicing |
|
|
348
|
+
| Secrets | All via environment variables |
|
|
349
|
+
| Division by zero | Protected with `.max(1e-9)` |
|
|
350
|
+
| Error handling | All `?` propagated with `anyhow::Context` |
|
|
351
|
+
| Clippy | 0 warnings |
|
|
352
|
+
| Tests | 106/106 passing (51 unit/smoke + 55 E2E) |
|
|
353
|
+
| Licenses | All MIT/Apache-2.0 (0 GPL/AGPL) |
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Dependencies
|
|
358
|
+
|
|
359
|
+
| Crate | Purpose | License |
|
|
360
|
+
|-------|---------|---------|
|
|
361
|
+
| `tokio` | Async runtime | MIT |
|
|
362
|
+
| `sqlx` | PostgreSQL (async) | MIT/Apache-2.0 |
|
|
363
|
+
| `serde` / `serde_json` | Serialization | MIT/Apache-2.0 |
|
|
364
|
+
| `pgvector` | Vector similarity | MIT |
|
|
365
|
+
| `ort` | ONNX Runtime (optional) | MIT/Apache-2.0 |
|
|
366
|
+
| `tokenizers` | HuggingFace tokenizers | Apache-2.0 |
|
|
367
|
+
| `blake3` | Cryptographic hashing | Apache-2.0/CC0 |
|
|
368
|
+
| `mimalloc` | Global allocator | MIT |
|
|
369
|
+
| `tracing` | Structured JSON logging | MIT |
|
|
370
|
+
| `lru` | O(1) LRU cache | MIT |
|
|
371
|
+
| `chrono` | Timezone-aware timestamps | MIT/Apache-2.0 |
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## Version History
|
|
376
|
+
|
|
377
|
+
| Version | Key Changes |
|
|
378
|
+
|---------|-------------|
|
|
379
|
+
| **0.3.0** | Deep Research V3: exponential decay replaces FSRS-6, dead code/columns eliminated, SEC-002 fix, importance in ranking, embeddings storage on write, GraphRAG CTE fix, Opus 4.6 token optimization, zero tech debt. 106 tests (51 unit/smoke + 55 E2E), 0 clippy warnings. |
|
|
380
|
+
| **0.2.0** | Complete Rust rewrite. BCM metaplasticity, Leiden communities, Shannon entropy, blake3 dedup. Internal audit: GO verdict. |
|
|
381
|
+
| **1.6.0** | KG-neighbor expansion, embedding LRU cache, async embed rebuild, community summaries, batch access tracking |
|
|
382
|
+
| **1.5.0** | Token-budget truncation, post-fusion dedup, source triangulation, adaptive confidence, session-aware decay |
|
|
383
|
+
| **1.3.0** | Modular architecture (CC avg D->A), 87% CC reduction |
|
|
384
|
+
| **1.1.0** | GraphRAG, REM Sleep, conditional pgvector, 4-signal RRF |
|
|
385
|
+
| **1.0.0** | Initial release: 12 tools, Hebbian learning |
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) — Free to use and modify, **not for commercial use**.
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## Author
|
|
396
|
+
|
|
397
|
+
**Leandro Perez G.**
|
|
398
|
+
|
|
399
|
+
- GitHub: [@LeandroPG19](https://github.com/LeandroPG19)
|
|
400
|
+
- Email: [leandropatodo@gmail.com](mailto:leandropatodo@gmail.com)
|
|
401
|
+
|
|
402
|
+
## Credits
|
|
403
|
+
|
|
404
|
+
Mathematical foundations: Oja (1982), Bienenstock, Cooper & Munro (1982, BCM), Cormack (2009, RRF), Brin & Page (1998, PageRank), Traag et al. (2019, Leiden), Brandes (2001), Shannon (1948), Pearson (1900, chi-squared), Friston (2023, PE gating), BAAI (2023, BGE), Malkov & Yashunin (2018, HNSW), O'Connor et al. (2020, blake3).
|
|
405
|
+
|