neural-memory 0.1.0__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.
- neural_memory/__init__.py +38 -0
- neural_memory/cli/__init__.py +15 -0
- neural_memory/cli/__main__.py +6 -0
- neural_memory/cli/config.py +176 -0
- neural_memory/cli/main.py +2702 -0
- neural_memory/cli/storage.py +169 -0
- neural_memory/cli/tui.py +471 -0
- neural_memory/core/__init__.py +52 -0
- neural_memory/core/brain.py +301 -0
- neural_memory/core/brain_mode.py +273 -0
- neural_memory/core/fiber.py +236 -0
- neural_memory/core/memory_types.py +331 -0
- neural_memory/core/neuron.py +168 -0
- neural_memory/core/project.py +257 -0
- neural_memory/core/synapse.py +215 -0
- neural_memory/engine/__init__.py +15 -0
- neural_memory/engine/activation.py +335 -0
- neural_memory/engine/encoder.py +391 -0
- neural_memory/engine/retrieval.py +440 -0
- neural_memory/extraction/__init__.py +42 -0
- neural_memory/extraction/entities.py +547 -0
- neural_memory/extraction/parser.py +337 -0
- neural_memory/extraction/router.py +396 -0
- neural_memory/extraction/temporal.py +428 -0
- neural_memory/mcp/__init__.py +9 -0
- neural_memory/mcp/__main__.py +6 -0
- neural_memory/mcp/server.py +621 -0
- neural_memory/py.typed +0 -0
- neural_memory/safety/__init__.py +31 -0
- neural_memory/safety/freshness.py +238 -0
- neural_memory/safety/sensitive.py +304 -0
- neural_memory/server/__init__.py +5 -0
- neural_memory/server/app.py +99 -0
- neural_memory/server/dependencies.py +33 -0
- neural_memory/server/models.py +138 -0
- neural_memory/server/routes/__init__.py +7 -0
- neural_memory/server/routes/brain.py +221 -0
- neural_memory/server/routes/memory.py +169 -0
- neural_memory/server/routes/sync.py +387 -0
- neural_memory/storage/__init__.py +17 -0
- neural_memory/storage/base.py +441 -0
- neural_memory/storage/factory.py +329 -0
- neural_memory/storage/memory_store.py +896 -0
- neural_memory/storage/shared_store.py +650 -0
- neural_memory/storage/sqlite_store.py +1613 -0
- neural_memory/sync/__init__.py +5 -0
- neural_memory/sync/client.py +435 -0
- neural_memory/unified_config.py +315 -0
- neural_memory/utils/__init__.py +5 -0
- neural_memory/utils/config.py +98 -0
- neural_memory-0.1.0.dist-info/METADATA +314 -0
- neural_memory-0.1.0.dist-info/RECORD +55 -0
- neural_memory-0.1.0.dist-info/WHEEL +4 -0
- neural_memory-0.1.0.dist-info/entry_points.txt +4 -0
- neural_memory-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""NeuralMemory - Reflex-based memory system for AI agents."""
|
|
2
|
+
|
|
3
|
+
from neural_memory.core.brain import Brain, BrainConfig
|
|
4
|
+
from neural_memory.core.brain_mode import (
|
|
5
|
+
BrainMode,
|
|
6
|
+
BrainModeConfig,
|
|
7
|
+
SharedConfig,
|
|
8
|
+
SyncStrategy,
|
|
9
|
+
)
|
|
10
|
+
from neural_memory.core.fiber import Fiber
|
|
11
|
+
from neural_memory.core.neuron import Neuron, NeuronState, NeuronType
|
|
12
|
+
from neural_memory.core.synapse import Direction, Synapse, SynapseType
|
|
13
|
+
from neural_memory.engine.encoder import EncodingResult, MemoryEncoder
|
|
14
|
+
from neural_memory.engine.retrieval import DepthLevel, ReflexPipeline, RetrievalResult
|
|
15
|
+
|
|
16
|
+
__version__ = "0.1.0"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"__version__",
|
|
20
|
+
"Brain",
|
|
21
|
+
"BrainConfig",
|
|
22
|
+
"BrainMode",
|
|
23
|
+
"BrainModeConfig",
|
|
24
|
+
"DepthLevel",
|
|
25
|
+
"Direction",
|
|
26
|
+
"EncodingResult",
|
|
27
|
+
"Fiber",
|
|
28
|
+
"MemoryEncoder",
|
|
29
|
+
"Neuron",
|
|
30
|
+
"NeuronState",
|
|
31
|
+
"NeuronType",
|
|
32
|
+
"ReflexPipeline",
|
|
33
|
+
"RetrievalResult",
|
|
34
|
+
"SharedConfig",
|
|
35
|
+
"Synapse",
|
|
36
|
+
"SynapseType",
|
|
37
|
+
"SyncStrategy",
|
|
38
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Neural Memory CLI.
|
|
2
|
+
|
|
3
|
+
Simple command-line interface for storing and retrieving memories.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
nmem remember "content" Store a memory
|
|
7
|
+
nmem recall "query" Query memories
|
|
8
|
+
nmem context Get recent context
|
|
9
|
+
nmem brain list List brains
|
|
10
|
+
nmem brain use <name> Switch brain
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from neural_memory.cli.main import app, main
|
|
14
|
+
|
|
15
|
+
__all__ = ["app", "main"]
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""CLI configuration management.
|
|
2
|
+
|
|
3
|
+
This module provides backward-compatible configuration for the CLI.
|
|
4
|
+
New code should use unified_config.py for cross-tool compatibility.
|
|
5
|
+
|
|
6
|
+
Storage locations:
|
|
7
|
+
- Legacy: ~/.neural-memory/brains/<name>.json (JSON files)
|
|
8
|
+
- New: ~/.neuralmemory/brains/<name>.db (SQLite database)
|
|
9
|
+
|
|
10
|
+
The CLI automatically migrates to the new unified config when:
|
|
11
|
+
- NEURALMEMORY_DIR environment variable is set, OR
|
|
12
|
+
- ~/.neuralmemory/config.toml exists
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_default_data_dir() -> Path:
|
|
26
|
+
"""Get default data directory for neural-memory.
|
|
27
|
+
|
|
28
|
+
Priority:
|
|
29
|
+
1. NEURALMEMORY_DIR environment variable (new unified location)
|
|
30
|
+
2. ~/.neuralmemory/ (if config.toml exists there)
|
|
31
|
+
3. ~/.neural-memory/ (legacy location)
|
|
32
|
+
"""
|
|
33
|
+
# Check for env var first (new unified approach)
|
|
34
|
+
env_dir = os.environ.get("NEURALMEMORY_DIR")
|
|
35
|
+
if env_dir:
|
|
36
|
+
return Path(env_dir)
|
|
37
|
+
|
|
38
|
+
# Check if new unified config exists
|
|
39
|
+
unified_dir = Path.home() / ".neuralmemory"
|
|
40
|
+
if (unified_dir / "config.toml").exists():
|
|
41
|
+
return unified_dir
|
|
42
|
+
|
|
43
|
+
# Fall back to legacy location
|
|
44
|
+
return Path.home() / ".neural-memory"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def use_unified_config() -> bool:
|
|
48
|
+
"""Check if we should use the unified config system."""
|
|
49
|
+
env_dir = os.environ.get("NEURALMEMORY_DIR")
|
|
50
|
+
if env_dir:
|
|
51
|
+
return True
|
|
52
|
+
|
|
53
|
+
unified_dir = Path.home() / ".neuralmemory"
|
|
54
|
+
return (unified_dir / "config.toml").exists()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass
|
|
58
|
+
class SharedModeConfig:
|
|
59
|
+
"""Configuration for shared/remote storage mode."""
|
|
60
|
+
|
|
61
|
+
enabled: bool = False
|
|
62
|
+
server_url: str = "http://localhost:8000"
|
|
63
|
+
api_key: str | None = None
|
|
64
|
+
timeout: float = 30.0
|
|
65
|
+
|
|
66
|
+
def to_dict(self) -> dict[str, Any]:
|
|
67
|
+
"""Convert to dictionary."""
|
|
68
|
+
return {
|
|
69
|
+
"enabled": self.enabled,
|
|
70
|
+
"server_url": self.server_url,
|
|
71
|
+
"api_key": self.api_key,
|
|
72
|
+
"timeout": self.timeout,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls, data: dict[str, Any]) -> SharedModeConfig:
|
|
77
|
+
"""Create from dictionary."""
|
|
78
|
+
return cls(
|
|
79
|
+
enabled=data.get("enabled", False),
|
|
80
|
+
server_url=data.get("server_url", "http://localhost:8000"),
|
|
81
|
+
api_key=data.get("api_key"),
|
|
82
|
+
timeout=data.get("timeout", 30.0),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass
|
|
87
|
+
class CLIConfig:
|
|
88
|
+
"""CLI configuration."""
|
|
89
|
+
|
|
90
|
+
data_dir: Path = field(default_factory=get_default_data_dir)
|
|
91
|
+
current_brain: str = "default"
|
|
92
|
+
default_depth: int | None = None # Auto-detect
|
|
93
|
+
default_max_tokens: int = 500
|
|
94
|
+
json_output: bool = False
|
|
95
|
+
shared: SharedModeConfig = field(default_factory=SharedModeConfig)
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def load(cls, data_dir: Path | None = None) -> CLIConfig:
|
|
99
|
+
"""Load configuration from file."""
|
|
100
|
+
if data_dir is None:
|
|
101
|
+
data_dir = get_default_data_dir()
|
|
102
|
+
|
|
103
|
+
config_file = data_dir / "config.json"
|
|
104
|
+
|
|
105
|
+
if not config_file.exists():
|
|
106
|
+
# Create default config
|
|
107
|
+
config = cls(data_dir=data_dir)
|
|
108
|
+
config.save()
|
|
109
|
+
return config
|
|
110
|
+
|
|
111
|
+
with open(config_file, encoding="utf-8") as f:
|
|
112
|
+
data = json.load(f)
|
|
113
|
+
|
|
114
|
+
# Parse shared config
|
|
115
|
+
shared_data = data.get("shared", {})
|
|
116
|
+
shared_config = SharedModeConfig.from_dict(shared_data)
|
|
117
|
+
|
|
118
|
+
return cls(
|
|
119
|
+
data_dir=data_dir,
|
|
120
|
+
current_brain=data.get("current_brain", "default"),
|
|
121
|
+
default_depth=data.get("default_depth"),
|
|
122
|
+
default_max_tokens=data.get("default_max_tokens", 500),
|
|
123
|
+
json_output=data.get("json_output", False),
|
|
124
|
+
shared=shared_config,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def save(self) -> None:
|
|
128
|
+
"""Save configuration to file."""
|
|
129
|
+
self.data_dir.mkdir(parents=True, exist_ok=True)
|
|
130
|
+
config_file = self.data_dir / "config.json"
|
|
131
|
+
|
|
132
|
+
data = {
|
|
133
|
+
"current_brain": self.current_brain,
|
|
134
|
+
"default_depth": self.default_depth,
|
|
135
|
+
"default_max_tokens": self.default_max_tokens,
|
|
136
|
+
"json_output": self.json_output,
|
|
137
|
+
"shared": self.shared.to_dict(),
|
|
138
|
+
"updated_at": datetime.now().isoformat(),
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
with open(config_file, "w", encoding="utf-8") as f:
|
|
142
|
+
json.dump(data, f, indent=2)
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def brains_dir(self) -> Path:
|
|
146
|
+
"""Get brains directory."""
|
|
147
|
+
return self.data_dir / "brains"
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def is_shared_mode(self) -> bool:
|
|
151
|
+
"""Check if shared mode is enabled."""
|
|
152
|
+
return self.shared.enabled
|
|
153
|
+
|
|
154
|
+
def get_brain_path(self, brain_name: str | None = None) -> Path:
|
|
155
|
+
"""Get path to brain data file."""
|
|
156
|
+
name = brain_name or self.current_brain
|
|
157
|
+
return self.brains_dir / f"{name}.json"
|
|
158
|
+
|
|
159
|
+
def list_brains(self) -> list[str]:
|
|
160
|
+
"""List available brains."""
|
|
161
|
+
if not self.brains_dir.exists():
|
|
162
|
+
return []
|
|
163
|
+
# Check both JSON (legacy) and DB (new) files
|
|
164
|
+
json_brains = [p.stem for p in self.brains_dir.glob("*.json")]
|
|
165
|
+
db_brains = [p.stem for p in self.brains_dir.glob("*.db")]
|
|
166
|
+
return list(set(json_brains + db_brains))
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def use_sqlite(self) -> bool:
|
|
170
|
+
"""Check if SQLite storage should be used (unified mode)."""
|
|
171
|
+
return use_unified_config()
|
|
172
|
+
|
|
173
|
+
def get_brain_db_path(self, brain_name: str | None = None) -> Path:
|
|
174
|
+
"""Get path to brain SQLite database (unified mode)."""
|
|
175
|
+
name = brain_name or self.current_brain
|
|
176
|
+
return self.brains_dir / f"{name}.db"
|