sqlite-local-ai-memory 0.0.0-stage → 1.4.3

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.
package/.env.example ADDED
@@ -0,0 +1,66 @@
1
+ # ==============================================================================
2
+ # sqlite-local-ai-memory Configuration Template (.env)
3
+ # ==============================================================================
4
+
5
+ # Database storage path (default: ./memoria.db)
6
+ SQLITE_MEM_PATH=./memoria.db
7
+
8
+ # SQLite Engine Tuning (Optional)
9
+ # SQLITE_JOURNAL_MODE=TRUNCATE # TRUNCATE (default, safe for NFS/network/cloud mounts), or WAL (for local SSD/NVMe)
10
+ # SQLITE_BUSY_TIMEOUT=5000 # Wait time in ms before throwing SQLITE_BUSY (default: 5000)
11
+
12
+ # Primary user identity for contextual memory
13
+ MEMORY_USER_NAME=User
14
+ MEMORY_USER_ID=user_default
15
+
16
+ # ------------------------------------------------------------------------------
17
+ # API Keys & Endpoints
18
+ # ------------------------------------------------------------------------------
19
+ # Google Gemini API Key (Required if using gemini/... models or cloud embeddings)
20
+ GEMINI_API_KEY=your_gemini_api_key_here
21
+
22
+ # Local Ollama base URL (default: http://localhost:11434)
23
+ OLLAMA_URL=http://localhost:11434
24
+
25
+ # OpenRouter API Key (Optional, for openrouter/... models)
26
+ OPENROUTER_API_KEY=your_openrouter_api_key_here
27
+
28
+ # OpenAI API Key & Custom Base URL (Optional, for openai/... or vLLM/LMStudio)
29
+ OPENAI_API_KEY=your_openai_api_key_here
30
+ # OPENAI_BASE_URL=https://api.openai.com/v1
31
+
32
+ # ------------------------------------------------------------------------------
33
+ # Cognitive Roles Model Sizing (Universal PROVIDER/MODEL syntax)
34
+ #
35
+ # Supported Providers:
36
+ # - gemini/... -> Uses Google GenAI SDK (e.g. gemini/gemini-2.5-flash-lite)
37
+ # - ollama/... -> Uses local Ollama HTTP API (e.g. ollama/qwen2.5-coder:1.5b)
38
+ # - openai/... -> Uses OpenAI-compatible /v1/chat/completions (e.g. openai/gpt-4o-mini)
39
+ # - openrouter/... -> Uses OpenRouter /v1/chat/completions (e.g. openrouter/anthropic/claude-3.5-haiku)
40
+ # ------------------------------------------------------------------------------
41
+
42
+ # 1. GATEKEEPER (The Bouncer): Drops conversational chit-chat before touching APIs
43
+ # Recommended: Local Ollama mini SLM (1B-3B)
44
+ GATEKEEPER_MODEL=ollama/qwen2.5-coder:1.5b
45
+
46
+ # 2. QUERY_EXPANDER (The Librarian): Rewrites vague queries using conversational context.
47
+ # OPTIONAL: Set to "none" or leave empty to disable!
48
+ # - Disabled ("none" or empty): Instant literal search with 0 ms overhead, $0 cost, zero hallucinations.
49
+ # - Enabled (e.g. gemini/...): Resolves anaphoric references ("where was that server?") into sharp keywords.
50
+ EXPANDER_MODEL=gemini/gemini-2.5-flash-lite
51
+
52
+ # 3. NOTARY (The Clerk): Extracts atomic facts in strict structured JSON
53
+ # Recommended: Gemini Flash-Lite (or models with rock-solid Structured Output)
54
+ NOTARY_MODEL=gemini/gemini-2.5-flash-lite
55
+
56
+ # 4. SEMANTIC_ARBITER (The Auditor): Detects collisions and soft-deletes outdated facts
57
+ # Recommended: Gemini Flash-Lite (requires relational logic)
58
+ ARBITER_MODEL=gemini/gemini-2.5-flash-lite
59
+
60
+ # 5. STATE_ORCHESTRATOR (The Historian / AutoDream): Multi-hour state synthesis and 4-block triage
61
+ # Recommended: Gemini Flash-Lite (requires 4k-8k context + complex nested JSON schema)
62
+ ORCHESTRATOR_MODEL=gemini/gemini-2.5-flash-lite
63
+
64
+ # 6. EMBEDDER (The Vectorizer): Generates 768-dim dense vectors for Int8 SQLite quantization
65
+ # Recommended: Local Ollama nomic-embed-text (fallback: gemini-embedding-001)
66
+ EMBEDDER_MODEL=ollama/nomic-embed-text
package/BENCHMARKS.md ADDED
@@ -0,0 +1,93 @@
1
+ # Production Benchmarks & Telemetry: sqlite-local-ai-memory (v1.4.2)
2
+
3
+ > **Real-World Validation:** Unlike synthetic benchmarks that measure vector cosine operations in isolated loops, the following metrics were captured **in a 24/7 production environment** running as the cognitive memory engine for an autonomous WhatsApp assistant (**Maria Corsini**) and technical engineering agents (**Antigravity AGY**).
4
+
5
+ ---
6
+
7
+ ## 1. Executive Summary
8
+
9
+ | Metric | Measured Result | Operational Impact |
10
+ | :--- | :--- | :--- |
11
+ | **Idle RAM Footprint** | **0.00 MB** (In-Process SQLite) | Eliminates dedicated memory daemons (saved +3.2 GB RAM vs Qdrant/Chroma). |
12
+ | **Historical Production Lifespan** | **5+ Months** (Apr 2026 – Present) | Zero corruption, zero index drift under XFS/Linux storage. |
13
+ | **Active Fact Database Size** | **15,904 Int8 Vectors** (7,858 FTS5 docs) | Instant warm boot (<15 ms), 4.6 MB total database file on disk. |
14
+ | **Production Retrieval Hit Rate** | **97.6%** ($\ge 0.60$ Relevance) | 164 of 168 real-world conversational user queries found relevant facts. |
15
+ | **Top-Tier Retrieval Accuracy** | **94.6%** ($\ge 0.80$ Relevance) | Overwhelming majority of matches had high semantic alignment. |
16
+ | **Blank Queries (0 Hits)** | **0.0% (0 / 168)** | Zero missed retrievals across 14 consecutive days of dialogue. |
17
+ | **Average End-to-End Latency** | **989 ms** (Dual RAG + Smart Gate) | Full disambiguation via SLM + Int8 vector math + SQLite ranking. |
18
+ | **Raw SQLite Search Latency** | **< 2.1 ms** (FTS5 BM25 + Vector scan) | Sub-millisecond lookup when query is pre-computed. |
19
+
20
+ ---
21
+
22
+ ## 2. Resource Consumption: Bare-Metal SQLite vs. Traditional Vector DBs
23
+
24
+ Memory and CPU profiles measured on an Intel Core i7-4770 (Haswell) with 16 GB DDR3 RAM running Debian 12 / Proxmox VE:
25
+
26
+ ```
27
+ [Memory Footprint in Production (Idle / Standby)]
28
+
29
+ Qdrant Container (mem0 cluster):
30
+ ████████████████████████████████████████ 3,250 MB (Rust/gRPC daemon)
31
+
32
+ ChromaDB / Milvus Standalone:
33
+ ██████████████████████████ 2,100 MB (Python/C++ runtime)
34
+
35
+ sqlite-local-ai-memory:
36
+ ▏ 0 MB (Zero RAM at rest; Kernel Page Cache on-demand)
37
+ ```
38
+
39
+ ### Architectural Highlights:
40
+ * **TRUNCATE Journal Mode:** Prevents SMB/CIFS and multi-process POSIX lock corruption while reducing inode allocation overhead by 100% compared to `DELETE` mode.
41
+ * **Int8 Scalar Quantization:** 768-dimensional float32 embeddings (3,072 bytes per vector) are quantized to 8-bit signed integers (-127 to +127), reducing vector storage to **768 bytes** (a 75% memory compression) with $<1.5\%$ degradation in recall.
42
+ * **Native In-Process Execution:** Zero network serialization, zero HTTP/gRPC overhead, zero Docker bridges.
43
+
44
+ ---
45
+
46
+ ## 3. Two-Week Deep Telemetry Audit (WhatsApp Production)
47
+
48
+ * **Logging Mechanism:** Append-only JSONL event stream (`memory_telemetry.jsonl`) instrumented directly inside the `MemoryEngine` facade.
49
+ * **Period Audited:** September 9, 2026 – September 22, 2026 (14 continuous days).
50
+ * **Total Operations Processed:** **929 memory events**.
51
+ * `SAVE_FACT` (Deterministic atomic facts): **488**
52
+ * `SAVE` (Conversational compilation & noise filtering): **273**
53
+ * `SEARCH` (Live conversational RAG retrievals): **168**
54
+
55
+ ### Retrieval Score Distribution (168 Queries)
56
+
57
+ ```
58
+ Score >= 0.80 (Excellent): ███████████████████████████████████ 159 (94.6%)
59
+ Score >= 0.70 (High): █████████████████████████████████████ 160 (95.2%)
60
+ Score >= 0.60 (Relevant): ██████████████████████████████████████ 164 (97.6%)
61
+ Score < 0.60 (Discarded): █ 4 (2.4%)
62
+ Zero Matches (0 hits): 0 (0.0%)
63
+ ```
64
+
65
+ * **Mean Top Relevance Score:** **0.832 / 1.000**
66
+ * **Average Hits Returned per Query:** **4.8 facts**
67
+
68
+ ---
69
+
70
+ ## 4. The Smart Gate & Conversational Ring Buffer Benchmark
71
+
72
+ Standard vector databases fail in conversational interfaces when users speak naturally using pronouns, short confirmations, or fragmented questions. `sqlite-local-ai-memory` embeds an ephemeral RAM ring buffer (FIFO 10 turns) coupled with an automatic **Smart Gate**:
73
+
74
+ * **Smart Gate Invocation Rate:** **95.8% (161 / 168 queries)**.
75
+ * **Autonomous Disambiguation Success:** **90.5% (152 / 168 queries)**.
76
+
77
+ ### Real Production Disambiguation Samples:
78
+
79
+ | User Input in WhatsApp | Smart Gate Disambiguation | Final Retrieval Score |
80
+ | :--- | :--- | :--- |
81
+ | *"De la 45 tenemos algo?"* | `alarmas Sucursal 0045` | **0.615** (Exact store status) |
82
+ | *"Mmm revisa si alguna se reporto sin luz (AC)"* | `alarmas sin luz AC` | **0.800** (Power failure log) |
83
+ | *"y desarmadas? alguna?"* | `sucursal desarmada` | **0.900** (Security events) |
84
+ | *"te regreso algo?"* | `estado de la sucursal 0045 a las 00:34` | **0.880** (Incident report) |
85
+
86
+ ---
87
+
88
+ ## 5. Historical Robustness: 5 Months at Scale
89
+
90
+ From the central unified database (`memoria.db`):
91
+ * **15,904 Vector Entries** accumulated since April 24, 2026.
92
+ * **7,858 BM25 Indexed Documents** in `recuerdos_fts`.
93
+ * **Zero instances of `SQLITE_CORRUPT`** across unexpected power cuts, reboot cycles, or multi-client concurrent access (Node.js + Python + CLI).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.