lean-memory 0.1.1__tar.gz → 0.1.3__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.
Files changed (100) hide show
  1. lean_memory-0.1.3/CHANGELOG.md +123 -0
  2. lean_memory-0.1.3/LICENSE +202 -0
  3. {lean_memory-0.1.1 → lean_memory-0.1.3}/PKG-INFO +8 -5
  4. {lean_memory-0.1.1 → lean_memory-0.1.3}/README.md +6 -4
  5. {lean_memory-0.1.1 → lean_memory-0.1.3}/pyproject.toml +30 -1
  6. {lean_memory-0.1.1 → lean_memory-0.1.3}/server.json +5 -5
  7. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/__init__.py +1 -1
  8. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/embed/sentence_transformer.py +7 -1
  9. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/contradiction.py +22 -0
  10. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/gliner_extractor.py +7 -1
  11. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/mcp_server.py +6 -0
  12. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/memory.py +45 -7
  13. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/retrieve/rerank.py +6 -1
  14. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/store/sqlite_store.py +64 -10
  15. lean_memory-0.1.3/tests/test_contradiction_high_band.py +90 -0
  16. lean_memory-0.1.3/tests/test_dim_guard.py +73 -0
  17. lean_memory-0.1.3/tests/test_fts_query.py +80 -0
  18. lean_memory-0.1.3/tests/test_functional_slot_supersession.py +72 -0
  19. lean_memory-0.1.3/tests/test_mcp_stdio_protocol.py +123 -0
  20. lean_memory-0.1.3/tests/test_schema_version.py +44 -0
  21. lean_memory-0.1.3/tests/test_server_manifest.py +56 -0
  22. lean_memory-0.1.3/tests/test_stdout_hygiene.py +85 -0
  23. lean_memory-0.1.3/tests/test_typer_fallback.py +45 -0
  24. lean_memory-0.1.1/.github/workflows/publish-mcp.yml +0 -52
  25. lean_memory-0.1.1/.github/workflows/release.yml +0 -44
  26. lean_memory-0.1.1/.github/workflows/test.yml +0 -43
  27. lean_memory-0.1.1/CHANGELOG.md +0 -64
  28. lean_memory-0.1.1/CLAUDE.md +0 -58
  29. lean_memory-0.1.1/bench/bet2_ablation.py +0 -897
  30. lean_memory-0.1.1/bench/bet2_goldset.py +0 -1057
  31. lean_memory-0.1.1/bench/phase2_escalation_probe.py +0 -204
  32. lean_memory-0.1.1/bench/phase2_eval.py +0 -329
  33. lean_memory-0.1.1/bench/phase2_ingest.py +0 -470
  34. lean_memory-0.1.1/bench/phase2_judge.py +0 -232
  35. lean_memory-0.1.1/bench/phase2_reader.py +0 -114
  36. lean_memory-0.1.1/bench/results/calibration/2026-07-bet2-revalidation.txt +0 -59
  37. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-baseline.json +0 -511
  38. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-postdrop-p1.json +0 -22
  39. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-postdrop-p2.json +0 -24
  40. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-postdrop-p3.json +0 -23
  41. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-postdrop-p4.json +0 -23
  42. lean_memory-0.1.1/bench/results/calibration/2026-07-escalation-postfix.json +0 -631
  43. lean_memory-0.1.1/bench/results/calibration/2026-07-granularity-sweep.json +0 -95
  44. lean_memory-0.1.1/bench/results/calibration/README.md +0 -200
  45. lean_memory-0.1.1/bench/results/phase2/.gitkeep +0 -0
  46. lean_memory-0.1.1/bench/results/phase2/dataset_pins.json +0 -5
  47. lean_memory-0.1.1/bench/smoke_quality.py +0 -101
  48. lean_memory-0.1.1/docs/assets/quickstart.gif +0 -0
  49. lean_memory-0.1.1/docs/assets/quickstart.tape +0 -25
  50. lean_memory-0.1.1/docs/benchmarks.md +0 -191
  51. lean_memory-0.1.1/docs/competitive-landscape.md +0 -212
  52. lean_memory-0.1.1/docs/launch-fixlist.md +0 -97
  53. lean_memory-0.1.1/docs/phase2-eval-plan.md +0 -317
  54. lean_memory-0.1.1/docs/phase2-learnings.md +0 -130
  55. lean_memory-0.1.1/docs/superpowers/phase2-HANDOFF.md +0 -161
  56. lean_memory-0.1.1/docs/superpowers/plans/2026-06-21-demo-agent.md +0 -745
  57. lean_memory-0.1.1/docs/superpowers/plans/2026-06-21-mcp-server.md +0 -488
  58. lean_memory-0.1.1/docs/superpowers/plans/2026-07-02-phase2-eval-harness.md +0 -2201
  59. lean_memory-0.1.1/docs/superpowers/plans/2026-07-08-launch-quality-gate.md +0 -1062
  60. lean_memory-0.1.1/docs/superpowers/specs/2026-07-02-phase2-eval-harness-design.md +0 -249
  61. lean_memory-0.1.1/docs/superpowers/specs/2026-07-08-strategic-direction-design.md +0 -141
  62. lean_memory-0.1.1/docs/superpowers/workpackets.md +0 -414
  63. lean_memory-0.1.1/tests/fixtures/phase2/lme_oracle_mini.json +0 -26
  64. lean_memory-0.1.1/tests/fixtures/phase2/lme_s_mini.json +0 -36
  65. lean_memory-0.1.1/tests/fixtures/phase2/locomo_mini.json +0 -23
  66. lean_memory-0.1.1/tests/test_escalation_probe.py +0 -64
  67. lean_memory-0.1.1/tests/test_phase2_eval.py +0 -98
  68. lean_memory-0.1.1/tests/test_phase2_ingest.py +0 -212
  69. lean_memory-0.1.1/tests/test_phase2_judge.py +0 -70
  70. lean_memory-0.1.1/tests/test_phase2_reader.py +0 -41
  71. {lean_memory-0.1.1 → lean_memory-0.1.3}/.gitignore +0 -0
  72. {lean_memory-0.1.1 → lean_memory-0.1.3}/ARCHITECTURE.md +0 -0
  73. {lean_memory-0.1.1 → lean_memory-0.1.3}/PERFORMANCE.md +0 -0
  74. {lean_memory-0.1.1 → lean_memory-0.1.3}/examples/chat.py +0 -0
  75. {lean_memory-0.1.1 → lean_memory-0.1.3}/examples/mcp_config.json +0 -0
  76. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/embed/__init__.py +0 -0
  77. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/embed/base.py +0 -0
  78. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/embed/fake.py +0 -0
  79. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/__init__.py +0 -0
  80. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/llm_typer.py +0 -0
  81. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/router.py +0 -0
  82. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/rules.py +0 -0
  83. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/salience.py +0 -0
  84. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/extract/taxonomy.py +0 -0
  85. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/retrieve/__init__.py +0 -0
  86. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/retrieve/retriever.py +0 -0
  87. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/store/__init__.py +0 -0
  88. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/store/base.py +0 -0
  89. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/store/schema.py +0 -0
  90. {lean_memory-0.1.1 → lean_memory-0.1.3}/src/lean_memory/types.py +0 -0
  91. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_asof_sparse.py +0 -0
  92. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_chat.py +0 -0
  93. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_contradiction_extends.py +0 -0
  94. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_embedder_default.py +0 -0
  95. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_known_entities_cap.py +0 -0
  96. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_mcp_server.py +0 -0
  97. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_phase1_extraction.py +0 -0
  98. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_router.py +0 -0
  99. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_search_now.py +0 -0
  100. {lean_memory-0.1.1 → lean_memory-0.1.3}/tests/test_spine.py +0 -0
@@ -0,0 +1,123 @@
1
+ # Changelog
2
+
3
+ All notable changes to lean-memory are documented here. The format is based on
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.3] - 2026-07-12
8
+
9
+ Publish-readiness release: an independent multi-team review of v0.1.2 found
10
+ three launch blockers on the canonical MCP first-run path plus packaging and
11
+ correctness majors — all fixed here.
12
+
13
+ ### Fixed
14
+ - **MCP Registry install crashed on startup**: `server.json` ran
15
+ `uvx --from lean-memory lean-memory-mcp`, but `mcp` is an optional extra, so
16
+ every registry install died with `ModuleNotFoundError`. The manifest now
17
+ installs `lean-memory[mcp,models,extract]` (pinned by a manifest test).
18
+ - **Model banner corrupted the MCP stdio stream**: gliner2's `from_pretrained`
19
+ prints a config banner to stdout — the JSON-RPC channel — on the first
20
+ `memory_add` of the canonical install. All model lazy-loads (GLiNER2,
21
+ SentenceTransformer, CrossEncoder) now route load-time chatter to stderr.
22
+ - **Embedder swap bricked existing namespaces**: reopening a DB created with a
23
+ different embedder dimension (768-dim offline stub → 1024-dim Qwen after
24
+ installing `[models]`) failed deep in retrieval with an opaque shape error;
25
+ the store now refuses the mismatch at open with an actionable message.
26
+ - **Uppercase FTS5 operator words crashed search**: `'coffee AND tea'` raised
27
+ `sqlite3.OperationalError` through `Memory.search` and the `memory_search`
28
+ tool. Terms are now quoted FTS5 string literals; the sparse arm degrades to
29
+ no-hits on any residual syntax error.
30
+ - **Functional-slot supersession left stale facts current**: a replacement
31
+ retired only the single most-similar fact, so a slot extended by an additive
32
+ cue ("I also work at Globex.") kept two conflicting current employers. A
33
+ replacement on a functional slot now retires every co-valid latest fact;
34
+ multi-valued slots keep single-target retirement.
35
+ - **High-similarity band ignored multi-valued slots**: with real embedders,
36
+ distinct co-valid values on a multi-valued slot (jazz/blues) embed at cosine
37
+ 0.6–0.95 and were silently superseded; multi-valued predicates now stay
38
+ co-valid in every band (new resolver route: `high_extends_additive`).
39
+ Predicate-scoped on purpose: the textual cue ("and"/"also") stays a
40
+ low/mid-band signal so a conjunction-phrased replacement still supersedes.
41
+ - **`[llm]` extra crashed every add() with Ollama stopped**: `Memory.add` now
42
+ catches `TyperError` and stub-types the escalated batch, as the typer
43
+ contract always documented.
44
+ - **Packaging**: Apache-2.0 `LICENSE` added (repo, wheel, and sdist — the
45
+ license was previously declared but its text shipped nowhere); the sdist is
46
+ scoped to user-facing files (0.1.2 shipped internal strategy docs, agent
47
+ instructions, and the bench harness to PyPI); the README hero GIF uses an
48
+ absolute URL so the PyPI page renders it; the demo-agent flow is clone-based
49
+ (the script was never in the wheel).
50
+
51
+ ### Added
52
+ - Schema-version stamp (`PRAGMA user_version = 1`) as the migration anchor for
53
+ 0.1.x namespace files (pre-stamp files upgrade in place; newer stamps are
54
+ never downgraded).
55
+ - `LM_FORCE_STUBS` env var pins the offline stub backends in the MCP server
56
+ (for tests/CI that must never load a model).
57
+ - Subprocess-level MCP stdio protocol test: handshake + real tool call, every
58
+ stdout line must parse as JSON. CI matrix now covers Python 3.11/3.12.
59
+
60
+ ## [0.1.2] - 2026-07-12
61
+
62
+ ### Fixed
63
+ - MCP Registry namespace case: `io.github.Wuesteon/lean-memory` (the registry's
64
+ PyPI ownership marker is compared case-exactly against the published README).
65
+
66
+ ## [0.1.1] - 2026-07-12
67
+
68
+ ### Added
69
+ - MCP Registry metadata: `server.json` (io.github.wuesteon/lean-memory) and an
70
+ OIDC publish workflow; `mcp-name` ownership marker in the README (required by
71
+ the registry's PyPI validation — the reason for this patch release).
72
+
73
+ ## [0.1.0] - 2026-07-12
74
+
75
+ First public release. lean-memory is an embedded, local-first agent-memory
76
+ engine: one SQLite file per namespace, hybrid dense+sparse retrieval with
77
+ rerank, and ADD-only supersession queryable at any past point in time
78
+ (`as_of`). No server, no daemon, no mandatory cloud key.
79
+
80
+ ### Added
81
+
82
+ - **MCP server** exposing memory as three tools (`memory_add`, `memory_search`,
83
+ `memory_clear`) for Claude Code, Claude Desktop, and other MCP clients.
84
+ Canonical install `pip install 'lean-memory[mcp,models,extract]'`
85
+ opportunistically upgrades each backend whose extra is present (real embedder
86
+ + reranker via `[models]`, GLiNER2 extraction via `[extract]`) and otherwise
87
+ falls back to deterministic offline stubs. Two-minute quickstart with
88
+ copy-paste Claude Code / Claude Desktop config and a demo GIF.
89
+ - **`Memory.search(now=...)`** — recency decay now anchors to a caller-supplied
90
+ timestamp, so the 0.2 recency term is no longer dead on historical corpora.
91
+ - **Point-in-time queries** via `as_of` (epoch ms) with `is_latest_only=False`.
92
+ - **CI + release workflows** (GitHub Actions): offline test matrix on
93
+ ubuntu/macOS × Python 3.10/3.13, plus build-and-publish to PyPI on `v*` tag
94
+ via Trusted Publishing.
95
+ - PyPI metadata: keywords, classifiers, and project URLs.
96
+
97
+ ### Changed
98
+
99
+ - **Default embedder is now the ungated Qwen3-Embedding-0.6B** (was a gated
100
+ Gemma model that broke the `[models]` first run). Reranker default is
101
+ Ettin-32M; both are pinned ungated and covered by regression tests.
102
+ - **Escalation engine recalibrated on real conversational turns.** Endpoint-
103
+ scoped coreference/ellipsis detection replaces the whole-text pronoun scan
104
+ (coreference escalations dropped from 65.6% to effectively nil on real
105
+ turns), and the `prior_entity` trigger was retired (subject re-mention is
106
+ normal discourse, measured at 52.8% of candidates). At the re-frozen
107
+ `(typing_threshold=0.4, conf_threshold=0.4)` operating point, escalation on
108
+ the real LongMemEval probe is **14.6%** (was ~96% pre-fix), with the residual
109
+ being irreducible inferential-edge (`derives`) escalations. BET-2 three-gate
110
+ revalidation PASSes at this operating point.
111
+ - **Extraction granularity calibrated** — GLiNER candidate threshold set to
112
+ 0.4, cutting the extractor from ~8 facts/turn to ~3.7 so `fact_text` reads as
113
+ facts rather than whole utterances.
114
+ - MCP server loads models lazily (first tool call rather than import) so a
115
+ cold-cache spawn answers the MCP handshake immediately instead of blocking on
116
+ a model download; search output is deduplicated.
117
+
118
+ ### Fixed
119
+
120
+ - Sparse BM25 retrieval arm now honors the `as_of` interval predicate.
121
+ - Known-entities handed to the router/typer are capped at the 100 most recent.
122
+
123
+ [0.1.0]: https://github.com/Wuesteon/lean-memory/releases/tag/v0.1.0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lean-memory
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Embedded, local-first agent memory with hybrid retrieval and ADD-only supersession.
5
5
  Project-URL: Homepage, https://github.com/Wuesteon/lean-memory
6
6
  Project-URL: Repository, https://github.com/Wuesteon/lean-memory
7
7
  Author: lean-memory
8
8
  License: Apache-2.0
9
+ License-File: LICENSE
9
10
  Keywords: agent-memory,embeddings,llm,local-first,mcp,memory,rag,retrieval,sqlite,vector-search
10
11
  Classifier: Development Status :: 4 - Beta
11
12
  Classifier: Intended Audience :: Developers
@@ -65,7 +66,7 @@ mem.add("user-42", "I now work at Globex.") # supersedes Acme automatic
65
66
  mem.search("user-42", "where does the user work?") # → "I now work at Globex."
66
67
  ```
67
68
 
68
- ![lean-memory quickstart](docs/assets/quickstart.gif)
69
+ ![lean-memory quickstart](https://raw.githubusercontent.com/Wuesteon/lean-memory/main/docs/assets/quickstart.gif)
69
70
 
70
71
  Facts are extracted from natural language, stored in a per-namespace SQLite file, and retrieved with hybrid dense+sparse search. Old facts are never deleted — they're superseded and queryable at any past point in time.
71
72
 
@@ -111,10 +112,12 @@ mem.close()
111
112
 
112
113
  ## Demo Agent
113
114
 
114
- A terminal chatbot showing the full memory loop — add, retrieve, supersede, restart:
115
+ A terminal chatbot showing the full memory loop — add, retrieve, supersede, restart.
116
+ The demo script lives in the repo (it is not installed with the package):
115
117
 
116
118
  ```bash
117
- pip install 'lean-memory[examples]'
119
+ git clone https://github.com/Wuesteon/lean-memory && cd lean-memory
120
+ pip install -e '.[examples]'
118
121
  export ANTHROPIC_API_KEY=sk-ant-...
119
122
  python examples/chat.py # uses offline stubs by default
120
123
  python examples/chat.py --namespace bob # separate memory tenant, persists across restarts
@@ -227,5 +230,5 @@ bench/ Retrieval quality + BET-2 ablation harnesses
227
230
 
228
231
  Apache-2.0
229
232
 
230
- <!-- mcp-name: io.github.wuesteon/lean-memory -->
233
+ <!-- mcp-name: io.github.Wuesteon/lean-memory -->
231
234
 
@@ -21,7 +21,7 @@ mem.add("user-42", "I now work at Globex.") # supersedes Acme automatic
21
21
  mem.search("user-42", "where does the user work?") # → "I now work at Globex."
22
22
  ```
23
23
 
24
- ![lean-memory quickstart](docs/assets/quickstart.gif)
24
+ ![lean-memory quickstart](https://raw.githubusercontent.com/Wuesteon/lean-memory/main/docs/assets/quickstart.gif)
25
25
 
26
26
  Facts are extracted from natural language, stored in a per-namespace SQLite file, and retrieved with hybrid dense+sparse search. Old facts are never deleted — they're superseded and queryable at any past point in time.
27
27
 
@@ -67,10 +67,12 @@ mem.close()
67
67
 
68
68
  ## Demo Agent
69
69
 
70
- A terminal chatbot showing the full memory loop — add, retrieve, supersede, restart:
70
+ A terminal chatbot showing the full memory loop — add, retrieve, supersede, restart.
71
+ The demo script lives in the repo (it is not installed with the package):
71
72
 
72
73
  ```bash
73
- pip install 'lean-memory[examples]'
74
+ git clone https://github.com/Wuesteon/lean-memory && cd lean-memory
75
+ pip install -e '.[examples]'
74
76
  export ANTHROPIC_API_KEY=sk-ant-...
75
77
  python examples/chat.py # uses offline stubs by default
76
78
  python examples/chat.py --namespace bob # separate memory tenant, persists across restarts
@@ -183,5 +185,5 @@ bench/ Retrieval quality + BET-2 ablation harnesses
183
185
 
184
186
  Apache-2.0
185
187
 
186
- <!-- mcp-name: io.github.wuesteon/lean-memory -->
188
+ <!-- mcp-name: io.github.Wuesteon/lean-memory -->
187
189
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lean-memory"
3
- version = "0.1.1"
3
+ version = "0.1.3"
4
4
  description = "Embedded, local-first agent memory with hybrid retrieval and ADD-only supersession."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -88,6 +88,35 @@ build-backend = "hatchling.build"
88
88
  [tool.hatch.build.targets.wheel]
89
89
  packages = ["src/lean_memory"]
90
90
 
91
+ # The sdist is a public artifact: allowlist what a user or downstream packager
92
+ # needs. Without this, hatchling ships every tracked file — which for 0.1.2
93
+ # meant internal strategy docs (docs/superpowers/), agent instructions
94
+ # (CLAUDE.md), and the whole bench/ harness went to PyPI.
95
+ [tool.hatch.build.targets.sdist]
96
+ # Leading slashes anchor to the project root (gitwildmatch): an unanchored
97
+ # "src/" would also match e.g. .claude/worktrees/*/src/ at any depth.
98
+ include = [
99
+ "/src/",
100
+ "/tests/",
101
+ "/examples/",
102
+ "/README.md",
103
+ "/ARCHITECTURE.md",
104
+ "/PERFORMANCE.md",
105
+ "/CHANGELOG.md",
106
+ "/LICENSE",
107
+ "/server.json",
108
+ "/pyproject.toml",
109
+ ]
110
+ exclude = [
111
+ "/.claude/",
112
+ "/.gitignore",
113
+ # These test the bench/ harness (not shipped) via sys.path insertion and
114
+ # cannot collect without it; the fixtures are their LongMemEval-derived data.
115
+ "/tests/test_phase2_*.py",
116
+ "/tests/test_escalation_probe.py",
117
+ "/tests/fixtures/",
118
+ ]
119
+
91
120
  [tool.pytest.ini_options]
92
121
  pythonpath = ["src"]
93
122
  testpaths = ["tests"]
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
- "name": "io.github.wuesteon/lean-memory",
3
+ "name": "io.github.Wuesteon/lean-memory",
4
4
  "description": "Embedded, local-first agent memory: one SQLite file per namespace, no server, no cloud.",
5
5
  "title": "lean-memory",
6
6
  "repository": {
7
7
  "url": "https://github.com/Wuesteon/lean-memory",
8
8
  "source": "github"
9
9
  },
10
- "version": "0.1.1",
10
+ "version": "0.1.3",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "pypi",
14
14
  "registryBaseUrl": "https://pypi.org",
15
15
  "identifier": "lean-memory",
16
- "version": "0.1.1",
16
+ "version": "0.1.3",
17
17
  "runtimeHint": "uvx",
18
18
  "transport": {
19
19
  "type": "stdio"
@@ -22,9 +22,9 @@
22
22
  {
23
23
  "type": "named",
24
24
  "name": "--from",
25
- "value": "lean-memory",
25
+ "value": "lean-memory[mcp,models,extract]",
26
26
  "isRequired": true,
27
- "description": "Install the lean-memory package, then run its lean-memory-mcp console-script entry point (the package name and script name differ, so uvx needs --from)."
27
+ "description": "Install lean-memory with the extras the server needs: [mcp] (imported at startup — a bare install crashes), plus [models] and [extract] (the canonical real-quality backends; ~2 GB of open models download on first tool call). The package name and script name differ, so uvx needs --from."
28
28
  }
29
29
  ],
30
30
  "packageArguments": [
@@ -11,4 +11,4 @@ from .memory import Memory
11
11
  from .types import Entity, Episode, Fact, RetrievedFact
12
12
 
13
13
  __all__ = ["Memory", "Episode", "Entity", "Fact", "RetrievedFact"]
14
- __version__ = "0.1.1" # keep in sync with pyproject.toml [project].version
14
+ __version__ = "0.1.3" # keep in sync with pyproject.toml [project].version
@@ -11,6 +11,9 @@ required). Both load through this one class. Requires the `models` extra
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
+ import contextlib
15
+ import sys
16
+
14
17
  import numpy as np
15
18
 
16
19
  from .base import Embedder
@@ -48,7 +51,10 @@ class SentenceTransformerEmbedder(Embedder):
48
51
  "SentenceTransformerEmbedder needs the 'models' extra: "
49
52
  "pip install 'lean-memory[models]'"
50
53
  ) from e
51
- self._model = SentenceTransformer(self.model_name, device=self._device)
54
+ # stdout is the MCP stdio protocol channel — any load-time library
55
+ # chatter there would corrupt JSON-RPC framing on a lazy first load.
56
+ with contextlib.redirect_stdout(sys.stderr):
57
+ self._model = SentenceTransformer(self.model_name, device=self._device)
52
58
  self.dim = self._model.get_sentence_embedding_dimension() or self.dim
53
59
  return self._model
54
60
 
@@ -98,6 +98,15 @@ _MULTIVALUED_PREDICATES = frozenset(
98
98
  )
99
99
 
100
100
 
101
+ def is_multivalued(predicate: str) -> bool:
102
+ """Does this predicate naturally hold many co-valid values at once?
103
+
104
+ Multi-valued slots (likes/uses/knows/...) accumulate; everything else is
105
+ FUNCTIONAL — one current value, so a replacement retires the whole slot
106
+ (memory.py applies supersession accordingly)."""
107
+ return predicate in _MULTIVALUED_PREDICATES
108
+
109
+
101
110
  @runtime_checkable
102
111
  class LLMTyper(Protocol):
103
112
  """Pass-4 constrained-typing backend, narrowed to the adjudication this resolver needs.
@@ -217,6 +226,19 @@ class ContradictionResolver:
217
226
  return Decision(
218
227
  label=EXTENDS, target=best, similarity=best_sim, route="high_extends"
219
228
  )
229
+ # Multi-valued predicates stay co-valid at EVERY band: with the real
230
+ # default embedder, distinct co-valid values on a multi-valued slot
231
+ # (jazz/blues, Python/Rust) embed at cosine 0.6-0.95, so without this
232
+ # check the high band silently retired facts the user still holds.
233
+ # PREDICATE-scoped on purpose — the textual _ADDITIVE_CUE ('and',
234
+ # 'also') is too weak here: at high cosine a replacement phrased with
235
+ # a conjunction ('I left Acme and now work at Globex.') would keep a
236
+ # stale value on a functional slot.
237
+ if is_multivalued(new_fact.predicate):
238
+ return Decision(
239
+ label=EXTENDS, target=best, similarity=best_sim,
240
+ route="high_extends_additive",
241
+ )
220
242
  # Same object, no added detail and not equal text ⇒ a restated change
221
243
  # (e.g. "moved to Berlin" vs "moved to Munich" that still embed close):
222
244
  # treat as a replacement on the slot.
@@ -29,7 +29,9 @@ router's escalation rate (<20% target), not the candidate count.
29
29
 
30
30
  from __future__ import annotations
31
31
 
32
+ import contextlib
32
33
  import re
34
+ import sys
33
35
  from abc import ABC, abstractmethod
34
36
  from typing import Any, Optional
35
37
 
@@ -161,7 +163,11 @@ class Gliner2Generator(CandidateGenerator):
161
163
  ) from exc
162
164
  # map_location="cpu" keeps us on CPU even if a checkpoint defaults elsewhere; the base
163
165
  # model is built for efficient CPU inference (no GPU required).
164
- self._model = GLiNER2.from_pretrained(self.model_name, map_location="cpu")
166
+ # stdout is the MCP stdio protocol channel: gliner2's from_pretrained prints a
167
+ # model-config banner with bare print(), which would interleave with JSON-RPC
168
+ # framing on the first lazy load. Route load-time chatter to stderr.
169
+ with contextlib.redirect_stdout(sys.stderr):
170
+ self._model = GLiNER2.from_pretrained(self.model_name, map_location="cpu")
165
171
  return self._model
166
172
 
167
173
  def generate(self, episode: Episode) -> list[Candidate]:
@@ -46,7 +46,13 @@ def _build_memory(root: Path) -> Memory:
46
46
  Each successful upgrade logs ONE line to stderr (stdout is the MCP protocol
47
47
  channel — NEVER print to stdout here) so cold-cache users, who wait through a
48
48
  ~2 GB download on first tool call, see progress in their client's server logs.
49
+
50
+ LM_FORCE_STUBS (env) pins the deterministic offline stubs even when the
51
+ extras are installed — for tests/CI that must never load a model.
49
52
  """
53
+ if os.environ.get("LM_FORCE_STUBS"):
54
+ return Memory(root=root)
55
+
50
56
  kwargs: dict = {}
51
57
 
52
58
  try: