spatial-memory-mcp 1.9.1__py3-none-any.whl
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.
- spatial_memory/__init__.py +97 -0
- spatial_memory/__main__.py +271 -0
- spatial_memory/adapters/__init__.py +7 -0
- spatial_memory/adapters/lancedb_repository.py +880 -0
- spatial_memory/config.py +769 -0
- spatial_memory/core/__init__.py +118 -0
- spatial_memory/core/cache.py +317 -0
- spatial_memory/core/circuit_breaker.py +297 -0
- spatial_memory/core/connection_pool.py +220 -0
- spatial_memory/core/consolidation_strategies.py +401 -0
- spatial_memory/core/database.py +3072 -0
- spatial_memory/core/db_idempotency.py +242 -0
- spatial_memory/core/db_indexes.py +576 -0
- spatial_memory/core/db_migrations.py +588 -0
- spatial_memory/core/db_search.py +512 -0
- spatial_memory/core/db_versioning.py +178 -0
- spatial_memory/core/embeddings.py +558 -0
- spatial_memory/core/errors.py +317 -0
- spatial_memory/core/file_security.py +701 -0
- spatial_memory/core/filesystem.py +178 -0
- spatial_memory/core/health.py +289 -0
- spatial_memory/core/helpers.py +79 -0
- spatial_memory/core/import_security.py +433 -0
- spatial_memory/core/lifecycle_ops.py +1067 -0
- spatial_memory/core/logging.py +194 -0
- spatial_memory/core/metrics.py +192 -0
- spatial_memory/core/models.py +660 -0
- spatial_memory/core/rate_limiter.py +326 -0
- spatial_memory/core/response_types.py +500 -0
- spatial_memory/core/security.py +588 -0
- spatial_memory/core/spatial_ops.py +430 -0
- spatial_memory/core/tracing.py +300 -0
- spatial_memory/core/utils.py +110 -0
- spatial_memory/core/validation.py +406 -0
- spatial_memory/factory.py +444 -0
- spatial_memory/migrations/__init__.py +40 -0
- spatial_memory/ports/__init__.py +11 -0
- spatial_memory/ports/repositories.py +630 -0
- spatial_memory/py.typed +0 -0
- spatial_memory/server.py +1214 -0
- spatial_memory/services/__init__.py +70 -0
- spatial_memory/services/decay_manager.py +411 -0
- spatial_memory/services/export_import.py +1031 -0
- spatial_memory/services/lifecycle.py +1139 -0
- spatial_memory/services/memory.py +412 -0
- spatial_memory/services/spatial.py +1152 -0
- spatial_memory/services/utility.py +429 -0
- spatial_memory/tools/__init__.py +5 -0
- spatial_memory/tools/definitions.py +695 -0
- spatial_memory/verify.py +140 -0
- spatial_memory_mcp-1.9.1.dist-info/METADATA +509 -0
- spatial_memory_mcp-1.9.1.dist-info/RECORD +55 -0
- spatial_memory_mcp-1.9.1.dist-info/WHEEL +4 -0
- spatial_memory_mcp-1.9.1.dist-info/entry_points.txt +2 -0
- spatial_memory_mcp-1.9.1.dist-info/licenses/LICENSE +21 -0
spatial_memory/verify.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Verify spatial-memory installation and dependencies.
|
|
2
|
+
|
|
3
|
+
Run: python -m spatial_memory.verify
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import contextlib
|
|
7
|
+
import io
|
|
8
|
+
import logging
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import warnings
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _suppress_noise() -> None:
|
|
15
|
+
"""Suppress noisy warnings and logs from dependencies."""
|
|
16
|
+
warnings.filterwarnings("ignore")
|
|
17
|
+
# Suppress verbose loggers
|
|
18
|
+
for logger_name in [
|
|
19
|
+
"sentence_transformers",
|
|
20
|
+
"optimum",
|
|
21
|
+
"huggingface_hub",
|
|
22
|
+
"transformers",
|
|
23
|
+
]:
|
|
24
|
+
logging.getLogger(logger_name).setLevel(logging.ERROR)
|
|
25
|
+
# Suppress HF symlink warnings on Windows
|
|
26
|
+
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def main() -> int:
|
|
30
|
+
"""Verify installation and print status."""
|
|
31
|
+
_suppress_noise()
|
|
32
|
+
|
|
33
|
+
print("Spatial Memory MCP - Installation Verification")
|
|
34
|
+
print("=" * 50)
|
|
35
|
+
|
|
36
|
+
errors = []
|
|
37
|
+
onnx_available = False
|
|
38
|
+
|
|
39
|
+
# Check core dependencies
|
|
40
|
+
print("\nChecking core dependencies...")
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
import lancedb # noqa: F401
|
|
44
|
+
print(" [OK] lancedb")
|
|
45
|
+
except ImportError as e:
|
|
46
|
+
print(f" [FAIL] lancedb: {e}")
|
|
47
|
+
errors.append("lancedb")
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
import sentence_transformers # noqa: F401
|
|
51
|
+
print(" [OK] sentence-transformers")
|
|
52
|
+
except ImportError as e:
|
|
53
|
+
print(f" [FAIL] sentence-transformers: {e}")
|
|
54
|
+
errors.append("sentence-transformers")
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
import mcp # noqa: F401
|
|
58
|
+
print(" [OK] mcp")
|
|
59
|
+
except ImportError as e:
|
|
60
|
+
print(f" [FAIL] mcp: {e}")
|
|
61
|
+
errors.append("mcp")
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
import hdbscan # noqa: F401
|
|
65
|
+
print(" [OK] hdbscan")
|
|
66
|
+
except ImportError as e:
|
|
67
|
+
print(f" [FAIL] hdbscan: {e}")
|
|
68
|
+
errors.append("hdbscan")
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
import umap # noqa: F401
|
|
72
|
+
print(" [OK] umap-learn")
|
|
73
|
+
except ImportError as e:
|
|
74
|
+
print(f" [FAIL] umap-learn: {e}")
|
|
75
|
+
errors.append("umap-learn")
|
|
76
|
+
|
|
77
|
+
# Check ONNX Runtime (optional but recommended)
|
|
78
|
+
print("\nChecking ONNX Runtime (for faster embeddings)...")
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
import onnxruntime # noqa: F401
|
|
82
|
+
print(" [OK] onnxruntime")
|
|
83
|
+
except ImportError:
|
|
84
|
+
print(" [WARN] onnxruntime not installed")
|
|
85
|
+
|
|
86
|
+
# Suppress "Multiple distributions" message from optimum
|
|
87
|
+
with contextlib.redirect_stdout(io.StringIO()):
|
|
88
|
+
try:
|
|
89
|
+
import optimum.onnxruntime # noqa: F401
|
|
90
|
+
optimum_ok = True
|
|
91
|
+
except ImportError:
|
|
92
|
+
optimum_ok = False
|
|
93
|
+
|
|
94
|
+
if optimum_ok:
|
|
95
|
+
print(" [OK] optimum")
|
|
96
|
+
else:
|
|
97
|
+
print(" [WARN] optimum not installed")
|
|
98
|
+
|
|
99
|
+
# Check embedding service
|
|
100
|
+
print("\nChecking embedding service...")
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
from spatial_memory.core.embeddings import EmbeddingService, _is_onnx_available
|
|
104
|
+
|
|
105
|
+
onnx_available = _is_onnx_available()
|
|
106
|
+
print(f" ONNX Runtime available: {onnx_available}")
|
|
107
|
+
|
|
108
|
+
# Suppress model loading messages
|
|
109
|
+
with contextlib.redirect_stdout(io.StringIO()), \
|
|
110
|
+
contextlib.redirect_stderr(io.StringIO()):
|
|
111
|
+
svc = EmbeddingService()
|
|
112
|
+
backend = svc.backend
|
|
113
|
+
dimensions = svc.dimensions
|
|
114
|
+
vec = svc.embed("test")
|
|
115
|
+
|
|
116
|
+
print(f" Active backend: {backend}")
|
|
117
|
+
print(f" Embedding dimensions: {dimensions}")
|
|
118
|
+
print(f" Embedding test: OK (shape: {vec.shape})")
|
|
119
|
+
|
|
120
|
+
except Exception as e:
|
|
121
|
+
print(f" [FAIL] Embedding service error: {e}")
|
|
122
|
+
errors.append("embedding-service")
|
|
123
|
+
|
|
124
|
+
# Summary
|
|
125
|
+
print("\n" + "=" * 50)
|
|
126
|
+
if errors:
|
|
127
|
+
print(f"FAILED: {len(errors)} issue(s) found")
|
|
128
|
+
print(f"Missing: {', '.join(errors)}")
|
|
129
|
+
print("\nTry: pip install -e \".[dev]\"")
|
|
130
|
+
return 1
|
|
131
|
+
else:
|
|
132
|
+
print("SUCCESS: All dependencies verified!")
|
|
133
|
+
if not onnx_available:
|
|
134
|
+
print("\nTip: Install ONNX for 2-3x faster embeddings:")
|
|
135
|
+
print(" pip install sentence-transformers[onnx]")
|
|
136
|
+
return 0
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
sys.exit(main())
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spatial-memory-mcp
|
|
3
|
+
Version: 1.9.1
|
|
4
|
+
Summary: Spatial bidirectional persistent memory MCP server for LLMs - vector-based semantic memory as a navigable landscape
|
|
5
|
+
Project-URL: Homepage, https://github.com/arman-tech/spatial-memory-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/arman-tech/spatial-memory-mcp
|
|
7
|
+
Project-URL: Documentation, https://github.com/arman-tech/spatial-memory-mcp#readme
|
|
8
|
+
Project-URL: Changelog, https://github.com/arman-tech/spatial-memory-mcp/blob/master/CHANGELOG.md
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/arman-tech/spatial-memory-mcp/issues
|
|
10
|
+
Author: arman-tech
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: embeddings,llm,mcp,memory,semantic-search,spatial,vector
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: filelock>=3.12.0
|
|
24
|
+
Requires-Dist: hdbscan>=0.8.33
|
|
25
|
+
Requires-Dist: lancedb>=0.27.0
|
|
26
|
+
Requires-Dist: mcp>=1.0.0
|
|
27
|
+
Requires-Dist: numpy>=1.24.0
|
|
28
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Requires-Dist: sentence-transformers[onnx]>=2.2.0
|
|
31
|
+
Requires-Dist: umap-learn>=0.5.5
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: prometheus-client>=0.20.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
39
|
+
Provides-Extra: metrics
|
|
40
|
+
Requires-Dist: prometheus-client>=0.20.0; extra == 'metrics'
|
|
41
|
+
Provides-Extra: openai
|
|
42
|
+
Requires-Dist: openai>=1.0.0; extra == 'openai'
|
|
43
|
+
Requires-Dist: tiktoken>=0.5.0; extra == 'openai'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# Spatial Memory MCP Server
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/spatial-memory-mcp/)
|
|
49
|
+
[](https://www.python.org/downloads/)
|
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
|
51
|
+
|
|
52
|
+
A vector-based spatial memory system that treats knowledge as a navigable landscape, not a filing cabinet.
|
|
53
|
+
|
|
54
|
+
> **Version 1.8.0** — Production-ready with 1,400+ tests passing.
|
|
55
|
+
|
|
56
|
+
## Supported Platforms
|
|
57
|
+
|
|
58
|
+
- **Windows 11**
|
|
59
|
+
- **macOS** (latest)
|
|
60
|
+
- **Linux** (Fedora, Ubuntu, Linux Mint)
|
|
61
|
+
|
|
62
|
+
## Overview
|
|
63
|
+
|
|
64
|
+
Spatial Memory MCP Server provides persistent, semantic memory for LLMs through the Model Context Protocol (MCP). Unlike traditional keyword-based memory systems, it uses vector embeddings to enable:
|
|
65
|
+
|
|
66
|
+
- **Semantic Search**: Find memories by meaning, not just keywords
|
|
67
|
+
- **Spatial Navigation**: Discover connections through `journey` and `wander` operations
|
|
68
|
+
- **Auto-Clustering**: `regions` automatically groups related concepts
|
|
69
|
+
- **Cognitive Dynamics**: Memories consolidate, decay, and reinforce like human cognition
|
|
70
|
+
- **Auto-Decay**: Memories automatically fade over time, keeping recent knowledge prominent
|
|
71
|
+
- **Visual Understanding**: Generate Mermaid/SVG/JSON visualizations of your knowledge space
|
|
72
|
+
- **Hybrid Search**: Combine vector similarity with full-text search
|
|
73
|
+
|
|
74
|
+
## Why Spatial Memory?
|
|
75
|
+
|
|
76
|
+
### Zero Cognitive Load
|
|
77
|
+
**You never think about memory. Claude handles everything automatically.**
|
|
78
|
+
|
|
79
|
+
- Auto-loads relevant context at session start
|
|
80
|
+
- Recognizes memory-worthy moments and asks "Save this? y/n"
|
|
81
|
+
- Synthesizes answers naturally—no raw JSON, no memory IDs
|
|
82
|
+
- MCP instructions inject automatically—zero configuration
|
|
83
|
+
|
|
84
|
+
### Cognitive Architecture, Not Storage
|
|
85
|
+
Other memory systems store embeddings. Spatial Memory implements how memory actually works:
|
|
86
|
+
|
|
87
|
+
- **Decay**: Memories fade over time (Ebbinghaus forgetting curve)
|
|
88
|
+
- **Reinforcement**: Frequently accessed memories grow stronger
|
|
89
|
+
- **Consolidation**: Similar memories merge intelligently
|
|
90
|
+
- **Extraction**: Auto-capture facts, decisions, patterns from conversations
|
|
91
|
+
|
|
92
|
+
### Spatial Navigation (Unique Innovation)
|
|
93
|
+
Navigate knowledge like a landscape, not a filing cabinet:
|
|
94
|
+
|
|
95
|
+
| Tool | What It Does |
|
|
96
|
+
|------|-------------|
|
|
97
|
+
| **Journey** | SLERP between two memories—discover what's conceptually in between |
|
|
98
|
+
| **Wander** | Random walk exploration—find unexpected connections |
|
|
99
|
+
| **Regions** | HDBSCAN clustering—see how your knowledge self-organizes |
|
|
100
|
+
| **Visualize** | UMAP projection—view your memory space in 2D/3D |
|
|
101
|
+
|
|
102
|
+
### 22 Tools vs. 3-6 in Competitors
|
|
103
|
+
Full lifecycle management: core operations, spatial navigation, memory lifecycle, hybrid search, namespace management, data import/export, and health/stats monitoring.
|
|
104
|
+
|
|
105
|
+
### Enterprise-Ready
|
|
106
|
+
Connection pooling, circuit breakers, per-agent rate limiting, request tracing, response caching, and defense-in-depth security (path traversal prevention, SQL injection detection, input validation).
|
|
107
|
+
|
|
108
|
+
> *See [MARKETING.md](MARKETING.md) for the complete comparison with competitors.*
|
|
109
|
+
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
- **22 MCP tools** across 4 categories (core, spatial, lifecycle, utility)
|
|
113
|
+
- **Clean Architecture** with ports/adapters pattern for testability
|
|
114
|
+
- **LanceDB** vector storage with automatic indexing
|
|
115
|
+
- **Dual embedding support**: Local (sentence-transformers) or OpenAI API
|
|
116
|
+
- **ONNX Runtime** by default for 2-3x faster embeddings
|
|
117
|
+
- **Enterprise features**: Connection pooling, retry logic, batch operations
|
|
118
|
+
- **Comprehensive security**: Path validation, SQL injection prevention, input sanitization
|
|
119
|
+
- **1400+ tests** including security edge cases
|
|
120
|
+
|
|
121
|
+
## Roadmap
|
|
122
|
+
|
|
123
|
+
| Phase | Status | Features |
|
|
124
|
+
|-------|--------|----------|
|
|
125
|
+
| Phase 1: Foundation | Complete | Config, Database, Embeddings, Models, Errors |
|
|
126
|
+
| Phase 2: Core Operations | Complete | `remember`, `recall`, `nearby`, `forget` |
|
|
127
|
+
| Phase 3: Spatial Operations | Complete | `journey`, `wander`, `regions`, `visualize` |
|
|
128
|
+
| Phase 4: Lifecycle Operations | Complete | `consolidate`, `extract`, `decay`, `reinforce` |
|
|
129
|
+
| Phase 5: Utilities | Complete | `stats`, `namespaces`, `export`, `import`, `hybrid_recall` |
|
|
130
|
+
| Phase 6: Polish & Release | Complete | v1.8.0 on PyPI |
|
|
131
|
+
|
|
132
|
+
## Installation
|
|
133
|
+
|
|
134
|
+
### From PyPI (Recommended)
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
pip install spatial-memory-mcp
|
|
138
|
+
|
|
139
|
+
# Or with uv
|
|
140
|
+
uv pip install spatial-memory-mcp
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Development Setup
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/arman-tech/spatial-memory-mcp.git
|
|
147
|
+
cd spatial-memory-mcp
|
|
148
|
+
pip install -e ".[dev]"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### With OpenAI Support
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# From PyPI
|
|
155
|
+
pip install spatial-memory-mcp[openai]
|
|
156
|
+
|
|
157
|
+
# From source
|
|
158
|
+
pip install -e ".[dev,openai]"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Verify Installation
|
|
162
|
+
|
|
163
|
+
After installation, verify that all dependencies are correctly installed:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
python -m spatial_memory.verify
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Or manually check:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
# Run in Python interpreter
|
|
173
|
+
from spatial_memory.core.embeddings import EmbeddingService, _is_onnx_available
|
|
174
|
+
print(f"ONNX available: {_is_onnx_available()}")
|
|
175
|
+
svc = EmbeddingService()
|
|
176
|
+
print(f"Backend: {svc.backend}, Dimensions: {svc.dimensions}")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Expected output with ONNX Runtime (default):
|
|
180
|
+
```
|
|
181
|
+
ONNX available: True
|
|
182
|
+
Backend: onnx, Dimensions: 384
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If ONNX shows as unavailable, reinstall with:
|
|
186
|
+
```bash
|
|
187
|
+
pip install --force-reinstall "sentence-transformers[onnx]"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### CLI Commands
|
|
191
|
+
|
|
192
|
+
The `spatial-memory` CLI provides several commands:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Start the MCP server (default)
|
|
196
|
+
spatial-memory serve
|
|
197
|
+
|
|
198
|
+
# View the MCP instructions injected into Claude's context
|
|
199
|
+
spatial-memory instructions
|
|
200
|
+
|
|
201
|
+
# Run database migrations
|
|
202
|
+
spatial-memory migrate --status # Check migration status
|
|
203
|
+
spatial-memory migrate --dry-run # Preview migrations
|
|
204
|
+
spatial-memory migrate # Apply pending migrations
|
|
205
|
+
|
|
206
|
+
# Show version
|
|
207
|
+
spatial-memory --version
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The `instructions` command is useful for understanding what behavioral guidelines are automatically injected when the MCP server connects to Claude.
|
|
211
|
+
|
|
212
|
+
### Optional Performance Dependencies
|
|
213
|
+
|
|
214
|
+
For best performance, install these optional dependencies:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# ONNX Runtime - 2-3x faster embeddings, 60% less memory
|
|
218
|
+
pip install onnxruntime
|
|
219
|
+
|
|
220
|
+
# Or install with sentence-transformers ONNX support
|
|
221
|
+
pip install "sentence-transformers[onnx]"
|
|
222
|
+
|
|
223
|
+
# scipy - Optimized pairwise similarity calculations
|
|
224
|
+
# Used by visualize, regions, and consolidate operations
|
|
225
|
+
pip install scipy
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Performance comparison:**
|
|
229
|
+
|
|
230
|
+
| Component | Without | With | Benefit |
|
|
231
|
+
|-----------|---------|------|---------|
|
|
232
|
+
| ONNX Runtime | PyTorch inference | ONNX inference | 2-3x faster embeddings |
|
|
233
|
+
| scipy | numpy matrix ops | scipy.cdist | Faster similarity calculations |
|
|
234
|
+
|
|
235
|
+
Both are optional - the system includes fallbacks that use numpy when these aren't available.
|
|
236
|
+
|
|
237
|
+
## Configuration
|
|
238
|
+
|
|
239
|
+
Copy `.env.example` to `.env` and customize:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
cp .env.example .env
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Key Configuration Options
|
|
246
|
+
|
|
247
|
+
| Variable | Default | Description |
|
|
248
|
+
|----------|---------|-------------|
|
|
249
|
+
| `SPATIAL_MEMORY_MEMORY_PATH` | `./.spatial-memory` | LanceDB storage directory |
|
|
250
|
+
| `SPATIAL_MEMORY_EMBEDDING_MODEL` | `all-MiniLM-L6-v2` | Embedding model (local or `openai:*`) |
|
|
251
|
+
| `SPATIAL_MEMORY_EMBEDDING_BACKEND` | `auto` | Backend: `auto`, `onnx`, or `pytorch` |
|
|
252
|
+
| `SPATIAL_MEMORY_OPENAI_API_KEY` | - | Required only for OpenAI embeddings |
|
|
253
|
+
| `SPATIAL_MEMORY_LOG_LEVEL` | `INFO` | Logging verbosity |
|
|
254
|
+
| `SPATIAL_MEMORY_AUTO_CREATE_INDEXES` | `true` | Auto-create vector indexes |
|
|
255
|
+
| `SPATIAL_MEMORY_AUTO_DECAY_ENABLED` | `true` | Enable automatic importance decay |
|
|
256
|
+
| `SPATIAL_MEMORY_AUTO_DECAY_FUNCTION` | `exponential` | Decay function: `exponential`, `linear`, or `step` |
|
|
257
|
+
| `SPATIAL_MEMORY_AUTO_DECAY_PERSIST_ENABLED` | `true` | Persist decay updates to database |
|
|
258
|
+
|
|
259
|
+
See [docs/CONFIGURATION.md](docs/CONFIGURATION.md) for the complete configuration reference.
|
|
260
|
+
|
|
261
|
+
### Embedding Models
|
|
262
|
+
|
|
263
|
+
**Local models** (no API key required):
|
|
264
|
+
- `all-MiniLM-L6-v2` - Fast, good quality (384 dimensions)
|
|
265
|
+
- `all-mpnet-base-v2` - Slower, better quality (768 dimensions)
|
|
266
|
+
|
|
267
|
+
**OpenAI models** (requires API key):
|
|
268
|
+
- `openai:text-embedding-3-small` - Fast, cost-effective (1536 dimensions)
|
|
269
|
+
- `openai:text-embedding-3-large` - Best quality (3072 dimensions)
|
|
270
|
+
|
|
271
|
+
### Embedding Backend
|
|
272
|
+
|
|
273
|
+
By default, local models use **ONNX Runtime** for 2-3x faster inference and 60% less memory:
|
|
274
|
+
|
|
275
|
+
| Backend | Speed | Memory | Notes |
|
|
276
|
+
|---------|-------|--------|-------|
|
|
277
|
+
| ONNX Runtime (default) | 2-3x faster | 60% less | Optimized for CPU inference |
|
|
278
|
+
| PyTorch | Baseline | Baseline | Full flexibility |
|
|
279
|
+
|
|
280
|
+
Configure via environment variable:
|
|
281
|
+
```bash
|
|
282
|
+
# Auto-detect (default) - uses ONNX if available
|
|
283
|
+
SPATIAL_MEMORY_EMBEDDING_BACKEND=auto
|
|
284
|
+
|
|
285
|
+
# Force specific backend
|
|
286
|
+
SPATIAL_MEMORY_EMBEDDING_BACKEND=onnx
|
|
287
|
+
SPATIAL_MEMORY_EMBEDDING_BACKEND=pytorch
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Usage
|
|
291
|
+
|
|
292
|
+
Add to your Claude Desktop config (`claude_desktop_config.json`):
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{
|
|
296
|
+
"mcpServers": {
|
|
297
|
+
"spatial-memory": {
|
|
298
|
+
"command": "python",
|
|
299
|
+
"args": ["-m", "spatial_memory"],
|
|
300
|
+
"env": {
|
|
301
|
+
"SPATIAL_MEMORY_MEMORY_PATH": "/path/to/memory/storage"
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Available Tools (22 Total)
|
|
309
|
+
|
|
310
|
+
For complete API documentation including parameters, return types, and examples, see [docs/API.md](docs/API.md).
|
|
311
|
+
|
|
312
|
+
### Core Operations
|
|
313
|
+
|
|
314
|
+
| Tool | Description |
|
|
315
|
+
|------|-------------|
|
|
316
|
+
| `remember` | Store a memory with optional tags, importance, and metadata |
|
|
317
|
+
| `remember_batch` | Store multiple memories efficiently in a single operation |
|
|
318
|
+
| `recall` | Find memories semantically similar to a query with optional filters |
|
|
319
|
+
| `nearby` | Find memories spatially close to a specific memory by ID |
|
|
320
|
+
| `forget` | Remove a memory by ID |
|
|
321
|
+
| `forget_batch` | Remove multiple memories by IDs |
|
|
322
|
+
|
|
323
|
+
### Spatial Operations
|
|
324
|
+
|
|
325
|
+
| Tool | Description |
|
|
326
|
+
|------|-------------|
|
|
327
|
+
| `journey` | Interpolate a path between two memories using SLERP, discovering concepts along the way |
|
|
328
|
+
| `wander` | Random walk through memory space for serendipitous discovery |
|
|
329
|
+
| `regions` | Discover conceptual regions via HDBSCAN clustering with auto-generated labels |
|
|
330
|
+
| `visualize` | Generate 2D visualization (JSON coordinates, Mermaid diagrams, or SVG) |
|
|
331
|
+
|
|
332
|
+
### Lifecycle Operations
|
|
333
|
+
|
|
334
|
+
| Tool | Description |
|
|
335
|
+
|------|-------------|
|
|
336
|
+
| `decay` | Reduce importance of stale/unused memories based on time or access patterns |
|
|
337
|
+
| `reinforce` | Boost importance of useful memories |
|
|
338
|
+
| `extract` | Auto-extract memorable facts, decisions, and insights from text |
|
|
339
|
+
| `consolidate` | Find and merge similar/duplicate memories with configurable strategies |
|
|
340
|
+
|
|
341
|
+
### Utility Operations
|
|
342
|
+
|
|
343
|
+
| Tool | Description |
|
|
344
|
+
|------|-------------|
|
|
345
|
+
| `stats` | Get comprehensive database statistics (counts, storage, indexes) |
|
|
346
|
+
| `namespaces` | List all namespaces with memory counts |
|
|
347
|
+
| `delete_namespace` | Delete a namespace and all its memories |
|
|
348
|
+
| `rename_namespace` | Rename a namespace |
|
|
349
|
+
| `export_memories` | Export memories to Parquet, JSON, or CSV format |
|
|
350
|
+
| `import_memories` | Import memories from exported files with validation |
|
|
351
|
+
| `hybrid_recall` | Combined vector + full-text search with configurable weighting |
|
|
352
|
+
| `health` | Check system health status |
|
|
353
|
+
|
|
354
|
+
## Tool Examples
|
|
355
|
+
|
|
356
|
+
### Remember a Memory
|
|
357
|
+
|
|
358
|
+
```
|
|
359
|
+
Store this: "Use repository pattern for database access in this project"
|
|
360
|
+
Tags: architecture, patterns
|
|
361
|
+
Importance: 0.8
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Semantic Recall
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
What do I know about database patterns?
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Journey Between Concepts
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
Show me a journey from "React components" to "database design"
|
|
374
|
+
```
|
|
375
|
+
This reveals intermediate concepts like state management, data flow, API design, etc.
|
|
376
|
+
|
|
377
|
+
### Discover Regions
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
What conceptual regions exist in my memories?
|
|
381
|
+
```
|
|
382
|
+
Returns auto-clustered groups with labels and representative memories.
|
|
383
|
+
|
|
384
|
+
### Apply Memory Decay
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
Decay unused memories (dry run first to preview)
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Export for Backup
|
|
391
|
+
|
|
392
|
+
```
|
|
393
|
+
Export all memories to parquet format
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Security Features
|
|
397
|
+
|
|
398
|
+
- **Path Traversal Prevention**: All file operations validate paths against allowed directories
|
|
399
|
+
- **Symlink Attack Protection**: Optional symlink blocking for sensitive environments
|
|
400
|
+
- **SQL Injection Prevention**: 13 patterns covering major attack vectors
|
|
401
|
+
- **Input Validation**: Pydantic models validate all inputs
|
|
402
|
+
- **Error Sanitization**: Internal errors return reference IDs, not stack traces
|
|
403
|
+
- **Secure Credential Handling**: API keys stored as SecretStr
|
|
404
|
+
|
|
405
|
+
## Deployment Considerations
|
|
406
|
+
|
|
407
|
+
### Network Filesystems (NFS/SMB/CIFS)
|
|
408
|
+
|
|
409
|
+
Spatial Memory uses file-based locking to prevent data corruption when multiple processes access the same storage. **File locking does not work reliably on network filesystems** such as NFS, SMB/CIFS, or SSHFS.
|
|
410
|
+
|
|
411
|
+
If the storage path is on a network filesystem, you will see a warning at startup:
|
|
412
|
+
|
|
413
|
+
```
|
|
414
|
+
WARNING: Storage path appears to be on a network filesystem (nfs).
|
|
415
|
+
File-based locking does not work reliably on network filesystems.
|
|
416
|
+
Running multiple instances against this storage may cause data corruption.
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Recommendations:**
|
|
420
|
+
1. **Use local storage** (default: `./.spatial-memory`) for reliable operation
|
|
421
|
+
2. **Single instance only**: If you must use network storage, ensure only one MCP server instance accesses it
|
|
422
|
+
3. **Acknowledge the risk**: Set `SPATIAL_MEMORY_ACKNOWLEDGE_NETWORK_FS_RISK=true` to suppress the warning
|
|
423
|
+
|
|
424
|
+
## Development
|
|
425
|
+
|
|
426
|
+
### Running Tests
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
# All tests
|
|
430
|
+
pytest tests/ -v
|
|
431
|
+
|
|
432
|
+
# Fast unit tests only
|
|
433
|
+
pytest tests/ -m unit -v
|
|
434
|
+
|
|
435
|
+
# Security-specific tests
|
|
436
|
+
pytest tests/ -k "security or injection" -v
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Type Checking
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
mypy spatial_memory/ --ignore-missing-imports
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Linting
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
ruff check spatial_memory/ tests/
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Architecture
|
|
452
|
+
|
|
453
|
+
The project follows Clean Architecture principles:
|
|
454
|
+
|
|
455
|
+
```
|
|
456
|
+
spatial_memory/
|
|
457
|
+
├── core/ # Domain logic (database, embeddings, models, errors)
|
|
458
|
+
├── services/ # Application services (memory, spatial, lifecycle)
|
|
459
|
+
├── adapters/ # Infrastructure (LanceDB repository)
|
|
460
|
+
├── ports/ # Protocol interfaces
|
|
461
|
+
└── server.py # MCP server entry point
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
See [SPATIAL-MEMORY-ARCHITECTURE-DIAGRAMS.md](SPATIAL-MEMORY-ARCHITECTURE-DIAGRAMS.md) for visual architecture documentation.
|
|
465
|
+
|
|
466
|
+
## Documentation
|
|
467
|
+
|
|
468
|
+
| Document | Description |
|
|
469
|
+
|----------|-------------|
|
|
470
|
+
| [docs/API.md](docs/API.md) | Complete API reference for all 22 tools |
|
|
471
|
+
| [docs/CONFIGURATION.md](docs/CONFIGURATION.md) | Full configuration reference (env vars, .mcp.json, auto-decay) |
|
|
472
|
+
| [docs/BENCHMARKS.md](docs/BENCHMARKS.md) | Performance benchmarks and test results |
|
|
473
|
+
| [docs/METRICS.md](docs/METRICS.md) | Prometheus metrics documentation |
|
|
474
|
+
| [docs/troubleshooting.md](docs/troubleshooting.md) | Troubleshooting guide |
|
|
475
|
+
|
|
476
|
+
## Troubleshooting
|
|
477
|
+
|
|
478
|
+
### Common Issues
|
|
479
|
+
|
|
480
|
+
**Model download fails**: The first run downloads the embedding model (~80MB). Ensure internet connectivity.
|
|
481
|
+
|
|
482
|
+
**Permission errors**: Check that `SPATIAL_MEMORY_MEMORY_PATH` is writable.
|
|
483
|
+
|
|
484
|
+
**OpenAI errors**: Verify `SPATIAL_MEMORY_OPENAI_API_KEY` is set correctly.
|
|
485
|
+
|
|
486
|
+
**Import validation errors**: Use `dry_run=true` first to preview validation issues.
|
|
487
|
+
|
|
488
|
+
## Contributing
|
|
489
|
+
|
|
490
|
+
Contributions welcome! Please:
|
|
491
|
+
1. Fork the repository
|
|
492
|
+
2. Create a feature branch
|
|
493
|
+
3. Add tests for new functionality
|
|
494
|
+
4. Ensure all tests pass
|
|
495
|
+
5. Submit a pull request
|
|
496
|
+
|
|
497
|
+
## Security
|
|
498
|
+
|
|
499
|
+
For security vulnerabilities, please email directly rather than opening a public issue.
|
|
500
|
+
|
|
501
|
+
## For Claude Code Users
|
|
502
|
+
|
|
503
|
+
When the MCP server connects, behavioral instructions are **automatically injected** into Claude's context—no configuration needed. Run `spatial-memory instructions` to view what gets injected.
|
|
504
|
+
|
|
505
|
+
For contributors working on this codebase, [CLAUDE.md](CLAUDE.md) provides project-specific guidance for AI assistants.
|
|
506
|
+
|
|
507
|
+
## License
|
|
508
|
+
|
|
509
|
+
MIT - See [LICENSE](LICENSE)
|