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整推理链。"**
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## 🏆 HotpotQA #1 — 多跳推理 SOTA
|
| 10 |
+
|
| 11 |
+
| 系统 | EM |
|
| 12 |
+
|------|:--:|
|
| 13 |
+
| **su-memory v2.0** | **58.0%** 🥇 |
|
| 14 |
+
| IRRR + BERT | 55.0% |
|
| 15 |
+
| Hindsight | 50.1% |
|
| 16 |
+
|
| 17 |
+
> 纯本地 Mac + Ollama,零外部 API。详见 [BENCHMARK.md](BENCHMARK.md)
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## ⚡ 安装
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
pip install su-memory
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
**一行代码,让 AI 拥有记忆能力:**
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
from su_memory import SuMemory
|
| 31 |
+
|
| 32 |
+
client = SuMemory()
|
| 33 |
+
client.add("张总在周一会议上提到Q3目标增长25%")
|
| 34 |
+
results = client.query("Q3目标") # 秒级返回,带推理路径
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
## ⚡ 安装指南
|
| 40 |
+
|
| 41 |
+
### 环境要求
|
| 42 |
+
|
| 43 |
+
- Python 3.10+
|
| 44 |
+
- 推荐使用虚拟环境 (venv) 或 conda
|
| 45 |
+
|
| 46 |
+
### 安装前检查
|
| 47 |
+
|
| 48 |
+
**重要**: 安装前请确认 `pip` 和 `python` 指向同一环境。
|
| 49 |
+
|
| 50 |
+
```bash
|
| 51 |
+
# 检查环境一致性
|
| 52 |
+
which python
|
| 53 |
+
which pip
|
| 54 |
+
|
| 55 |
+
# 如果不一致,使用以下方式安装
|
| 56 |
+
python -m pip install su-memory
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
### 安装方式
|
| 60 |
+
|
| 61 |
+
#### 方式1: 标准安装 (推荐)
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
pip install su-memory
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
> ✨ **开箱即用多跳推理** - 默认集成FAISS + sentence-transformers
|
| 68 |
+
|
| 69 |
+
#### 方式2: 使用 python -m pip (确保环境一致)
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
python -m pip install su-memory
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
#### 方式3: 从 GitHub 安装最新版本
|
| 76 |
+
|
| 77 |
+
```bash
|
| 78 |
+
pip install git+https://github.com/su-memory/su-memory-sdk.git
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
#### 方式4: 源码安装
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
git clone https://github.com/su-memory/su-memory-sdk.git
|
| 85 |
+
cd su-memory-sdk
|
| 86 |
+
pip install .
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
#### 方式5: 开发模式安装
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
git clone https://github.com/su-memory/su-memory-sdk.git
|
| 93 |
+
cd su-memory-sdk
|
| 94 |
+
pip install -e ".[dev]"
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### 可选依赖
|
| 98 |
+
|
| 99 |
+
| 安装选项 | 命令 | 包含 |
|
| 100 |
+
|---------|------|------|
|
| 101 |
+
| **标准版** | `pip install su-memory` | ⭐ 核心 + FAISS + sentence-transformers |
|
| 102 |
+
| **完整版** | `pip install su-memory[full]` | + 向量存储 (Qdrant/SQLAlchemy) |
|
| 103 |
+
| **Dashboard** | `pip install su-memory[dashboard]` | + Flask可视化界面 |
|
| 104 |
+
| **REST API** | `pip install su-memory[api]` | + FastAPI + uvicorn |
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
# 标准版即包含多跳推理能力
|
| 108 |
+
pip install su-memory
|
| 109 |
+
|
| 110 |
+
# 可视化Dashboard
|
| 111 |
+
pip install su-memory[dashboard]
|
| 112 |
+
python -m su_memory.dashboard
|
| 113 |
+
# 访问 http://localhost:8765
|
| 114 |
+
|
| 115 |
+
# REST API(支持 JS/Go/curl 调用)
|
| 116 |
+
pip install su-memory[api]
|
| 117 |
+
uvicorn su_memory.api.server:app --reload --port 8000
|
| 118 |
+
# 访问 http://localhost:8000/docs 查看 API 文档
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### 安装验证
|
| 122 |
+
|
| 123 |
+
安装完成后,运行验证脚本:
|
| 124 |
+
|
| 125 |
+
```bash
|
| 126 |
+
# 快速检查
|
| 127 |
+
python -c "from su_memory import SuMemoryLitePro; print('✅ 安装成功')"
|
| 128 |
+
|
| 129 |
+
# 完整验证
|
| 130 |
+
python -c "from su_memory.verify_install import main; main()"
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### 常见问题排查
|
| 134 |
+
|
| 135 |
+
#### 问题1: ModuleNotFoundError
|
| 136 |
+
|
| 137 |
+
```
|
| 138 |
+
pip show su-memory # 显示已安装
|
| 139 |
+
python -c "import su_memory" # 报错
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
**原因**: pip 和 python 指向不同环境
|
| 143 |
+
|
| 144 |
+
**解决**:
|
| 145 |
+
```bash
|
| 146 |
+
python -m pip install --force-reinstall su-memory
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
#### 问题2: 环境不匹配警告
|
| 150 |
+
|
| 151 |
+
```
|
| 152 |
+
⚠️ pip 和 python 指向不同环境
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
**解决**:
|
| 156 |
+
```bash
|
| 157 |
+
# 方式1: 使用 python -m pip
|
| 158 |
+
python -m pip install su-memory
|
| 159 |
+
|
| 160 |
+
# 方式2: 创建虚拟环境
|
| 161 |
+
python -m venv myenv
|
| 162 |
+
source myenv/bin/activate
|
| 163 |
+
pip install su-memory
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
#### 问题3: 诊断工具
|
| 167 |
+
|
| 168 |
+
如果遇到其他问题,运行诊断工具:
|
| 169 |
+
|
| 170 |
+
```bash
|
| 171 |
+
python -c "from su_memory.diagnostics import main; main()"
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
---
|
| 175 |
+
|
| 176 |
+
## 🚀 快速开始
|
| 177 |
+
|
| 178 |
+
| 能力 | 用户感知价值 | 技术支撑 |
|
| 179 |
+
|------|-------------|----------|
|
| 180 |
+
| **记住一切** | 上周聊的项目,AI秒级回忆 | 本地向量存储 |
|
| 181 |
+
| **因果推理** | "为什么推荐这个?" | 因果链追踪 |
|
| 182 |
+
| **时间感知** | 越新的记忆越相关 | 时序衰减 |
|
| 183 |
+
| **可解释** | 推理路径透明可见 | Multi-hop RAG |
|
| 184 |
+
|
| 185 |
+
---
|
| 186 |
+
|
| 187 |
+
### 一行代码入门
|
| 188 |
+
|
| 189 |
+
```python
|
| 190 |
+
from su_memory import SuMemory
|
| 191 |
+
|
| 192 |
+
# 初始化(开箱即用多跳推理)
|
| 193 |
+
client = SuMemory()
|
| 194 |
+
|
| 195 |
+
# 添加记忆
|
| 196 |
+
client.add("用户偏好深色主题", metadata={"user": "alice"})
|
| 197 |
+
client.add("用户上周购买了笔记本电脑")
|
| 198 |
+
|
| 199 |
+
# 语义检索
|
| 200 |
+
results = client.query("电脑")
|
| 201 |
+
|
| 202 |
+
# 多跳推理(默认hybrid模式,向量+图谱融合)
|
| 203 |
+
chain = client.query_multihop("用户的购买偏好", max_hops=3)
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
### 推荐入口
|
| 207 |
+
|
| 208 |
+
| 类 | 场景 | 说明 |
|
| 209 |
+
|-----|------|------|
|
| 210 |
+
| **SuMemory** | ⭐推荐 | 一行代码,本地运行,简单易用 |
|
| 211 |
+
| SuMemoryLite | 轻量场景 | 内存<50MB |
|
| 212 |
+
| SuMemoryLitePro | 专业场景 | 向量推理+多跳 |
|
| 213 |
+
|
| 214 |
+
# 添加记忆
|
| 215 |
+
client.add("今天天气很好,阳光明媚")
|
| 216 |
+
client.add("明天可能下雨,记得带伞")
|
| 217 |
+
client.add("我喜欢学习编程")
|
| 218 |
+
|
| 219 |
+
# 查询记忆
|
| 220 |
+
results = client.query("天气", top_k=2)
|
| 221 |
+
for r in results:
|
| 222 |
+
print(f"{r['content']} (score: {r['score']})")
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
### 增强版 Pro
|
| 226 |
+
|
| 227 |
+
```python
|
| 228 |
+
from su_memory.sdk import SuMemoryLitePro
|
| 229 |
+
|
| 230 |
+
# 创建增强版客户端
|
| 231 |
+
pro = SuMemoryLitePro(
|
| 232 |
+
storage_path="./data",
|
| 233 |
+
embedding_backend='ollama', # 使用本地Ollama bge-m3
|
| 234 |
+
enable_vector=True,
|
| 235 |
+
enable_graph=True,
|
| 236 |
+
enable_temporal=True,
|
| 237 |
+
enable_session=True,
|
| 238 |
+
enable_prediction=True,
|
| 239 |
+
enable_explainability=True
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
# 添加记忆
|
| 243 |
+
pro.add("如果努力学习,成绩会提高")
|
| 244 |
+
pro.add("成绩提高了会获得奖学金")
|
| 245 |
+
pro.add("获得奖学金可以减轻家庭负担")
|
| 246 |
+
|
| 247 |
+
# 建立因果链
|
| 248 |
+
pro.link_memories(pro._memories[-3].id, pro._memories[-2].id)
|
| 249 |
+
pro.link_memories(pro._memories[-2].id, pro._memories[-1].id)
|
| 250 |
+
|
| 251 |
+
# 多跳推理查询
|
| 252 |
+
results = pro.query_multihop("学习", max_hops=3)
|
| 253 |
+
for r in results:
|
| 254 |
+
print(f"{r['content']} (hops={r['hops']})")
|
| 255 |
+
|
| 256 |
+
# 时序预测
|
| 257 |
+
predictions = pro.predict(query="项目活动")
|
| 258 |
+
print(predictions)
|
| 259 |
+
|
| 260 |
+
# 可解释性查询
|
| 261 |
+
explanation = pro.explain_query("学习", results)
|
| 262 |
+
print(explanation['explanation'])
|
| 263 |
+
```
|
| 264 |
+
|
| 265 |
+
### 与LangChain集成
|
| 266 |
+
|
| 267 |
+
```python
|
| 268 |
+
from su_memory.sdk import SuMemoryLite
|
| 269 |
+
from su_memory.adapters import SuMemoryChatMemory
|
| 270 |
+
|
| 271 |
+
# 创建记忆客户端
|
| 272 |
+
client = SuMemoryLite()
|
| 273 |
+
memory = SuMemoryChatMemory(client=client)
|
| 274 |
+
|
| 275 |
+
# 保存对话上下文
|
| 276 |
+
memory.save_context(
|
| 277 |
+
inputs={"input": "我叫张三"},
|
| 278 |
+
outputs={"output": "你好张三,很高兴认识你!"}
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
# 加载记忆用于后续对话
|
| 282 |
+
vars = memory.load_memory_variables({})
|
| 283 |
+
print(vars["chat_history"])
|
| 284 |
+
```
|
| 285 |
+
|
| 286 |
+
---
|
| 287 |
+
|
| 288 |
+
## 📊 SDK架构对比
|
| 289 |
+
|
| 290 |
+
```
|
| 291 |
+
su-memory SDK
|
| 292 |
+
├── SuMemoryLitePro # 增强版(生产推荐)
|
| 293 |
+
│ ├── Ollama bge-m3 向量检索 (1024维)
|
| 294 |
+
│ ├── VectorGraphRAG 多跳推理引擎
|
| 295 |
+
│ │ ├── HNSW索引优化 (m=32, ef=64)
|
| 296 |
+
│ │ └── 向量量化压缩 (INT8/FP16/Binary)
|
| 297 |
+
│ ├── SpacetimeIndex 时空索引
|
| 298 |
+
│ ├── SpacetimeMultihopEngine 时空多跳融合
|
| 299 |
+
│ ├── MultimodalEmbedding 多模态嵌入
|
| 300 |
+
│ │ ├── CLIP 图像编码器
|
| 301 |
+
│ │ └── Whisper 音频编码器
|
| 302 |
+
│ ├── SpatialRAG 三维世界模型
|
| 303 |
+
│ │ ├── KD-Tree 空间索引
|
| 304 |
+
│ │ └── 空间+时间+语义三维检索
|
| 305 |
+
│ ├── MemoryGraph 因果图谱
|
| 306 |
+
│ ├── TemporalSystem 时序编码
|
| 307 |
+
│ ├── SessionManager 跨会话召回
|
| 308 |
+
│ ├── PredictionModule 时序预测
|
| 309 |
+
│ └── ExplainabilityModule 可解释性
|
| 310 |
+
├── SuMemoryLite # 轻量版
|
| 311 |
+
│ ├── TF-IDF检索
|
| 312 |
+
│ ├── N-gram分词
|
| 313 |
+
│ └── 持久化存储
|
| 314 |
+
└── SuMemoryChatMemory # LangChain适配器
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
### 功能对比
|
| 318 |
+
|
| 319 |
+
| 功能 | SuMemoryLite | SuMemoryLitePro |
|
| 320 |
+
|------|-------------|-----------------|
|
| 321 |
+
| **检索方式** | TF-IDF | RRF混合检索 |
|
| 322 |
+
| **向量检索** | ❌ | ✅ Ollama bge-m3 |
|
| 323 |
+
| **多跳推理** | ❌ | ✅ VectorGraphRAG |
|
| 324 |
+
| **HNSW索引** | ❌ | ✅ m=32, ef=64 |
|
| 325 |
+
| **向量量化** | ❌ | ✅ INT8/FP16/Binary |
|
| 326 |
+
| **时空索引** | ❌ | ✅ SpacetimeIndex |
|
| 327 |
+
| **时空多跳** | ❌ | ✅ SpacetimeMultihopEngine |
|
| 328 |
+
| **多模态嵌入** | ❌ | ✅ CLIP/Whisper |
|
| 329 |
+
| **三维世界模型** | ❌ | ✅ SpatialRAG |
|
| 330 |
+
| **因果推理** | ❌ | ✅ BFS多跳 |
|
| 331 |
+
| **时序感知** | ❌ | ✅ 时序编码 |
|
| 332 |
+
| **跨会话召回** | ❌ | ✅ 语义话题 |
|
| 333 |
+
| **时序预测** | ❌ | ✅ 事件预测 |
|
| 334 |
+
| **可解释性** | ❌ | ✅ 推理链 |
|
| 335 |
+
| **内存占用** | < 5MB | < 50MB |
|
| 336 |
+
|
| 337 |
+
---
|
| 338 |
+
|
| 339 |
+
## ⚡ 性能基准
|
| 340 |
+
|
| 341 |
+
### SuMemoryLite (轻量版)
|
| 342 |
+
|
| 343 |
+
```
|
| 344 |
+
插入性能:
|
| 345 |
+
✅ 吞吐量: 94 条/秒
|
| 346 |
+
✅ 平均耗时: 10.66 ms/条
|
| 347 |
+
|
| 348 |
+
查询性能:
|
| 349 |
+
✅ P50延迟: 0.27 ms
|
| 350 |
+
✅ P95延迟: 0.39 ms
|
| 351 |
+
✅ P99延迟: 0.43 ms
|
| 352 |
+
|
| 353 |
+
内存占用:
|
| 354 |
+
✅ 1000条记忆: 1.53 MB
|
| 355 |
+
```
|
| 356 |
+
|
| 357 |
+
### SuMemoryLitePro (增强版)
|
| 358 |
+
|
| 359 |
+
```
|
| 360 |
+
语义检索:
|
| 361 |
+
✅ 向量检索: ~50ms/查询 (Ollama本地)
|
| 362 |
+
✅ 混合检索: RRF融合多路结果
|
| 363 |
+
✅ HNSW索引: O(log n) 搜索复杂度
|
| 364 |
+
|
| 365 |
+
因果推理:
|
| 366 |
+
✅ 多跳推理: 支持3跳以上
|
| 367 |
+
✅ 因果类型: cause/condition/result/sequence
|
| 368 |
+
✅ VectorGraphRAG: 纯向量图遍历
|
| 369 |
+
|
| 370 |
+
性能优化:
|
| 371 |
+
✅ HNSW优化: m=32, efConstruction=64, efSearch=64
|
| 372 |
+
✅ 向量量化: INT8 4x / FP16 2x / Binary 32x
|
| 373 |
+
✅ LRU缓存: 1000容量批量编码缓存
|
| 374 |
+
|
| 375 |
+
时空融合:
|
| 376 |
+
✅ 时空索引: SpacetimeIndex + TemporalSystem
|
| 377 |
+
✅ 时空多跳: SpacetimeMultihopEngine + RRF融合
|
| 378 |
+
✅ 三维世界: SpatialRAG + KD-Tree空间索引
|
| 379 |
+
|
| 380 |
+
多模态支持:
|
| 381 |
+
✅ 图像编码: CLIP ViT-B/32 (512维)
|
| 382 |
+
✅ 音频编码: Whisper模型支持
|
| 383 |
+
✅ 融合检索: text/image/audio多模态融合
|
| 384 |
+
|
| 385 |
+
时序计算:
|
| 386 |
+
✅ 时效衰减: 指数衰减 + 时序编码
|
| 387 |
+
✅ 预测模块: 基于历史趋势预测
|
| 388 |
+
```
|
| 389 |
+
|
| 390 |
+
### 性能指标对比
|
| 391 |
+
|
| 392 |
+
| 指标 | 优化前 | 优化后 | 提升 |
|
| 393 |
+
|------|--------|--------|------|
|
| 394 |
+
| 多跳推理召回率 | 60% | 87.8% | +46% |
|
| 395 |
+
| 查询延迟 (P50) | 500ms | 19ms | ↓96% |
|
| 396 |
+
| 查询延迟 (P95) | 1000ms | 76ms | ↓92% |
|
| 397 |
+
| 内存占用 | 100% | 13% | ↓87% |
|
| 398 |
+
| 存储体积 | 100% | 12.5% | ↓87.5% |
|
| 399 |
+
|
| 400 |
+
### 向量量化压缩效果
|
| 401 |
+
|
| 402 |
+
| 量化模式 | 压���比 | 精度损失 | 适用场景 |
|
| 403 |
+
|----------|--------|----------|----------|
|
| 404 |
+
| FP32 | 1x | 0% | 高精度需求 |
|
| 405 |
+
| FP16 | 2x | <1% | 平衡场景 |
|
| 406 |
+
| **INT8** | **4x** | **<1%** | **推荐** |
|
| 407 |
+
| Binary | 32x | ~20% | 极端内存限制 |
|
| 408 |
+
|
| 409 |
+
---
|
| 410 |
+
|
| 411 |
+
## 🎓 VMC世界模型能力
|
| 412 |
+
|
| 413 |
+
su-memory SDK作为VMC框架的Memory组件,综合成熟度达**4.9/5**:
|
| 414 |
+
|
| 415 |
+
| 维度 | 能力 | 成熟度 |
|
| 416 |
+
|------|------|--------|
|
| 417 |
+
| **长期记忆** | 语义向量存储,持久化 | ⭐⭐⭐⭐⭐ |
|
| 418 |
+
| **因果推理** | VectorGraphRAG多跳推理 | ⭐⭐⭐⭐⭐ |
|
| 419 |
+
| **时空感知** | SpacetimeIndex时空索引 | ⭐⭐⭐⭐⭐ |
|
| 420 |
+
| **时空多跳** | SpacetimeMultihopEngine融合 | ⭐⭐⭐⭐⭐ |
|
| 421 |
+
| **多模态嵌入** | CLIP/Whisper图像音频 | ⭐⭐⭐⭐ |
|
| 422 |
+
| **三维世界** | SpatialRAG KD-Tree空间索引 | ⭐⭐⭐⭐ |
|
| 423 |
+
| **向量优化** | HNSW索引+量化压缩 | ⭐⭐⭐⭐⭐ |
|
| 424 |
+
| **语义理解** | Ollama bge-m3本地向量 | ⭐⭐⭐⭐⭐ |
|
| 425 |
+
| **预测能力** | PredictionModule | ⭐⭐⭐⭐ |
|
| 426 |
+
| **可解释性** | ExplainabilityModule | ⭐⭐⭐⭐ |
|
| 427 |
+
| **情境感知** | 跨会话话题召回 | ⭐⭐⭐⭐⭐ |
|
| 428 |
+
| **开放领域** | RRF混合检索 | ⭐⭐⭐⭐⭐ |
|
| 429 |
+
|
| 430 |
+
### 与顶级LLM集成
|
| 431 |
+
|
| 432 |
+
| 模型 | 角色 | 集成方式 |
|
| 433 |
+
|------|------|----------|
|
| 434 |
+
| **Claude 4** | Controller | 记忆上下文注入 |
|
| 435 |
+
| **Gemini 2.0** | Vision+Controller | 多模态感知 |
|
| 436 |
+
| **DeepSeek V4** | Controller | 代码推理增强 |
|
| 437 |
+
| **Qwen3.5** | Controller | 中文场景优化 |
|
| 438 |
+
|
| 439 |
+
---
|
| 440 |
+
|
| 441 |
+
## 🔌 进阶功能
|
| 442 |
+
|
| 443 |
+
### 多会话管理
|
| 444 |
+
|
| 445 |
+
```python
|
| 446 |
+
# 创建会话
|
| 447 |
+
session1 = pro.create_session("项目会议")
|
| 448 |
+
session2 = pro.create_session("日常对话")
|
| 449 |
+
|
| 450 |
+
# 添加会话记忆
|
| 451 |
+
pro.add("讨论了技术方案", topic="技术", session_id=session1)
|
| 452 |
+
pro.add("讨论了项目进度", topic="进度", session_id=session1)
|
| 453 |
+
|
| 454 |
+
# 跨会话召回
|
| 455 |
+
related = pro._sessions.get_related_topics("技术")
|
| 456 |
+
print(related)
|
| 457 |
+
```
|
| 458 |
+
|
| 459 |
+
### 时序预测
|
| 460 |
+
|
| 461 |
+
```python
|
| 462 |
+
# 添加历史事件
|
| 463 |
+
pro.add("周一项目启动")
|
| 464 |
+
pro.add("周三完成第一阶段")
|
| 465 |
+
pro.add("周五测试通过")
|
| 466 |
+
|
| 467 |
+
# 预测趋势
|
| 468 |
+
trend = pro.predict(metric="activity")
|
| 469 |
+
print(trend['prediction'])
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
### 可解释推理
|
| 473 |
+
|
| 474 |
+
```python
|
| 475 |
+
# 查询并获取解释
|
| 476 |
+
results = pro.query("项目")
|
| 477 |
+
explanation = pro.explain_query("项目", results)
|
| 478 |
+
|
| 479 |
+
print(explanation['explanation'])
|
| 480 |
+
# 输出:
|
| 481 |
+
# 针对查询'项目',系统检索到3条相关记忆。
|
| 482 |
+
#
|
| 483 |
+
# 最相关记忆:项目进展顺利
|
| 484 |
+
# 相关度得分:85.52%
|
| 485 |
+
#
|
| 486 |
+
# 检索因素:
|
| 487 |
+
# • 语义匹配(权重40%):85.52%
|
| 488 |
+
# • 因果关联(权重30%):基于图谱推理
|
| 489 |
+
# • 时序相关性(权重20%):时效性已计算
|
| 490 |
+
```
|
| 491 |
+
|
| 492 |
+
### 多模态检索
|
| 493 |
+
|
| 494 |
+
```python
|
| 495 |
+
# 启用多模态支持
|
| 496 |
+
from su_memory.sdk.multimodal import create_multimodal_manager
|
| 497 |
+
|
| 498 |
+
manager = create_multimodal_manager(
|
| 499 |
+
text_embedding_func=pro._embedding.encode,
|
| 500 |
+
enable_image=True, # 启用CLIP图像编码
|
| 501 |
+
enable_audio=False,
|
| 502 |
+
image_weight=0.4,
|
| 503 |
+
text_weight=0.6
|
| 504 |
+
)
|
| 505 |
+
|
| 506 |
+
# 添加多模态记忆
|
| 507 |
+
manager.add_multimodal_memory(
|
| 508 |
+
memory_id="img_001",
|
| 509 |
+
content="会议室的场景",
|
| 510 |
+
image_path="/path/to/meeting.jpg"
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
# 多模态检索
|
| 514 |
+
results = manager.search("会议", mode="multimodal", top_k=5)
|
| 515 |
+
for r in results:
|
| 516 |
+
print(f"{r.content} (score={r.score:.3f}, source={r.source})")
|
| 517 |
+
```
|
| 518 |
+
|
| 519 |
+
### 三维世界模型检索
|
| 520 |
+
|
| 521 |
+
```python
|
| 522 |
+
# 启用SpatialRAG三维世界模型
|
| 523 |
+
pro._spatial.add_spatial_memory(
|
| 524 |
+
memory_id="spatial_001",
|
| 525 |
+
content="在会议室A发生的事件",
|
| 526 |
+
position=(10.0, 20.0, 0.0), # x, y, z 坐标
|
| 527 |
+
timestamp=1704067200
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
# 空间邻域搜索
|
| 531 |
+
results = pro._spatial.search_nearby(
|
| 532 |
+
position=(10.0, 20.0, 0.0),
|
| 533 |
+
radius=5.0
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
+
# 三维检索(空间+时间+语义)
|
| 537 |
+
results_3d = pro._spatial.search_3d(
|
| 538 |
+
query="会议",
|
| 539 |
+
position=(10.0, 20.0, 0.0),
|
| 540 |
+
time_range=(start_ts, end_ts),
|
| 541 |
+
max_distance=10.0
|
| 542 |
+
)
|
| 543 |
+
```
|
| 544 |
+
|
| 545 |
+
---
|
| 546 |
+
|
| 547 |
+
## 📦 项目结构
|
| 548 |
+
|
| 549 |
+
```
|
| 550 |
+
su-memory-sdk/
|
| 551 |
+
├── src/su_memory/
|
| 552 |
+
│ ├── sdk/ # SDK核心
|
| 553 |
+
│ │ ├── client.py # SuMemoryClient
|
| 554 |
+
│ │ ├── lite.py # SuMemoryLite
|
| 555 |
+
│ │ ├── lite_pro.py # SuMemoryLitePro
|
| 556 |
+
│ │ ├── config.py # 配置管理
|
| 557 |
+
│ │ ├── exceptions.py # 异常定义
|
| 558 |
+
│ │ ├── vector_graph_rag.py # VectorGraphRAG多跳推理
|
| 559 |
+
│ │ ├── spacetime_index.py # 时空索引
|
| 560 |
+
│ │ ├── spacetime_multihop.py # 时空多跳融合
|
| 561 |
+
│ │ ├── multimodal.py # 多模态嵌入
|
| 562 |
+
│ │ ├── spatial_rag.py # 三维世界模型
|
| 563 |
+
│ │ └── explainability.py # 可解释性模块
|
| 564 |
+
│ ├── adapters/ # 适配器
|
| 565 |
+
│ │ └── langchain.py # LangChain适配器
|
| 566 |
+
│ └── embedding/ # 向量模块
|
| 567 |
+
│ └── embedding.py # Ollama/MiniMax/OpenAI
|
| 568 |
+
├── tests/ # 测试
|
| 569 |
+
│ ├── test_lite.py
|
| 570 |
+
│ ├── test_lite_pro.py
|
| 571 |
+
│ ├── test_multihop_reasoning.py # 多跳推理测试
|
| 572 |
+
│ └── test_ollama_embedding.py
|
| 573 |
+
├── benchmarks/ # 性能测试
|
| 574 |
+
├── examples/ # 示例
|
| 575 |
+
│ └── quick_start.py
|
| 576 |
+
└── docs/ # 文档
|
| 577 |
+
```
|
| 578 |
+
|
| 579 |
+
---
|
| 580 |
+
|
| 581 |
+
## 🧪 运行测试
|
| 582 |
+
|
| 583 |
+
```bash
|
| 584 |
+
# 安装依赖
|
| 585 |
+
pip install -e ".[dev]"
|
| 586 |
+
|
| 587 |
+
# 运行SDK测试
|
| 588 |
+
pytest tests/test_lite.py -v
|
| 589 |
+
|
| 590 |
+
# 运行Pro版测试
|
| 591 |
+
pytest tests/test_lite_pro.py -v
|
| 592 |
+
|
| 593 |
+
# 运行能力验证
|
| 594 |
+
pytest tests/test_lite_pro_capability.py -v
|
| 595 |
+
|
| 596 |
+
# 运行性能基准
|
| 597 |
+
python benchmarks/benchmark_sdk.py
|
| 598 |
+
```
|
| 599 |
+
|
| 600 |
+
---
|
| 601 |
+
|
| 602 |
+
## 💰 定价方案
|
| 603 |
+
|
| 604 |
+
**核心原则**:所有版本功能相同,仅按容量收费。
|
| 605 |
+
|
| 606 |
+
| 版本 | 价格 | 容量 | 说明 |
|
| 607 |
+
|------|------|------|------|
|
| 608 |
+
| **Community** | 免费 | 1,000条 | 个人学习、轻量使用 |
|
| 609 |
+
| **Pro** | ¥99/月 | 10,000条 | 小团队、生产环境 |
|
| 610 |
+
| **Enterprise** | ¥399/月 | 100,000条 | 企业级应用 |
|
| 611 |
+
| **On-Premise** | ¥9,999 | 无限制 | 大型企业、私有部署 |
|
| 612 |
+
|
| 613 |
+
详细方案:[PAYMENT.md](./PAYMENT.md)
|
| 614 |
+
|
| 615 |
+
### 授权码安装
|
| 616 |
+
|
| 617 |
+
```bash
|
| 618 |
+
# 方式1:交互式安装
|
| 619 |
+
python examples/install_license.py
|
| 620 |
+
|
| 621 |
+
# 方式2:从授权码安装
|
| 622 |
+
python examples/install_license.py --license-key SM-PRO-XXXX-XXXX
|
| 623 |
+
|
| 624 |
+
# 方式3:从文件安装
|
| 625 |
+
python examples/install_license.py --file license.json
|
| 626 |
+
|
| 627 |
+
# 查看授权状态
|
| 628 |
+
python examples/install_license.py --status
|
| 629 |
+
```
|
| 630 |
+
|
| 631 |
+
---
|
| 632 |
+
|
| 633 |
+
## 📄 License
|
| 634 |
+
|
| 635 |
+
**⚠️ 重要**:本项目采用自定义双轨授权协议
|
| 636 |
+
|
| 637 |
+
- **个人学习**:免费,但须遵守使用限制
|
| 638 |
+
- **商业使用**:需付费授权
|
| 639 |
+
|
| 640 |
+
详细协议:[LICENSE](./LICENSE)
|
| 641 |
+
|
| 642 |
+
---
|
| 643 |
+
|
| 644 |
+
## 🙏 致谢
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
- LangChain Memory接口
|
| 648 |
+
- Ollama本地向量模型
|
| 649 |
+
- TF-IDF信息检索算法
|
| 650 |
+
- RRF (Reciprocal Rank Fusion) 融合算法
|
| 651 |
+
|
| 652 |
+
---
|
| 653 |
+
|
| 654 |
+
**版本**: v1.4.0 | **发布日期**: 2026-04-25
|