memsave 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- memsave-0.2.0/LICENSE +202 -0
- memsave-0.2.0/PKG-INFO +281 -0
- memsave-0.2.0/README.md +250 -0
- memsave-0.2.0/memsave/__init__.py +12 -0
- memsave-0.2.0/memsave/__main__.py +3 -0
- memsave-0.2.0/memsave/afdian.py +310 -0
- memsave-0.2.0/memsave/billing.py +574 -0
- memsave-0.2.0/memsave/budget.py +71 -0
- memsave-0.2.0/memsave/cli.py +360 -0
- memsave-0.2.0/memsave/distill.py +211 -0
- memsave-0.2.0/memsave/embed.py +191 -0
- memsave-0.2.0/memsave/export.py +144 -0
- memsave-0.2.0/memsave/license.py +200 -0
- memsave-0.2.0/memsave/ops.py +392 -0
- memsave-0.2.0/memsave/server.py +287 -0
- memsave-0.2.0/memsave/store.py +548 -0
- memsave-0.2.0/memsave/tokenize.py +116 -0
- memsave-0.2.0/memsave/webhook.py +246 -0
- memsave-0.2.0/memsave.egg-info/PKG-INFO +281 -0
- memsave-0.2.0/memsave.egg-info/SOURCES.txt +26 -0
- memsave-0.2.0/memsave.egg-info/dependency_links.txt +1 -0
- memsave-0.2.0/memsave.egg-info/entry_points.txt +2 -0
- memsave-0.2.0/memsave.egg-info/requires.txt +8 -0
- memsave-0.2.0/memsave.egg-info/top_level.txt +1 -0
- memsave-0.2.0/pyproject.toml +46 -0
- memsave-0.2.0/setup.cfg +4 -0
- memsave-0.2.0/tests/test_core.py +602 -0
- memsave-0.2.0/tests/test_reconcile.py +103 -0
memsave-0.2.0/LICENSE
ADDED
|
@@ -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.
|
memsave-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: memsave
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Read AI memories without spending credits — local, free hybrid retrieval
|
|
5
|
+
Author: memsave contributors
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://memsave.app.workbuddy.host/?sharecode=5V43SCBI5Q
|
|
8
|
+
Project-URL: Documentation, https://memsave.app.workbuddy.host/guide.html?sharecode=5V43SCBI5Q
|
|
9
|
+
Project-URL: Funding, https://afdian.com/item/6f246044d49611f1b0a4525400c8052f
|
|
10
|
+
Keywords: memory,mcp,rag,bm25,embeddings,llm,context,token
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: local
|
|
25
|
+
Requires-Dist: onnxruntime>=1.16; extra == "local"
|
|
26
|
+
Requires-Dist: numpy>=1.24; extra == "local"
|
|
27
|
+
Requires-Dist: tokenizers>=0.15; extra == "local"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# memsave
|
|
33
|
+
|
|
34
|
+
读回忆不花积分。
|
|
35
|
+
|
|
36
|
+
大多数"记忆系统"贵在一个地方:它们把整座记忆库灌进上下文,然后让大模型自己去判断哪条相关。上下文是唯一稀缺资源,于是每想一次都要重新付一遍钱。
|
|
37
|
+
|
|
38
|
+
memsave 反过来做:**检索全程跑在本地 CPU 上,一次模型调用都不发,只把真正命中的那一小段送进上下文。**
|
|
39
|
+
|
|
40
|
+
## 核心方法
|
|
41
|
+
|
|
42
|
+
**1. 检索不要过模型**
|
|
43
|
+
- `SQLite FTS5` + BM25 做关键词召回。记忆这种命名实体密集的文本(人名、项目名、术语),关键词命中率高得离谱。
|
|
44
|
+
- 中文没有空格,所以 CJK 串切成重叠 bigram 再索引 —— 零依赖,不需要分词库。
|
|
45
|
+
- 可选 24MB 的 `bge-small-zh-v1.5` ONNX 模型做语义重排,CPU 单条 5–15ms。没装就退化成哈希向量,照样免费。
|
|
46
|
+
|
|
47
|
+
**2. 三层分级,只加载最薄的一层**
|
|
48
|
+
|
|
49
|
+
| 层 | 内容 | 体积 | 时机 |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| L0 | 标题 + 自动关键词 | ~17 token/条 | 常驻系统提示 |
|
|
52
|
+
| L1 | 摘要 | ~80 token | 命中后加载 |
|
|
53
|
+
| L2 | 原文 | 实际长度 | 显式请求才取 |
|
|
54
|
+
|
|
55
|
+
L0 大小**恒定**:不管库里 300 条还是 5000 条,索引都是约 1000 token,因为只取 Top-N。
|
|
56
|
+
|
|
57
|
+
**3. 成本从读取侧搬到写入侧**
|
|
58
|
+
原始对话流水账不要存。存蒸馏后的事实:谁 / 做了什么 / 何时 / 决策 / 偏好。写一次花一次钱,之后读一万次都是零。
|
|
59
|
+
|
|
60
|
+
**4. 文档只在写入时被处理一次**
|
|
61
|
+
分词、关键词、向量、token 计数,全部在写入时算好存进表里。检索时唯一的计算是点积。
|
|
62
|
+
|
|
63
|
+
## 实测数据
|
|
64
|
+
|
|
65
|
+
300 条记忆库:
|
|
66
|
+
|
|
67
|
+
| 查询 | 注入 | 全库基线 | 省下 | 耗时 |
|
|
68
|
+
|---|---|---|---|---|
|
|
69
|
+
| 老陈负责哪个项目 | 140 | 33,442 | 33,302 | 11.8ms |
|
|
70
|
+
| Alpha 排期 | 145 | 33,442 | 32,297 | 13.3ms |
|
|
71
|
+
| 预算上限 | 115 | 33,442 | 33,327 | 9.0ms |
|
|
72
|
+
|
|
73
|
+
5000 条记忆库:压缩比 **0.02%**,检索 35–70ms,L0 索引仍是 1051 token。
|
|
74
|
+
|
|
75
|
+
## 安装
|
|
76
|
+
|
|
77
|
+
给**用户**装(对外分发用 wheel 直装,包名在 PyPI 尚未发布):
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install https://memsave.app.workbuddy.host/memsave-0.2.0-py3-none-any.whl?sharecode=5V43SCBI5Q
|
|
81
|
+
python -m memsave stats # 看到统计输出就装好了
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
给**开发者**装(从源码):
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
pip install -e . # 零依赖核心,BM25 检索开箱可用
|
|
88
|
+
pip install -e ".[local]" # 可选:加上本地语义模型
|
|
89
|
+
python -m memsave embedder install
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
完整上手步骤见 **[`site/guide.html`](site/guide.html)**(使用教程,已上线)。
|
|
93
|
+
|
|
94
|
+
## 用法
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# 手写摘要(推荐:你比启发式更清楚什么重要)
|
|
98
|
+
python -m memsave add "Alpha 项目延期" \
|
|
99
|
+
--summary "Alpha 因 GPU 到货延迟推到 11 月 15 日" \
|
|
100
|
+
--body "2026-10-12 会议决定:上线时间从 10/30 推迟到 11/15…" \
|
|
101
|
+
--kind decision --tags "alpha,排期" --salience 0.9 --pinned
|
|
102
|
+
|
|
103
|
+
# 丢原始文本进去自动蒸馏,--llm 用你自己的 key 蒸馏得更好
|
|
104
|
+
python -m memsave add "会议决定:Alpha 上线时间推迟到 11/15,因 H800 到货延迟" --raw
|
|
105
|
+
python -m memsave add "会议决定:Alpha 上线时间推迟到 11/15" --raw --llm
|
|
106
|
+
|
|
107
|
+
python -m memsave search "Alpha 排期"
|
|
108
|
+
python -m memsave index # 输出 L0,粘进系统提示
|
|
109
|
+
python -m memsave stats # 省了多少 token / 多少钱
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 写入侧蒸馏:唯一该花钱的地方
|
|
113
|
+
|
|
114
|
+
一条记忆写一次,读无数次。所以蒸馏是**唯一值得调用 LLM 的地方** —— 一次调用,永久摊销。
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
export OPENAI_API_KEY=sk-... # 也支持任何 /chat/completions 兼容端点
|
|
118
|
+
export OPENAI_BASE_URL=https://api.deepseek.com/v1
|
|
119
|
+
export MEMSAVE_LLM_MODEL=deepseek-chat
|
|
120
|
+
|
|
121
|
+
python -m memsave distill "会议开了两小时,最后老陈拍板说预算就卡在 80 万" --llm
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
不配 key 也能跑,走启发式:按句切分取首句、按提示词分类(`决定`→decision、`偏好`→preference)、按重要度给权重(偏好 0.85 > 决策 0.80 > 一次性事件 0.40)。
|
|
125
|
+
|
|
126
|
+
**LLM 挂了就自动退回启发式,绝不丢记忆。**
|
|
127
|
+
|
|
128
|
+
## 导出(免费版也有)
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
python -m memsave export ~/memories.md
|
|
132
|
+
python -m memsave export ~/memories.json --format json
|
|
133
|
+
python -m memsave import ~/memories.json # 合并
|
|
134
|
+
python -m memsave import ~/memories.json --replace
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
记忆是用户的资产,不是 lock-in 的筹码。**给不了干净导出的产品,用户就不敢往里放真正重要的东西。**
|
|
138
|
+
|
|
139
|
+
## 授权
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
python -m memsave license status
|
|
143
|
+
python -m memsave license activate MSV1-XXXX.XXXXXXXX
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
签发给客户:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
export MEMSAVE_LICENSE_SECRET="<换成你自己的长随机串>"
|
|
150
|
+
python -m memsave license issue --email a@b.com --tier pro # 永久
|
|
151
|
+
python -m memsave license issue --email a@b.com --tier team --days 365 --seats 20
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
看清楚这一点:**客户端授权是减速带,不是锁。** 任何客户端校验都能被提取密钥绕过。它的作用是让"付费"比"破解"更省事。真正的闸门在服务端 —— 同步、团队共享、更新,这些本来就要联网,校验应该放在那里。别在客户端 DRM 上烧工程时间。
|
|
155
|
+
|
|
156
|
+
## 收款与自动发码
|
|
157
|
+
|
|
158
|
+
从"有产品"到"有钱进账",差的只是一个 HTTP 端点。`billing` 就是那个端点,标准库实现,不需要任何 web 框架。
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
export MEMSAVE_LICENSE_SECRET="<你自己的长随机串>"
|
|
162
|
+
export STRIPE_WEBHOOK_SECRET="whsec_..."
|
|
163
|
+
|
|
164
|
+
# SMTP,不配就落盘等待人工发送,绝不丢码
|
|
165
|
+
export SMTP_HOST=smtp.resend.com SMTP_PORT=587
|
|
166
|
+
export SMTP_USER=apikey SMTP_PASS=re_xxx MAIL_FROM=billing@yourdomain.com
|
|
167
|
+
|
|
168
|
+
python -m memsave billing test # 不发网络请求的自检
|
|
169
|
+
python -m memsave billing serve --provider stripe --port 8787
|
|
170
|
+
python -m memsave billing stats # 订单 / 已发送 / 待发送
|
|
171
|
+
python -m memsave billing pending # 列出待人工发送的授权码
|
|
172
|
+
python -m memsave billing retry # 邮件失败后补发
|
|
173
|
+
python -m memsave billing reconcile --provider afdian --days 3 # 对账补漏单
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`reconcile` 是"不买服务器"这条路的兜底:webhook 是推送,你关机时收不到。
|
|
177
|
+
它反过来主动去平台拉订单,只补发本地账本里没有的(走同一套三道闸和幂等账本,
|
|
178
|
+
重复跑不会重复发码)。详见 **[`docs/hosting.md`](docs/hosting.md)**。
|
|
179
|
+
|
|
180
|
+
Stripe 后台配 `checkout.session.completed`,Lemon Squeezy 配 `order_created`。创建 Checkout Session 时带上 `metadata: {"tier": "pro", "seats": 1}`(`days` 留空即永久)。
|
|
181
|
+
|
|
182
|
+
放 Caddy 后面:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
pay.yourdomain.com { reverse_proxy 127.0.0.1:8787 }
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**默认只监听 127.0.0.1。** `--public` 是给容器用的,不是给笔记本用的。
|
|
189
|
+
|
|
190
|
+
### 三条不可妥协的规则
|
|
191
|
+
|
|
192
|
+
1. **验签必须开。** 不验签的 webhook 就是一台任何人都能 POST 的免费发码机。签名密钥每次请求都重新读取,轮换不用重启。
|
|
193
|
+
2. **幂等由本地账本保证,不信 provider。** Stripe 收到任何非 2xx 都会重试,而且重试不止一次。没有幂等,客户会收到三把不同的钥匙,然后不知道该用哪把。
|
|
194
|
+
3. **授权码绝不丢。** 邮件发不出去就落盘到 `~/.memsave/pending-delivery/`,然后 `billing pending` 人工补发。静默丢码是一张无法挽回的工单。
|
|
195
|
+
|
|
196
|
+
## 运维
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
memsave ops doctor # 体检:密钥 / 数据库完整性 / 磁盘 / 邮件积压
|
|
200
|
+
memsave ops backup # 备份(自动校验可读性)
|
|
201
|
+
memsave ops restore <file> # 恢复(先把当前状态另存,绝不直接覆盖)
|
|
202
|
+
memsave ops prune --keep 14 # 清理旧备份
|
|
203
|
+
memsave ops new-secret # 生成密钥
|
|
204
|
+
memsave ops rotate-key <新密钥> # 轮换并重新签发全部已售授权码
|
|
205
|
+
memsave ops audit . # 扫描硬编码密钥,发布前必做
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
服务器部署:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
sudo ./deploy/install.sh # 建用户、装服务、配 cron 备份、给 Caddy 提示
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
完整运维流程、故障排查表、应急预案见 **[`docs/operations.md`](docs/operations.md)**。
|
|
215
|
+
|
|
216
|
+
一句话说清运维的本质:**每天能回答"它健康吗",以及随时能把数据拿回来。** 其余都是细节。
|
|
217
|
+
|
|
218
|
+
## 文档
|
|
219
|
+
|
|
220
|
+
| 文档 | 内容 |
|
|
221
|
+
|---|---|
|
|
222
|
+
| [`README.md`](README.md) | 安装、用法、原理、收款、运维 |
|
|
223
|
+
| [`site/guide.html`](site/guide.html) | **用户使用教程**(已上线,含各客户端配置路径与排错) |
|
|
224
|
+
| [`docs/pricing.md`](docs/pricing.md) | 付费模式设计、上线清单、护城河与风险 |
|
|
225
|
+
| [`docs/operations.md`](docs/operations.md) | 运维手册、故障排查、应急预案 |
|
|
226
|
+
| [`docs/marketing.md`](docs/marketing.md) | 推广骨架与口径 |
|
|
227
|
+
| [`promo/README.md`](promo/README.md) | **推广执行包**:口径卡 + 发布追踪表(先看这个) |
|
|
228
|
+
| [`promo/06-video.md`](promo/06-video.md) | 推广视频:分镜、口播稿、各平台配文 |
|
|
229
|
+
| [`docs/hosting.md`](docs/hosting.md) | **托管方案**:为什么现在不用买服务器 |
|
|
230
|
+
| [`docs/pypi-release.md`](docs/pypi-release.md) | **PyPI 发布**:注册 → token → 上传(工程已就绪,只差你 3 步) |
|
|
231
|
+
| [`CHANGELOG.md`](CHANGELOG.md) | 版本记录 |
|
|
232
|
+
|
|
233
|
+
## 接进任意 AI(MCP)
|
|
234
|
+
|
|
235
|
+
MCP 是"让所有 AI 都能调用"的答案:Claude Desktop、Cursor、Windsurf、Cline、WorkBuddy 都支持。
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"mcpServers": {
|
|
240
|
+
"memsave": {
|
|
241
|
+
"command": "python",
|
|
242
|
+
"args": ["-m", "memsave", "serve"],
|
|
243
|
+
"env": { "MEMSAVE_HOME": "C:/Users/you/.memsave" }
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
暴露 9 个工具:`memory_index` / `memory_search` / `memory_get` / `memory_add`(支持 `raw` 自动蒸馏)/ `memory_update` / `memory_forget` / `memory_export` / `memory_license` / `memory_stats`。
|
|
250
|
+
|
|
251
|
+
每次 `memory_search` 的返回都在末尾附一行统计:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
本轮注入 140 token,全库基线 33442 token,省下 33302 token。
|
|
255
|
+
累计 6 次调用共省下 199,858 token (≈ $0.60)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**这个数字就是产品本身。** 用户不需要你解释技术原理,他只需要看到"本次对话省了 3 万 token"。当省下的钱超过定价时,付费没有任何心理阻力。
|
|
259
|
+
|
|
260
|
+
## 建议的系统提示
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
每次会话开始时调用 memory_index 一次。
|
|
264
|
+
需要细节时调用 memory_search,默认只取摘要。
|
|
265
|
+
禁止一次性加载全部记忆原文。
|
|
266
|
+
新学到的用户偏好、决策、人物关系,用 memory_add 写入,
|
|
267
|
+
写入前先蒸馏成事实,不要存原始对话。
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## 商业化设计
|
|
271
|
+
|
|
272
|
+
见 `docs/pricing.md`。要点:**BYOK 路径边际成本≈0,所以终身买断是净赚**;纯订阅在这个人群里转化率很差,因为 AI 重度用户已经订阅疲劳了。
|
|
273
|
+
|
|
274
|
+
## 已知边界
|
|
275
|
+
|
|
276
|
+
- 语义检索只在装了 `onnxruntime` 后启用,否则退化为 BM25 + 哈希向量。功能不残,语义质量下降。
|
|
277
|
+
- 自动关键词用的是位置 + 词频启发式,不是真 IDF。要真 IDF 就得每次写入全量重算,不值得。
|
|
278
|
+
- **标签里会出现 `库最`、`终选` 这种跨词碎片** —— 这是 bigram 索引无分词的固有痕迹。检索走完整 bigram 索引不受影响,标签只是给人扫一眼用的。要干净的中文标签就得引 jieba,为了这个不值当。
|
|
279
|
+
- 单机单文件。多机同步和团队共享是商业版的事,也是服务端校验应该待的地方。
|
|
280
|
+
- `estimate_tokens` 是启发式估算,误差约 15%。它用于展示节省量,**不用于计费**。
|
|
281
|
+
- 客户端授权可被绕过,这是设计上的取舍,不是 bug。见上文。
|