mindforge-memory 6.5.6__tar.gz → 6.5.8__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.
- {mindforge_memory-6.5.6/mindforge_memory.egg-info → mindforge_memory-6.5.8}/PKG-INFO +11 -9
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/README.md +10 -8
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/encryption.py +8 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/mindforge.py +14 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/query.py +305 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/storage.py +136 -28
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/types.py +5 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/version.py +2 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/knowledge_graph.py +84 -3
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8/mindforge_memory.egg-info}/PKG-INFO +11 -9
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge_memory.egg-info/SOURCES.txt +1 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v568_fixes.py +1 -1
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v575_release_consistency.py +2 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v579_graph.py +22 -9
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v612_fixes.py +2 -2
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v643_fixes.py +1 -1
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v645_fixes.py +1 -1
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v646_fixes.py +1 -1
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v649_fixes.py +2 -2
- mindforge_memory-6.5.8/tests/test_v657_six_path.py +184 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/LICENSE +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/MindForge.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/claude_adapter.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/crewai_memory.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/generic_api.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/langgraph_store.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/adapters/openclaw_adapter.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/api/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/api/server.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/cli/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/cli/main.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/embedding.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/indexer.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/core/paths.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/daemon/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/daemon/server.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/mcp/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/mcp/server.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/__init__.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/categorizer.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/conflict_detector.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/connectors.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/context_window.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/event_bus.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/evolution.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/experience.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/federated.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/federated_acl.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/follow_up.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/hybrid_search.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/importer.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/integrator.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/intent_router.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/memory_compressor.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/memory_decay.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/memory_passport.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/multi_agent.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/multimodal.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/outcome_learning.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/personality.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/principled_forgetting.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/privacy.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/recall.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/session_focus.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/share_conflict.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/skill_extractor.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/skill_pack.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/timeline_viz.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge/modules/v6.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge_memory.egg-info/dependency_links.txt +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge_memory.egg-info/entry_points.txt +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge_memory.egg-info/requires.txt +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/mindforge_memory.egg-info/top_level.txt +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/pyproject.toml +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/setup.cfg +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/setup.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_core.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_security_hardening.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_trash_hard_delete.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v546_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v547_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v548_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v550_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v552_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v554_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v556_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v557_banner_insight_wal.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v557_security_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v557_webhook_sig_export.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v558_audit_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v558_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v560_decay_gc.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v560_kdf_versioning.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v560_module_coverage.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v561_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v562_p2_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v563_entry_coverage.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v563_perf_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v565_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v566_encrypted_search.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v567_security_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v569_fts_sync.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v570_coverage_expansion.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v570_drama_and_utils.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v570_encrypted_fallback.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v571_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v572_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v573_encrypted_export.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v573_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v576_bitemporal.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v576_gdpr.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v577_agent_governance.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v578_embedding.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v580_experience.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v5812_bugfixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v583_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v584_adapters.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v585_benchmark.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v586_federated_mcp.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v590_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v592_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v593_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v595_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v600_forgetting_followup.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v600_import_timeline.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v600_multi_agent_formal.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v600_outcome_passport.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v600_skillpack_evolution.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v611_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v612_cascade_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v613_integrity.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v620_growth_governance.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v630_search_explain.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v631_scrypt.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v632_explain_interfaces.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v635_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v635_integration.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v636_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v648_fixes.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v652_context_expansion.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v654_search_multi.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v655_temporal_norm.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v656_security.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v65_features.py +0 -0
- {mindforge_memory-6.5.6 → mindforge_memory-6.5.8}/tests/test_v6_ports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mindforge-memory
|
|
3
|
-
Version: 6.5.
|
|
3
|
+
Version: 6.5.8
|
|
4
4
|
Summary: AI Agent 终身记忆系统 - 四层记忆架构 · 知识图谱 · 多模态支持
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/opok-ops/MindForge
|
|
@@ -36,11 +36,13 @@ Dynamic: license-file
|
|
|
36
36
|
|
|
37
37
|
MindForge gives AI agents a persistent, structured long-term memory: a four-tier lifecycle model, knowledge graphs, hybrid retrieval, end-to-end encryption, and MCP / CLI / REST interfaces. All data stays on your machine.
|
|
38
38
|
|
|
39
|
-
> **The story** — one developer, seven months, from v1.0 (March 2026) to v6.5.
|
|
39
|
+
> **The story** — one developer, seven months, from v1.0 (March 2026) to v6.5.8: no team, no funding, 1,305 passing tests. [Read the journey →](https://opok-ops.github.io/MindForge/#developer)
|
|
40
|
+
>
|
|
41
|
+
> *Timeline note (v6.5.8):* "seven months" counts from project start (2026-03, pre-git prototyping era). Git history begins 2026-07-17 with the v5.7.x repository consolidation — earlier code lived outside this repo. The 416+ commits reflect consolidated history only.
|
|
40
42
|
|
|
41
43
|
[](https://www.python.org/downloads/)
|
|
42
44
|
[](LICENSE)
|
|
43
|
-
[](https://github.com/opok-ops/MindForge/releases)
|
|
44
46
|
[](https://github.com/opok-ops/MindForge/stargazers)
|
|
45
47
|
[](https://github.com/opok-ops/MindForge/forks)
|
|
46
48
|
[](https://github.com/opok-ops/MindForge/issues)
|
|
@@ -72,7 +74,7 @@ Install from source, then start writing and reading memories in minutes:
|
|
|
72
74
|
git clone https://github.com/opok-ops/MindForge.git
|
|
73
75
|
cd MindForge
|
|
74
76
|
pip install -e . # zero ML deps: 3-path retrieval (TF-IDF + FTS5 + fuzzy)
|
|
75
|
-
pip install -e ".[embedding]" # + vector path → full
|
|
77
|
+
pip install -e ".[embedding]" # + vector path → full 6-way hybrid retrieval
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
> Without the `embedding` extra, MindForge runs in zero-dependency mode — fully functional, but paraphrased queries may go unrecalled (no semantic path). With it, a small sentence-transformers model downloads on first vector search.
|
|
@@ -106,15 +108,15 @@ MindForge stats
|
|
|
106
108
|
- **Ten-million-character library, millisecond-class across all query types (v6.4.9)**: pathological 218→**0.4ms** (−99.8%), mixed 143→**3.0ms** (−98%), rare 6.8ms, combined 17.8ms (100k full-pipeline, clean environment). The last bottleneck — FTS5 high-frequency-phrase bm25 scoring — is now pruned query-side via trigram-df pre-check (df upper bound = min trigram df, pruned at 5% corpus size, symmetric to the TF-IDF max_df design; df served from an in-process cache — fts5vocab is a streaming virtual table, per-term probes scan it fully).
|
|
107
109
|
- **Index-blindness fix (v6.4.8)**: TF-IDF vocabulary was locked to the first 5 documents since v6.4.6 — incremental adds indexed as empty vectors (TF-IDF effectively half-dead; previous numbers carried by FTS5/fuzzy). Fixed with incremental vocabulary growth; all pipeline numbers above are now *true full-pipeline* measurements.
|
|
108
110
|
- Retrieval quality (fixed-seed, `benchmarks/quality_bench.py`, 2k entries): needle Recall@1 = 1.0, MRR = 1.0, topic Recall@1 = 1.0, noise false-recall = 0.
|
|
109
|
-
- **LoCoMo full-suite, LLM-judged (v6.5.
|
|
111
|
+
- **LoCoMo full-suite, LLM-judged (v6.5.8, 2026-11-13)**: 1,986 questions across all 10 conversations — **51.5% accuracy (≥9/10 judge score)**, 2.13× over the 24.2% pre-assembly baseline; cross-validated by two independent judges (DeepSeek 51.5% / Kimi K3.1 52.72%, Δ1.2pt); excluding the adversarial "should-refuse" bucket, **43.05%** (663/1540). Per-bucket: adversarial 93.9%, single-hop 57.8%, multi-hop 25.2%, temporal 9.6%, open-domain 10.4% — temporal evidence recall and two-hop chain retrieval are the named v6.6 targets. Data: `benchmarks/results/`, judge pipeline in `benchmarks/`.
|
|
110
112
|
- LongMemEval — interface ready, not yet run (requires external LLM API key).
|
|
111
113
|
- TF-IDF degraded mode process memory at 100k: ~700 MB. Index LRU cap: 100,000 docs (MINDFORGE_INDEX_MAX_DOCS).
|
|
112
114
|
|
|
113
115
|
## What's New
|
|
114
116
|
|
|
115
|
-
v6.1.3 – v6.5.
|
|
117
|
+
v6.1.3 – v6.5.8 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,300+ tests**.
|
|
116
118
|
|
|
117
|
-
- **v6.5.
|
|
119
|
+
- **v6.5.8 — security fix pack from dual-judge external review** (2026-11-14). Qwen4-Max (Doubao) and Kimi K3.1 independently reviewed the codebase; their overlapping findings became this release. (1) **GDPR erasure completed**: `gdpr_erase_all` now cascades to 17 tables — added `knowledge_graph` entities, `memory_snapshots`, `memory_templates`, and the four drama_* creation-content tables that previously survived erasure (the "right to be forgotten" had a real gap). (2) **Legacy key-file verification fixed**: v5.5-era key files (no `verify_blob`) previously accepted *any* password during `rekey` — a wrong old password could rewrite the key file and orphan all data. Rekey now probe-decrypts a real ciphertext from the store; empty stores fall back to the old behavior. (3) **KDF cost floor**: `KDFParams.from_dict` rejects tampered parameters (PBKDF2 < 60k, scrypt N < 4096) that would downgrade brute-force cost — key files and ciphertext headers are attacker-visible input. (4) **Compression × encryption unblocked**: `compress_memories` previously raised `SecurityError` on encrypted stores, making the two flagship features mutually exclusive by default. Compression now hydrates its TF-IDF index via the same in-memory decryption path as `fuzzy_search` (`_plaintext_for_index`) — plaintext never touches disk or FTS5. (5) **Interface matrix completed**: REST gains `/api/gdpr/report`, `/api/gdpr/export`, `/api/gdpr/erase` (confirm=true required), `/api/compress`, `/api/compressions`; MCP gains `gdpr_report`, `gdpr_erase` (confirm required), `memory_compress` — 87→90 tools, all three interfaces now expose the full governance surface. (6) **Honesty fixes**: README previously claimed "six-way hybrid search"; the actual retrieval count is four (vector/FTS5/TF-IDF/fuzzy) — wording corrected, and the cross-encoder/heuristic distinction is now explicit. LoCoMo full-suite results (51.5%, dual-judge) added to the benchmarks section. 7+ new contract tests (`tests/test_v656_security.py`).
|
|
118
120
|
|
|
119
121
|
- **v6.4.9 — ten-million-char library at millisecond latency: FTS5 high-frequency-phrase scoring pruned** (2026-11-11). The last honest bottleneck from v6.4.8's ledger. Root cause (30k per-path timing): under the trigram tokenizer, corpus-wide phrases (template data's "陈述性记忆") match every row — bm25 full-match scoring cost 50.5ms/query, the dominant remainder of 100k mixed latency. Fix, query-side df pre-pruning symmetric to TF-IDF max_df: a phrase's df upper bound = min df of its trigrams (phrase matches ⊆ every trigram's row set); prune at 5% of corpus size; keep the lowest-ub phrase if all pruned. df is served from an in-process cache keyed by `max(rowid)` (add/update invalidate; hard-delete leaves df slightly stale = prunes more conservatively) — **two real pitfalls found en route: fts5vocab is a *streaming virtual table* — per-term probes AND `IN` batches trigger full scans (combined regressed 17→45ms before the cache)**. Plus: FTS5 path skipped on pathological fallback (no discriminating signal). Clean-environment 100k re-bench: pathological 122→**0.4ms** (−99.7%), mixed 134.9→**3.0ms** (−98%), all query types millisecond-class at ~10M chars. AI-flavored comment cleanup (essay-style docstrings → engineer-speak, info preserved). 5 new guards.
|
|
120
122
|
|
|
@@ -147,7 +149,7 @@ v6.1.3 – v6.5.6 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,30
|
|
|
147
149
|
|
|
148
150
|
**Retrieval**
|
|
149
151
|
|
|
150
|
-
- **
|
|
152
|
+
- **Six-way hybrid retrieval (real, as of v6.5.8)** — six recall paths fused into one ranked result set: vector, FTS5, TF-IDF, fuzzy (the four core paths, RRF-style max-fusion with per-path score breakdown via `search --explain`), **temporal anchoring** (query absolute dates / anchored relative phrases → windowed SQL recall; v6.5.8) and **knowledge-graph adjacency** (entity match → 2-hop relation walk → memory back-references; v6.5.8). Paths 5-6 run in "blind-spot fill" mode — they only add candidates the four core paths missed, never re-rank existing high-quality hits. Degradation is per-path and safe: encrypted stores skip temporal (ciphertext is not SQL-matchable), empty KG skips graph, missing time anchor degrades to absolute-date-only.
|
|
151
153
|
- **Knowledge graph** — automatic entity and relation extraction, path finding, and associative recall.
|
|
152
154
|
- **Weighted recall** — multi-factor scoring (coverage, importance, access frequency, time decay) instead of similarity alone.
|
|
153
155
|
|
|
@@ -191,7 +193,7 @@ v6.1.3 – v6.5.6 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,30
|
|
|
191
193
|
|
|
192
194
|
```
|
|
193
195
|
┌──────────────────────────────────────────────────────┐
|
|
194
|
-
│ MindForge v6.5.
|
|
196
|
+
│ MindForge v6.5.8 │
|
|
195
197
|
│ Cognitive Layer Personality · KnowledgeGraph │
|
|
196
198
|
│ MemoryEvolution · FederatedMemory │
|
|
197
199
|
├──────────────────────────────────────────────────────┤
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
MindForge gives AI agents a persistent, structured long-term memory: a four-tier lifecycle model, knowledge graphs, hybrid retrieval, end-to-end encryption, and MCP / CLI / REST interfaces. All data stays on your machine.
|
|
8
8
|
|
|
9
|
-
> **The story** — one developer, seven months, from v1.0 (March 2026) to v6.5.
|
|
9
|
+
> **The story** — one developer, seven months, from v1.0 (March 2026) to v6.5.8: no team, no funding, 1,305 passing tests. [Read the journey →](https://opok-ops.github.io/MindForge/#developer)
|
|
10
|
+
>
|
|
11
|
+
> *Timeline note (v6.5.8):* "seven months" counts from project start (2026-03, pre-git prototyping era). Git history begins 2026-07-17 with the v5.7.x repository consolidation — earlier code lived outside this repo. The 416+ commits reflect consolidated history only.
|
|
10
12
|
|
|
11
13
|
[](https://www.python.org/downloads/)
|
|
12
14
|
[](LICENSE)
|
|
13
|
-
[](https://github.com/opok-ops/MindForge/releases)
|
|
14
16
|
[](https://github.com/opok-ops/MindForge/stargazers)
|
|
15
17
|
[](https://github.com/opok-ops/MindForge/forks)
|
|
16
18
|
[](https://github.com/opok-ops/MindForge/issues)
|
|
@@ -42,7 +44,7 @@ Install from source, then start writing and reading memories in minutes:
|
|
|
42
44
|
git clone https://github.com/opok-ops/MindForge.git
|
|
43
45
|
cd MindForge
|
|
44
46
|
pip install -e . # zero ML deps: 3-path retrieval (TF-IDF + FTS5 + fuzzy)
|
|
45
|
-
pip install -e ".[embedding]" # + vector path → full
|
|
47
|
+
pip install -e ".[embedding]" # + vector path → full 6-way hybrid retrieval
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
> Without the `embedding` extra, MindForge runs in zero-dependency mode — fully functional, but paraphrased queries may go unrecalled (no semantic path). With it, a small sentence-transformers model downloads on first vector search.
|
|
@@ -76,15 +78,15 @@ MindForge stats
|
|
|
76
78
|
- **Ten-million-character library, millisecond-class across all query types (v6.4.9)**: pathological 218→**0.4ms** (−99.8%), mixed 143→**3.0ms** (−98%), rare 6.8ms, combined 17.8ms (100k full-pipeline, clean environment). The last bottleneck — FTS5 high-frequency-phrase bm25 scoring — is now pruned query-side via trigram-df pre-check (df upper bound = min trigram df, pruned at 5% corpus size, symmetric to the TF-IDF max_df design; df served from an in-process cache — fts5vocab is a streaming virtual table, per-term probes scan it fully).
|
|
77
79
|
- **Index-blindness fix (v6.4.8)**: TF-IDF vocabulary was locked to the first 5 documents since v6.4.6 — incremental adds indexed as empty vectors (TF-IDF effectively half-dead; previous numbers carried by FTS5/fuzzy). Fixed with incremental vocabulary growth; all pipeline numbers above are now *true full-pipeline* measurements.
|
|
78
80
|
- Retrieval quality (fixed-seed, `benchmarks/quality_bench.py`, 2k entries): needle Recall@1 = 1.0, MRR = 1.0, topic Recall@1 = 1.0, noise false-recall = 0.
|
|
79
|
-
- **LoCoMo full-suite, LLM-judged (v6.5.
|
|
81
|
+
- **LoCoMo full-suite, LLM-judged (v6.5.8, 2026-11-13)**: 1,986 questions across all 10 conversations — **51.5% accuracy (≥9/10 judge score)**, 2.13× over the 24.2% pre-assembly baseline; cross-validated by two independent judges (DeepSeek 51.5% / Kimi K3.1 52.72%, Δ1.2pt); excluding the adversarial "should-refuse" bucket, **43.05%** (663/1540). Per-bucket: adversarial 93.9%, single-hop 57.8%, multi-hop 25.2%, temporal 9.6%, open-domain 10.4% — temporal evidence recall and two-hop chain retrieval are the named v6.6 targets. Data: `benchmarks/results/`, judge pipeline in `benchmarks/`.
|
|
80
82
|
- LongMemEval — interface ready, not yet run (requires external LLM API key).
|
|
81
83
|
- TF-IDF degraded mode process memory at 100k: ~700 MB. Index LRU cap: 100,000 docs (MINDFORGE_INDEX_MAX_DOCS).
|
|
82
84
|
|
|
83
85
|
## What's New
|
|
84
86
|
|
|
85
|
-
v6.1.3 – v6.5.
|
|
87
|
+
v6.1.3 – v6.5.8 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,300+ tests**.
|
|
86
88
|
|
|
87
|
-
- **v6.5.
|
|
89
|
+
- **v6.5.8 — security fix pack from dual-judge external review** (2026-11-14). Qwen4-Max (Doubao) and Kimi K3.1 independently reviewed the codebase; their overlapping findings became this release. (1) **GDPR erasure completed**: `gdpr_erase_all` now cascades to 17 tables — added `knowledge_graph` entities, `memory_snapshots`, `memory_templates`, and the four drama_* creation-content tables that previously survived erasure (the "right to be forgotten" had a real gap). (2) **Legacy key-file verification fixed**: v5.5-era key files (no `verify_blob`) previously accepted *any* password during `rekey` — a wrong old password could rewrite the key file and orphan all data. Rekey now probe-decrypts a real ciphertext from the store; empty stores fall back to the old behavior. (3) **KDF cost floor**: `KDFParams.from_dict` rejects tampered parameters (PBKDF2 < 60k, scrypt N < 4096) that would downgrade brute-force cost — key files and ciphertext headers are attacker-visible input. (4) **Compression × encryption unblocked**: `compress_memories` previously raised `SecurityError` on encrypted stores, making the two flagship features mutually exclusive by default. Compression now hydrates its TF-IDF index via the same in-memory decryption path as `fuzzy_search` (`_plaintext_for_index`) — plaintext never touches disk or FTS5. (5) **Interface matrix completed**: REST gains `/api/gdpr/report`, `/api/gdpr/export`, `/api/gdpr/erase` (confirm=true required), `/api/compress`, `/api/compressions`; MCP gains `gdpr_report`, `gdpr_erase` (confirm required), `memory_compress` — 87→90 tools, all three interfaces now expose the full governance surface. (6) **Honesty fixes**: README previously claimed "six-way hybrid search"; the actual retrieval count is four (vector/FTS5/TF-IDF/fuzzy) — wording corrected, and the cross-encoder/heuristic distinction is now explicit. LoCoMo full-suite results (51.5%, dual-judge) added to the benchmarks section. 7+ new contract tests (`tests/test_v656_security.py`).
|
|
88
90
|
|
|
89
91
|
- **v6.4.9 — ten-million-char library at millisecond latency: FTS5 high-frequency-phrase scoring pruned** (2026-11-11). The last honest bottleneck from v6.4.8's ledger. Root cause (30k per-path timing): under the trigram tokenizer, corpus-wide phrases (template data's "陈述性记忆") match every row — bm25 full-match scoring cost 50.5ms/query, the dominant remainder of 100k mixed latency. Fix, query-side df pre-pruning symmetric to TF-IDF max_df: a phrase's df upper bound = min df of its trigrams (phrase matches ⊆ every trigram's row set); prune at 5% of corpus size; keep the lowest-ub phrase if all pruned. df is served from an in-process cache keyed by `max(rowid)` (add/update invalidate; hard-delete leaves df slightly stale = prunes more conservatively) — **two real pitfalls found en route: fts5vocab is a *streaming virtual table* — per-term probes AND `IN` batches trigger full scans (combined regressed 17→45ms before the cache)**. Plus: FTS5 path skipped on pathological fallback (no discriminating signal). Clean-environment 100k re-bench: pathological 122→**0.4ms** (−99.7%), mixed 134.9→**3.0ms** (−98%), all query types millisecond-class at ~10M chars. AI-flavored comment cleanup (essay-style docstrings → engineer-speak, info preserved). 5 new guards.
|
|
90
92
|
|
|
@@ -117,7 +119,7 @@ v6.1.3 – v6.5.6 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,30
|
|
|
117
119
|
|
|
118
120
|
**Retrieval**
|
|
119
121
|
|
|
120
|
-
- **
|
|
122
|
+
- **Six-way hybrid retrieval (real, as of v6.5.8)** — six recall paths fused into one ranked result set: vector, FTS5, TF-IDF, fuzzy (the four core paths, RRF-style max-fusion with per-path score breakdown via `search --explain`), **temporal anchoring** (query absolute dates / anchored relative phrases → windowed SQL recall; v6.5.8) and **knowledge-graph adjacency** (entity match → 2-hop relation walk → memory back-references; v6.5.8). Paths 5-6 run in "blind-spot fill" mode — they only add candidates the four core paths missed, never re-rank existing high-quality hits. Degradation is per-path and safe: encrypted stores skip temporal (ciphertext is not SQL-matchable), empty KG skips graph, missing time anchor degrades to absolute-date-only.
|
|
121
123
|
- **Knowledge graph** — automatic entity and relation extraction, path finding, and associative recall.
|
|
122
124
|
- **Weighted recall** — multi-factor scoring (coverage, importance, access frequency, time decay) instead of similarity alone.
|
|
123
125
|
|
|
@@ -161,7 +163,7 @@ v6.1.3 – v6.5.6 shipped in two weeks (2026-11-01 → 11-14), guarded by **1,30
|
|
|
161
163
|
|
|
162
164
|
```
|
|
163
165
|
┌──────────────────────────────────────────────────────┐
|
|
164
|
-
│ MindForge v6.5.
|
|
166
|
+
│ MindForge v6.5.8 │
|
|
165
167
|
│ Cognitive Layer Personality · KnowledgeGraph │
|
|
166
168
|
│ MemoryEvolution · FederatedMemory │
|
|
167
169
|
├──────────────────────────────────────────────────────┤
|
|
@@ -9,6 +9,7 @@ import hashlib
|
|
|
9
9
|
import hmac
|
|
10
10
|
import json
|
|
11
11
|
import base64
|
|
12
|
+
import logging
|
|
12
13
|
import threading # v5.4.7 修复 H-4:全局引擎初始化线程安全
|
|
13
14
|
from pathlib import Path
|
|
14
15
|
from typing import Optional, Tuple, Callable
|
|
@@ -400,8 +401,13 @@ def _write_key_file(key_path: Path, salt: bytes, kdf_params: KDFParams,
|
|
|
400
401
|
["icacls", str(key_path), "/inheritance:r", "/grant:r", f"{username}:F"],
|
|
401
402
|
capture_output=True, timeout=5, check=False
|
|
402
403
|
)
|
|
403
|
-
except Exception:
|
|
404
|
-
|
|
404
|
+
except Exception as _acl_err:
|
|
405
|
+
# v6.5.6:ACL 失败不再静默(评审指出 Windows 密钥文件权限
|
|
406
|
+
# 失败无声 = 用户以为已加固实际继承默认 ACL)。仍不阻断
|
|
407
|
+
# 创建,但显式告警留痕。
|
|
408
|
+
logging.getLogger("core.encryption").warning(
|
|
409
|
+
"Windows 密钥文件 ACL 设置失败(%s)——文件权限为"
|
|
410
|
+
"继承默认值,建议手动 icacls 加固", _acl_err)
|
|
405
411
|
|
|
406
412
|
|
|
407
413
|
def _verify_key_password(engine: EncryptionEngine, key_data: dict,
|
|
@@ -663,7 +663,10 @@ class MindForge:
|
|
|
663
663
|
kg = self._knowledge_graph
|
|
664
664
|
stats: Dict[str, Any] = {"entities_added": 0, "relations_added": 0, "memory_processed": 0}
|
|
665
665
|
if memory_id:
|
|
666
|
-
|
|
666
|
+
# v6.5.7:内部管线读取不触发 auto-expire——add 流程的自动
|
|
667
|
+
# 建图会立即 get_memory,若条目带过去 expires_at 会被提前
|
|
668
|
+
# 移入回收站(TTL 语义破坏:list_expired/purge_expired 全空)
|
|
669
|
+
entry = self._storage.get_memory(memory_id, _auto_expire=False)
|
|
667
670
|
if entry is None:
|
|
668
671
|
raise ValueError(f"记忆不存在: {memory_id}")
|
|
669
672
|
if str(getattr(entry, "privacy", "")) in ("PrivacyLevel.STRICT", "STRICT"):
|
|
@@ -831,7 +834,8 @@ class MindForge:
|
|
|
831
834
|
session_id: str = "",
|
|
832
835
|
use_embedding: bool = True,
|
|
833
836
|
explain: bool = False,
|
|
834
|
-
expand_context: int = 0
|
|
837
|
+
expand_context: int = 0,
|
|
838
|
+
time_anchor: Optional[str] = None):
|
|
835
839
|
"""搜索记忆
|
|
836
840
|
|
|
837
841
|
v5.4.5 新增 use_embedding 参数:
|
|
@@ -844,6 +848,13 @@ class MindForge:
|
|
|
844
848
|
multi-hop 正确率 +27pt 的核心机制产品化)
|
|
845
849
|
- 0(默认):行为与旧版完全一致
|
|
846
850
|
|
|
851
|
+
v6.5.7 新增 time_anchor 参数(六路检索的第 5 路时间锚):
|
|
852
|
+
- ISO 日期("2023-05-06"):query 中的相对时间词(yesterday/
|
|
853
|
+
两周前)以此为锚换算绝对日期窗口,启用 temporal 召回路;
|
|
854
|
+
同时 query 中的绝对日期直接成窗
|
|
855
|
+
- None(默认):仅 query 携带绝对日期时启用 temporal 路
|
|
856
|
+
(相对词无锚降级,v6.5.5 同款安全语义)
|
|
857
|
+
|
|
847
858
|
v6.3.0 新增 explain 参数(检索可解释性):
|
|
848
859
|
- True:每个返回的 MemoryChunk.score_breakdown 携带各召回路
|
|
849
860
|
(tfidf/fts5/fuzzy/vector)原始分数、融合明细与最终胜出
|
|
@@ -875,6 +886,7 @@ class MindForge:
|
|
|
875
886
|
use_embedding=use_embedding,
|
|
876
887
|
explain=explain,
|
|
877
888
|
expand_context=expand_context,
|
|
889
|
+
time_anchor=time_anchor,
|
|
878
890
|
_update_access=False,
|
|
879
891
|
_record_search=False,
|
|
880
892
|
)
|
|
@@ -4,6 +4,7 @@ MindForge 查询引擎
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
|
+
import sqlite3
|
|
7
8
|
import re
|
|
8
9
|
from dataclasses import dataclass, field
|
|
9
10
|
from typing import List, Optional, Dict, Any, Tuple
|
|
@@ -77,6 +78,18 @@ _TEMPORAL_RULES = [
|
|
|
77
78
|
("next weekend", 7), ("last month", -30), ("next month", 30),
|
|
78
79
|
("last year", -365), ("next year", 365),
|
|
79
80
|
]
|
|
81
|
+
# v6.5.7:中文相对时间词(第 5 路查询解析用;与 _TEMPORAL_RULES
|
|
82
|
+
# 英文表分开,避免 "上个月" 被 N-数量模式抢先误配)
|
|
83
|
+
_CN_TEMPORAL_RULES = [
|
|
84
|
+
("今天", 0), ("今晚", 0), ("今天早上", 0), ("今天下午", 0),
|
|
85
|
+
("昨天", -1), ("昨晚", -1), ("前天", -2),
|
|
86
|
+
("明天", 1), ("明晚", 1), ("后天", 2),
|
|
87
|
+
("上周", -7), ("上星期", -7), ("下周", 7), ("下星期", 7),
|
|
88
|
+
("上个月", -30), ("上个月份", -30), ("上月", -30),
|
|
89
|
+
("下个月", 30), ("下月", 30),
|
|
90
|
+
("去年", -365), ("明年", 365),
|
|
91
|
+
]
|
|
92
|
+
|
|
80
93
|
_N_REL = re.compile(
|
|
81
94
|
r"(\b\d+\s+(?:day|week|month|year)s?\s+ago\b"
|
|
82
95
|
r"|\bin\s+\d+\s+(?:day|week|month|year)s?\b"
|
|
@@ -87,6 +100,110 @@ _REL_DUR = {"day": 1, "week": 7, "month": 30, "year": 365,
|
|
|
87
100
|
"天": 1, "周": 7, "月": 30, "年": 365}
|
|
88
101
|
|
|
89
102
|
|
|
103
|
+
_ABS_DATE_PATTERNS = [
|
|
104
|
+
# ISO 日期 2023-05-06 / 2023-5-6
|
|
105
|
+
re.compile(r"\b(20\d{2})-(\d{1,2})-(\d{1,2})\b"),
|
|
106
|
+
# 中文 2023年5月6日 / 2023年5月
|
|
107
|
+
re.compile(r"(20\d{2})\s*年\s*(\d{1,2})\s*月(?:\s*(\d{1,2})\s*日)?"),
|
|
108
|
+
# M月D日 / M月(年份取锚年,无锚则跳过)
|
|
109
|
+
re.compile(r"(?<!\d)(\d{1,2})\s*月\s*(\d{1,2})\s*日(?![\d年])"),
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _parse_query_window(query: str,
|
|
114
|
+
time_anchor: Optional[str] = None
|
|
115
|
+
) -> Optional[Tuple[str, str, str]]:
|
|
116
|
+
"""v6.5.7 第 5 路:从 query 解析时间窗口(第 5 路召回的前置)。
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
(start_iso, end_iso, label) —— ISO 日期闭区间;无法解析返回 None。
|
|
120
|
+
- query 携带绝对日期:直接成窗(单日窗口)
|
|
121
|
+
- query 携带相对时间词:需 time_anchor(ISO 日期)换算;
|
|
122
|
+
无锚时降级返回 None(v6.5.5 同款降级安全语义)
|
|
123
|
+
label 用于 explain(如 "yesterday@2023-05-06")。
|
|
124
|
+
"""
|
|
125
|
+
q = (query or "").strip()
|
|
126
|
+
if not q:
|
|
127
|
+
return None
|
|
128
|
+
today = None
|
|
129
|
+
if time_anchor:
|
|
130
|
+
try:
|
|
131
|
+
from datetime import date as _d
|
|
132
|
+
parts = str(time_anchor).strip().split("-")
|
|
133
|
+
today = _d(int(parts[0]), int(parts[1]), int(parts[2]))
|
|
134
|
+
except (ValueError, IndexError, TypeError):
|
|
135
|
+
today = None
|
|
136
|
+
|
|
137
|
+
# 1) 绝对日期优先
|
|
138
|
+
for pat in _ABS_DATE_PATTERNS:
|
|
139
|
+
m = pat.search(q)
|
|
140
|
+
if not m:
|
|
141
|
+
continue
|
|
142
|
+
try:
|
|
143
|
+
groups = m.groups()
|
|
144
|
+
if len(groups) == 3 and groups[0] and len(groups[0]) == 4:
|
|
145
|
+
y, mo, dy = int(groups[0]), int(groups[1]), int(groups[2])
|
|
146
|
+
elif len(groups) == 3 and groups[2] is None:
|
|
147
|
+
y, mo, dy = int(groups[0]), int(groups[1]), 1
|
|
148
|
+
else:
|
|
149
|
+
# M月D日:年份取锚
|
|
150
|
+
if today is None:
|
|
151
|
+
continue
|
|
152
|
+
y, mo, dy = today.year, int(groups[0]), int(groups[1])
|
|
153
|
+
from datetime import date as _d
|
|
154
|
+
the_day = _d(y, mo, dy)
|
|
155
|
+
except (ValueError, TypeError):
|
|
156
|
+
continue
|
|
157
|
+
iso = the_day.isoformat()
|
|
158
|
+
return iso, iso, iso
|
|
159
|
+
|
|
160
|
+
# 2) 相对词 → 锚换算
|
|
161
|
+
if today is None:
|
|
162
|
+
return None
|
|
163
|
+
from datetime import timedelta as _td
|
|
164
|
+
ql = q.lower()
|
|
165
|
+
offset = None
|
|
166
|
+
# 中文相对词优先("上个月"含"个月"会被 _N_REL 数量模式误吸,
|
|
167
|
+
# 必须先于英文表与数量模式匹配)
|
|
168
|
+
for phrase, off in _CN_TEMPORAL_RULES:
|
|
169
|
+
if phrase in q:
|
|
170
|
+
offset = off
|
|
171
|
+
label = phrase
|
|
172
|
+
break
|
|
173
|
+
if offset is None:
|
|
174
|
+
for phrase, off in _TEMPORAL_RULES:
|
|
175
|
+
if phrase in ql:
|
|
176
|
+
offset = off
|
|
177
|
+
label = phrase
|
|
178
|
+
break
|
|
179
|
+
if offset is None:
|
|
180
|
+
m = _N_REL.search(q)
|
|
181
|
+
if m:
|
|
182
|
+
token = m.group(1)
|
|
183
|
+
# 数字 + 单位 + 前/后
|
|
184
|
+
import re as _re2
|
|
185
|
+
num_m = _re2.search(r"(\d+|[两二三四五六七八九十]+)", token)
|
|
186
|
+
unit_m = _re2.search(r"(day|week|month|year|天|周|月|年)", token,
|
|
187
|
+
_re2.IGNORECASE)
|
|
188
|
+
if num_m and unit_m:
|
|
189
|
+
raw = num_m.group(1)
|
|
190
|
+
n = (_CN_NUM.get(raw) if raw in _CN_NUM
|
|
191
|
+
else int(raw) if raw.isdigit() else None)
|
|
192
|
+
if n is not None:
|
|
193
|
+
mult = _REL_DUR.get(unit_m.group(1).lower(), 1)
|
|
194
|
+
offset = (-n if ("ago" in token or "前" in token)
|
|
195
|
+
else n if ("in " in token or "后" in token
|
|
196
|
+
or "以" in token) else -n)
|
|
197
|
+
label = token
|
|
198
|
+
if offset is None:
|
|
199
|
+
return None
|
|
200
|
+
# 相对词窗口 ±3 天容差:对话时间表达天然模糊("上周"可能指
|
|
201
|
+
# 上周任何一天),单日窗口召回率过低(v6.5.7 199 问实测修正)
|
|
202
|
+
d_start = today + _td(days=offset - 3)
|
|
203
|
+
d_end = today + _td(days=offset + 3)
|
|
204
|
+
return d_start.isoformat(), d_end.isoformat(), f"{label}@{today.isoformat()}"
|
|
205
|
+
|
|
206
|
+
|
|
90
207
|
def _normalize_temporal(text: str, anchor: Optional[str]) -> str:
|
|
91
208
|
"""把 text 中的相对时间词换算为 [绝对日期±N] 标注(v6.5.5)
|
|
92
209
|
|
|
@@ -266,6 +383,158 @@ class QueryEngine:
|
|
|
266
383
|
|
|
267
384
|
return list(expanded_terms)
|
|
268
385
|
|
|
386
|
+
def _temporal_candidates(self, query: str,
|
|
387
|
+
time_anchor: Optional[str],
|
|
388
|
+
max_candidates: int = 30
|
|
389
|
+
) -> List[Tuple[str, float, str]]:
|
|
390
|
+
"""v6.5.7 第 5 路:时间锚定召回。
|
|
391
|
+
|
|
392
|
+
动机(LoCoMo 全量数据):temporal 桶 acc 9.6% 为最大失血桶——
|
|
393
|
+
问「上周做了什么」时相关记忆内容带绝对日期(2023-05-06),
|
|
394
|
+
query 的「上周」与内容日期在四路(词面/语义)上均不匹配,
|
|
395
|
+
证据根本进不了候选集。本路:
|
|
396
|
+
1. 解析 query 时间窗(_parse_query_window,绝对日期或锚定相对词)
|
|
397
|
+
2. 明文库 SQL 月粒度 LIKE 召回 content/tags 命中窗口日期的记忆
|
|
398
|
+
3. 窗口内日期精确命中加权 0.85,月粒度命中 0.65
|
|
399
|
+
|
|
400
|
+
加密库 content 为密文无法 SQL 匹配——自动跳过本路(warn 一次)。
|
|
401
|
+
Returns:
|
|
402
|
+
[(memory_id, score, label), ...]
|
|
403
|
+
"""
|
|
404
|
+
win = _parse_query_window(query, time_anchor)
|
|
405
|
+
if not win:
|
|
406
|
+
return []
|
|
407
|
+
start_iso, end_iso, label = win
|
|
408
|
+
try:
|
|
409
|
+
from datetime import date as _d
|
|
410
|
+
d0, d1 = _d.fromisoformat(start_iso), _d.fromisoformat(end_iso)
|
|
411
|
+
except ValueError:
|
|
412
|
+
return []
|
|
413
|
+
# 生成窗口覆盖的年月 pattern(最多 3 个,防超宽窗口全表扫)
|
|
414
|
+
months = []
|
|
415
|
+
y, mo = d0.year, d0.month
|
|
416
|
+
while True:
|
|
417
|
+
months.append(f"{y:04d}-{mo:02d}")
|
|
418
|
+
if (y, mo) == (d1.year, d1.month) or len(months) >= 3:
|
|
419
|
+
break
|
|
420
|
+
mo += 1
|
|
421
|
+
if mo > 12:
|
|
422
|
+
y, mo = y + 1, 1
|
|
423
|
+
conn = self.storage._get_conn()
|
|
424
|
+
ids: Dict[str, float] = {}
|
|
425
|
+
try:
|
|
426
|
+
for ym in months:
|
|
427
|
+
pat = f"%{ym}-%"
|
|
428
|
+
rows = conn.execute(
|
|
429
|
+
"SELECT id, content, tags FROM memories "
|
|
430
|
+
"WHERE encrypted=0 AND category != 'trash' "
|
|
431
|
+
"AND (content LIKE ? OR tags LIKE ?) LIMIT ?",
|
|
432
|
+
(pat, pat, max_candidates)).fetchall()
|
|
433
|
+
for r in rows:
|
|
434
|
+
score = 0.5 # 月粒度命中(v6.5.7 小样校准:补盲分
|
|
435
|
+
# 必须低于四路典型命中 0.5-0.7,否则挤掉正确证据)
|
|
436
|
+
text = (r[1] or "") + " " + (r[2] or "")
|
|
437
|
+
# 窗口内日期精确命中 → 加权
|
|
438
|
+
import re as _re3
|
|
439
|
+
for dm in _re3.finditer(r"20\d{2}-\d{2}-\d{2}", text):
|
|
440
|
+
try:
|
|
441
|
+
dd = _d.fromisoformat(dm.group(0)[:10])
|
|
442
|
+
except ValueError:
|
|
443
|
+
continue
|
|
444
|
+
if d0 <= dd <= d1:
|
|
445
|
+
score = 0.6
|
|
446
|
+
break
|
|
447
|
+
if r[0] not in ids or score > ids[r[0]]:
|
|
448
|
+
ids[r[0]] = score
|
|
449
|
+
except sqlite3.OperationalError as e:
|
|
450
|
+
logger.warning("temporal 路召回失败(降级跳过): %s", e)
|
|
451
|
+
return []
|
|
452
|
+
return [(mid, s, label) for mid, s in ids.items()]
|
|
453
|
+
|
|
454
|
+
def _graph_candidates(self, query: str,
|
|
455
|
+
max_entities: int = 8,
|
|
456
|
+
max_hops: int = 2,
|
|
457
|
+
) -> List[Tuple[str, float, str]]:
|
|
458
|
+
"""v6.5.7 第 6 路:知识图谱邻接召回(两跳内)。
|
|
459
|
+
|
|
460
|
+
动机(LoCoMo 全量数据):multi-hop 桶 acc 25.2%——两跳问题
|
|
461
|
+
需要「A 关联 B、B 关联 C」的链式证据,词面/语义检索对间接
|
|
462
|
+
关联天然盲。本路:
|
|
463
|
+
1. query 与 KG 实体匹配(双向 LIKE,限 max_entities)
|
|
464
|
+
2. 沿 graph_relations 展开 1-2 跳邻接实体
|
|
465
|
+
3. 收集沿途 relation.memory_ids 指回的记忆作为候选
|
|
466
|
+
分数:1 跳 0.55、2 跳 0.45,× relation weight(cap 0.9)。
|
|
467
|
+
(v6.5.7 小样校准:0.8/0.5 会把四路正确证据挤出 top-k,
|
|
468
|
+
cat1 multi-hop 实测 -3.1pt——补盲分必须低于四路典型命中。)
|
|
469
|
+
|
|
470
|
+
KG 为空(未跑 graph_extract)时本路空转返回 []——零成本降级。
|
|
471
|
+
Returns:
|
|
472
|
+
[(memory_id, score, label), ...]
|
|
473
|
+
"""
|
|
474
|
+
conn = self.storage._get_conn()
|
|
475
|
+
try:
|
|
476
|
+
ent_rows = conn.execute(
|
|
477
|
+
"SELECT id, entity FROM knowledge_graph LIMIT 500").fetchall()
|
|
478
|
+
except sqlite3.OperationalError as e:
|
|
479
|
+
logger.warning("graph 路召回失败(KG 表缺失,降级跳过): %s", e)
|
|
480
|
+
return []
|
|
481
|
+
if not ent_rows:
|
|
482
|
+
return []
|
|
483
|
+
|
|
484
|
+
ql = (query or "").lower()
|
|
485
|
+
if not ql:
|
|
486
|
+
return []
|
|
487
|
+
# 双向包含匹配:query 含实体名 或 实体名含 query 词
|
|
488
|
+
# (实体名普遍较短,双向匹配召回率远高于单向)
|
|
489
|
+
matched = []
|
|
490
|
+
for eid, name in ent_rows:
|
|
491
|
+
nm = (name or "").strip().lower()
|
|
492
|
+
if not nm or len(nm) < 2:
|
|
493
|
+
continue
|
|
494
|
+
if nm in ql or ql in nm:
|
|
495
|
+
matched.append((eid, name))
|
|
496
|
+
if len(matched) >= max_entities:
|
|
497
|
+
break
|
|
498
|
+
if not matched:
|
|
499
|
+
return []
|
|
500
|
+
|
|
501
|
+
import json as _json
|
|
502
|
+
cand: Dict[str, float] = {}
|
|
503
|
+
start_ids = {eid for eid, _ in matched}
|
|
504
|
+
frontier = {eid: (0.55, 1) for eid in start_ids}
|
|
505
|
+
visited = set(start_ids)
|
|
506
|
+
collected_rel_ids: set = set()
|
|
507
|
+
for _hop in range(max_hops):
|
|
508
|
+
if not frontier:
|
|
509
|
+
break
|
|
510
|
+
placeholders = ",".join("?" * len(frontier))
|
|
511
|
+
rows = conn.execute(
|
|
512
|
+
f"SELECT from_entity, to_entity, weight, memory_ids "
|
|
513
|
+
f"FROM graph_relations "
|
|
514
|
+
f"WHERE from_entity IN ({placeholders}) "
|
|
515
|
+
f"OR to_entity IN ({placeholders})",
|
|
516
|
+
list(frontier.keys()) + list(frontier.keys())).fetchall()
|
|
517
|
+
nxt = {}
|
|
518
|
+
for fe, te, w, mids in rows:
|
|
519
|
+
score0, hop = frontier.get(fe) or frontier.get(te) or (0.45, 2)
|
|
520
|
+
other = te if fe in frontier else fe
|
|
521
|
+
rel_score = min(0.9, score0 * (w or 1.0))
|
|
522
|
+
if mids:
|
|
523
|
+
try:
|
|
524
|
+
for mid in _json.loads(mids):
|
|
525
|
+
if mid:
|
|
526
|
+
s = rel_score
|
|
527
|
+
if mid not in cand or s > cand[mid]:
|
|
528
|
+
cand[mid] = s
|
|
529
|
+
except (ValueError, TypeError):
|
|
530
|
+
pass
|
|
531
|
+
if other not in visited:
|
|
532
|
+
visited.add(other)
|
|
533
|
+
nxt[other] = (min(0.9, score0 * 0.6), hop + 1)
|
|
534
|
+
frontier = nxt
|
|
535
|
+
label = ",".join(name for _, name in matched[:3])
|
|
536
|
+
return [(mid, s, f"kg:{label}") for mid, s in cand.items()]
|
|
537
|
+
|
|
269
538
|
def search(self,
|
|
270
539
|
query: str,
|
|
271
540
|
max_results: int = 10,
|
|
@@ -277,6 +546,7 @@ class QueryEngine:
|
|
|
277
546
|
use_embedding: bool = True,
|
|
278
547
|
explain: bool = False,
|
|
279
548
|
expand_context: int = 0,
|
|
549
|
+
time_anchor: Optional[str] = None,
|
|
280
550
|
*, _update_access: bool = True,
|
|
281
551
|
_record_search: bool = True) -> RecallResult:
|
|
282
552
|
"""搜索记忆
|
|
@@ -486,6 +756,39 @@ class QueryEngine:
|
|
|
486
756
|
mid, _batch_access=True)
|
|
487
757
|
return _entry_cache[mid]
|
|
488
758
|
|
|
759
|
+
# ===== v6.5.7 第 5/6 路:temporal + graph 召回 =====
|
|
760
|
+
# 设计为「补盲区」语义:仅当记忆未被四路捞到(或四路分更低)时
|
|
761
|
+
# 生效(score_map 取 max),不重排既有高质量命中。
|
|
762
|
+
# 降级矩阵:加密库 temporal 跳过(密文不可 SQL 匹配)、KG 空
|
|
763
|
+
# graph 空转、无 time_anchor 时相对词降级仅绝对日期可用——
|
|
764
|
+
# 全部零异常退出,四路结果不受影响。
|
|
765
|
+
five_six_used = []
|
|
766
|
+
if not self.storage.encrypted and query:
|
|
767
|
+
for mid, s, lbl in self._temporal_candidates(query, time_anchor):
|
|
768
|
+
if explain:
|
|
769
|
+
_bd(mid)["temporal"] = max(s, _bd(mid).get("temporal", 0.0))
|
|
770
|
+
if s >= score_map.get(mid, 0.0):
|
|
771
|
+
is_new = mid not in score_map
|
|
772
|
+
score_map[mid] = s
|
|
773
|
+
if explain and is_new:
|
|
774
|
+
_bd(mid)["winner"] = "temporal"
|
|
775
|
+
_bd(mid)["final"] = s
|
|
776
|
+
if query:
|
|
777
|
+
for mid, s, lbl in self._graph_candidates(query):
|
|
778
|
+
if explain:
|
|
779
|
+
_bd(mid)["graph"] = max(s, _bd(mid).get("graph", 0.0))
|
|
780
|
+
if s >= score_map.get(mid, 0.0):
|
|
781
|
+
is_new = mid not in score_map
|
|
782
|
+
score_map[mid] = s
|
|
783
|
+
if explain and is_new:
|
|
784
|
+
_bd(mid)["winner"] = "graph"
|
|
785
|
+
_bd(mid)["final"] = s
|
|
786
|
+
if explain and breakdown_map:
|
|
787
|
+
if any("temporal" in (v or {}) for v in breakdown_map.values()):
|
|
788
|
+
five_six_used.append("temporal")
|
|
789
|
+
if any("graph" in (v or {}) for v in breakdown_map.values()):
|
|
790
|
+
five_six_used.append("graph")
|
|
791
|
+
|
|
489
792
|
# 预过滤:按 categories/layers 筛选 score_map,避免非匹配记忆占据排序位
|
|
490
793
|
if categories or layers:
|
|
491
794
|
filtered_map = {}
|
|
@@ -502,6 +805,8 @@ class QueryEngine:
|
|
|
502
805
|
|
|
503
806
|
# 合并排序
|
|
504
807
|
raw_results = sorted(score_map.items(), key=lambda x: x[1], reverse=True)
|
|
808
|
+
if five_six_used:
|
|
809
|
+
strategy_used = strategy_used + "+" + "+".join(five_six_used)
|
|
505
810
|
|
|
506
811
|
# ===== 第二阶段:构建结果 =====
|
|
507
812
|
chunks = []
|