albert-memory 0.4.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.
Files changed (74) hide show
  1. albert/__init__.py +3 -0
  2. albert/admin.py +532 -0
  3. albert/api.py +698 -0
  4. albert/automatic_memory_release.json +14 -0
  5. albert/benchmark.py +272 -0
  6. albert/benchmark_cli.py +37 -0
  7. albert/capture.py +1051 -0
  8. albert/capture_installer.py +1000 -0
  9. albert/capture_promotion.py +298 -0
  10. albert/capture_retention.py +72 -0
  11. albert/capture_sdk.py +558 -0
  12. albert/capture_security.py +79 -0
  13. albert/chunking.py +79 -0
  14. albert/classifier.py +263 -0
  15. albert/claude_adapter.py +357 -0
  16. albert/claude_lifecycle.py +418 -0
  17. albert/claude_package.json +19 -0
  18. albert/claude_plugin/.claude-plugin/plugin.json +11 -0
  19. albert/claude_plugin/.mcp.json +13 -0
  20. albert/claude_plugin/hooks/hooks.json +70 -0
  21. albert/clusters.py +140 -0
  22. albert/codex_adapter.py +308 -0
  23. albert/codex_hooks/hooks.json +49 -0
  24. albert/codex_lifecycle.py +485 -0
  25. albert/codex_package.json +19 -0
  26. albert/compatibility.py +121 -0
  27. albert/config.py +144 -0
  28. albert/console.py +508 -0
  29. albert/console_backends.py +236 -0
  30. albert/console_map.py +518 -0
  31. albert/console_ops.py +919 -0
  32. albert/credentials.py +616 -0
  33. albert/cursor_adapter.py +320 -0
  34. albert/cursor_hooks/hooks.json +11 -0
  35. albert/cursor_rules/albert-memory.mdc +11 -0
  36. albert/db.py +68 -0
  37. albert/embeddings.py +91 -0
  38. albert/graph.py +623 -0
  39. albert/graph_builders.py +879 -0
  40. albert/graph_cypher.py +669 -0
  41. albert/graph_store.py +376 -0
  42. albert/host_targets/claude-code.json +45 -0
  43. albert/host_targets/codex.json +45 -0
  44. albert/host_targets/openclaw.json +45 -0
  45. albert/host_targets.py +271 -0
  46. albert/links.py +428 -0
  47. albert/mcp_server.py +457 -0
  48. albert/memory_safety.py +111 -0
  49. albert/models.py +611 -0
  50. albert/openclaw_adapter.py +326 -0
  51. albert/openclaw_adapter_trust.json +5 -0
  52. albert/openclaw_package.json +22 -0
  53. albert/openclaw_plugin/index.js +135 -0
  54. albert/openclaw_plugin/openclaw.plugin.json +25 -0
  55. albert/openclaw_plugin/package.json +12 -0
  56. albert/portability.py +291 -0
  57. albert/provenance.py +105 -0
  58. albert/recorder.py +166 -0
  59. albert/release_gate.py +83 -0
  60. albert/schemas.py +617 -0
  61. albert/scope.py +26 -0
  62. albert/search.py +447 -0
  63. albert/security.py +150 -0
  64. albert/services.py +1316 -0
  65. albert/session_context.py +162 -0
  66. albert/trace_feed.py +165 -0
  67. albert/trace_writer.py +131 -0
  68. albert/tracing.py +75 -0
  69. albert/worker.py +202 -0
  70. albert/workspaces.py +256 -0
  71. albert_memory-0.4.0.dist-info/METADATA +554 -0
  72. albert_memory-0.4.0.dist-info/RECORD +74 -0
  73. albert_memory-0.4.0.dist-info/WHEEL +4 -0
  74. albert_memory-0.4.0.dist-info/entry_points.txt +14 -0
albert/graph_store.py ADDED
@@ -0,0 +1,376 @@
1
+ """The knowledge-graph storage interface and the catalogue of stores.
2
+
3
+ Every graph read and write in Albert goes through a `GraphStore`. PostgreSQL is
4
+ the built-in store; others plug in by implementing the same interface. The
5
+ types here are store-neutral on purpose: nothing outside a store's own module
6
+ may assume the graph lives in SQL tables.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass, field
12
+ from datetime import datetime
13
+ from typing import Any, Protocol
14
+ from uuid import UUID
15
+
16
+ from sqlalchemy.orm import Session
17
+
18
+ from albert.classifier import ExtractedRelationship
19
+ from albert.schemas import RelationshipRead
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class GraphEntity:
24
+ id: UUID
25
+ organization_id: UUID
26
+ workspace_id: UUID | None
27
+ name: str
28
+ entity_type: str
29
+ description: str = ""
30
+ confidence: float = 1.0
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class StoredRelationship:
35
+ """One edge with both endpoints, as any store can return it."""
36
+
37
+ id: UUID
38
+ organization_id: UUID
39
+ workspace_id: UUID | None
40
+ source: GraphEntity
41
+ target: GraphEntity
42
+ relation_type: str
43
+ sensitivity: str
44
+ source_memory_id: UUID | None
45
+ confidence: float
46
+ valid_from: datetime
47
+ valid_until: datetime | None
48
+ metadata: dict[str, Any] = field(default_factory=dict)
49
+
50
+ def read(self) -> RelationshipRead:
51
+ return RelationshipRead(
52
+ id=self.id,
53
+ source_entity_id=self.source.id,
54
+ source_name=self.source.name,
55
+ source_type=self.source.entity_type,
56
+ relation_type=self.relation_type,
57
+ sensitivity=self.sensitivity,
58
+ target_entity_id=self.target.id,
59
+ target_name=self.target.name,
60
+ target_type=self.target.entity_type,
61
+ source_memory_id=self.source_memory_id,
62
+ confidence=self.confidence,
63
+ valid_from=self.valid_from,
64
+ valid_until=self.valid_until,
65
+ )
66
+
67
+
68
+ class GraphStore(Protocol):
69
+ """What Albert needs from a knowledge-graph backend.
70
+
71
+ Every method receives the request's SQLAlchemy session. The PostgreSQL store
72
+ writes through it, so graph changes commit or roll back with the memory they
73
+ belong to. A store that keeps its data elsewhere cannot join that
74
+ transaction: it must make each write idempotent (the worker retries failed
75
+ jobs) and must enforce `organization_id`, `workspace_id`, sensitivity and
76
+ validity filters itself.
77
+
78
+ On reads (query, subgraph, export_relationships, snapshot) a `workspace_id`
79
+ covers that workspace plus the organization-wide edges and entities every
80
+ workspace shares, and None covers the whole organization (see albert.scope).
81
+ """
82
+
83
+ name: str
84
+
85
+ def add_relationship(
86
+ self,
87
+ session: Session,
88
+ *,
89
+ organization_id: UUID,
90
+ workspace_id: UUID | None,
91
+ extracted: ExtractedRelationship,
92
+ source_memory_id: UUID | None,
93
+ sensitivity: str,
94
+ valid_from: datetime,
95
+ valid_until: datetime | None = None,
96
+ metadata: dict | None = None,
97
+ ) -> tuple[StoredRelationship, bool]:
98
+ """Create or reuse an open edge, upserting both entities; (edge, created)."""
99
+ ...
100
+
101
+ def close_memory_edges(
102
+ self,
103
+ session: Session,
104
+ *,
105
+ organization_id: UUID,
106
+ memory_id: UUID,
107
+ at: datetime,
108
+ extracted_only: bool,
109
+ ) -> int:
110
+ """End the validity of a memory's still-open edges at `at`; returns how many."""
111
+ ...
112
+
113
+ def close_external_edges(
114
+ self,
115
+ session: Session,
116
+ *,
117
+ organization_id: UUID,
118
+ workspace_id: UUID | None,
119
+ builder: str,
120
+ external_ids: list[str],
121
+ at: datetime,
122
+ ) -> int:
123
+ """End edges superseded by a temporal builder's stable external ids."""
124
+ ...
125
+
126
+ def retarget_memory_edges(
127
+ self,
128
+ session: Session,
129
+ *,
130
+ organization_id: UUID,
131
+ memory_id: UUID,
132
+ sensitivity: str,
133
+ valid_until: datetime | None,
134
+ ) -> int:
135
+ """Make a memory's extracted edges follow its new sensitivity and validity."""
136
+ ...
137
+
138
+ def memory_edge_metadata(
139
+ self, session: Session, *, organization_id: UUID, memory_id: UUID
140
+ ) -> list[dict]:
141
+ """The metadata of every edge a memory produced, open or closed."""
142
+ ...
143
+
144
+ def move_workspace(
145
+ self,
146
+ session: Session,
147
+ *,
148
+ organization_id: UUID,
149
+ workspace_id: UUID,
150
+ to_workspace_id: UUID | None,
151
+ ) -> int:
152
+ """Move a workspace's entities and edges into another scope; returns edges moved.
153
+
154
+ An entity that already exists in the target scope (same canonical name and
155
+ type) absorbs the moving one's edges, so the target keeps one node per name.
156
+ """
157
+ ...
158
+
159
+ def delete_workspace(
160
+ self, session: Session, *, organization_id: UUID, workspace_id: UUID
161
+ ) -> int:
162
+ """Remove a workspace's entities and edges outright; returns edges removed."""
163
+ ...
164
+
165
+ def query(
166
+ self,
167
+ session: Session,
168
+ *,
169
+ organization_id: UUID,
170
+ workspace_id: UUID | None,
171
+ query: str,
172
+ temporal_as_of: datetime | None,
173
+ limit: int,
174
+ sensitivities: list[str],
175
+ ) -> list[RelationshipRead]:
176
+ """Edges whose entities or relation match the words of a query."""
177
+ ...
178
+
179
+ def get_entity(
180
+ self, session: Session, *, entity_id: UUID, organization_id: UUID | None = None
181
+ ) -> GraphEntity | None: ...
182
+
183
+ def subgraph(
184
+ self,
185
+ session: Session,
186
+ *,
187
+ organization_id: UUID,
188
+ workspace_id: UUID | None,
189
+ entity_id: UUID,
190
+ hops: int,
191
+ temporal_as_of: datetime | None,
192
+ limit: int,
193
+ sensitivities: list[str],
194
+ ) -> list[RelationshipRead]:
195
+ """Edges within `hops` of an entity."""
196
+ ...
197
+
198
+ def export_relationships(
199
+ self,
200
+ session: Session,
201
+ *,
202
+ organization_id: UUID,
203
+ workspace_id: UUID | None,
204
+ sensitivities: list[str],
205
+ ) -> list[StoredRelationship]:
206
+ """Explicit (not extracted) edges for a portable export."""
207
+ ...
208
+
209
+ def snapshot(
210
+ self,
211
+ session: Session,
212
+ *,
213
+ organization_id: UUID,
214
+ workspace_id: UUID | None,
215
+ when: datetime,
216
+ limit: int,
217
+ ) -> tuple[list[GraphEntity], list[StoredRelationship], bool]:
218
+ """Newest entities and the edges among them valid at `when`; (…, …, truncated)."""
219
+ ...
220
+
221
+ def counts(self, session: Session, *, when: datetime) -> dict[UUID, tuple[int, int]]:
222
+ """Per organization: (entities, edges valid at `when`)."""
223
+ ...
224
+
225
+ def fingerprint(self, session: Session, *, organization_id: UUID) -> str:
226
+ """Changes whenever the organization's graph does; used as a cache key."""
227
+ ...
228
+
229
+ def ping(self, session: Session) -> str:
230
+ """Round-trip to the backend; returns its version. Raises when unreachable."""
231
+ ...
232
+
233
+
234
+ @dataclass(frozen=True)
235
+ class BackendOption:
236
+ """One selectable backend, described for operators."""
237
+
238
+ label: str
239
+ summary: str
240
+ choose_when: str
241
+ available: bool
242
+ enable: tuple[str, ...] = ()
243
+
244
+
245
+ # The catalogues are the single source for docs, the console's Backends page and
246
+ # the settings' error messages. `available` means the adapter ships in this build.
247
+ GRAPH_STORES: dict[str, BackendOption] = {
248
+ "postgres": BackendOption(
249
+ label="PostgreSQL",
250
+ summary="Entities and edges as tables in Albert's own PostgreSQL database.",
251
+ choose_when=(
252
+ "The default. One database to run and back up, and graph writes commit with "
253
+ "the memory they came from. Suits lookups of one or two hops."
254
+ ),
255
+ available=True,
256
+ enable=("Set ALBERT_GRAPH_STORE=postgres in .env (this is the default).",),
257
+ ),
258
+ "falkordb": BackendOption(
259
+ label="FalkorDB",
260
+ summary="A Redis-based graph database queried with Cypher.",
261
+ choose_when=(
262
+ "Deep multi-hop traversal is a core workload and you want a small footprint "
263
+ "on a single host. Also the lightest database Graphiti can build on. "
264
+ "Graph writes no longer commit with the memory they came from."
265
+ ),
266
+ available=True,
267
+ enable=(
268
+ "Set ALBERT_GRAPH_STORE=falkordb in .env.",
269
+ "Start it with the others: docker compose --profile falkordb up -d",
270
+ "Re-index so the new store fills: docker compose exec api albert-admin "
271
+ "reindex-memories --all",
272
+ ),
273
+ ),
274
+ "neo4j": BackendOption(
275
+ label="Neo4j",
276
+ summary="The established graph database: Cypher, graph algorithms, clustering.",
277
+ choose_when=(
278
+ "You need its ecosystem (graph data science, visual tooling, enterprise "
279
+ "support) or already operate it. The heaviest option to run: allow it at "
280
+ "least 1-2 GB of memory."
281
+ ),
282
+ available=True,
283
+ enable=(
284
+ "Set ALBERT_GRAPH_STORE=neo4j and ALBERT_NEO4J_PASSWORD=<a strong password> in .env.",
285
+ "Start it with the others: docker compose --profile neo4j up -d",
286
+ "Re-index so the new store fills: docker compose exec api albert-admin "
287
+ "reindex-memories --all",
288
+ ),
289
+ ),
290
+ }
291
+
292
+ GRAPH_BUILDERS: dict[str, BackendOption] = {
293
+ "regex": BackendOption(
294
+ label="Regex",
295
+ summary='Pattern matching for statements like "A uses B". No model.',
296
+ choose_when=(
297
+ "No model is available. Free and deterministic, but finds little in ordinary "
298
+ "prose; explicit relationships written through the API still work fully."
299
+ ),
300
+ available=True,
301
+ enable=("Set ALBERT_LLM_PROVIDER=none in .env (this is the default).",),
302
+ ),
303
+ "llm-classifier": BackendOption(
304
+ label="LLM classifier",
305
+ summary="Albert's own extractor, using any OpenAI-compatible model.",
306
+ choose_when=(
307
+ "The first step up from regex: typed entities and relationships from every "
308
+ "memory, written to whichever store is configured. One model call per memory."
309
+ ),
310
+ available=True,
311
+ enable=(
312
+ "Set ALBERT_LLM_PROVIDER=openai-compatible, ALBERT_OPENAI_API_KEY and "
313
+ "ALBERT_CLASSIFICATION_MODEL in .env.",
314
+ "Restart: docker compose up -d api worker",
315
+ "Re-index existing memories: docker compose exec api albert-admin "
316
+ "reindex-memories --all",
317
+ ),
318
+ ),
319
+ "graphiti": BackendOption(
320
+ label="Graphiti",
321
+ summary="A temporal knowledge-graph framework that tracks facts as they change.",
322
+ choose_when=(
323
+ "Facts that change over time are central and plain extraction is not enough. "
324
+ "Needs FalkorDB or Neo4j and several model calls per memory."
325
+ ),
326
+ available=True,
327
+ enable=(
328
+ "Set ALBERT_GRAPH_BUILDER=graphiti with ALBERT_GRAPH_STORE=falkordb or neo4j.",
329
+ "Configure openai-compatible classification and embedding models.",
330
+ "Restart api and worker, then run albert-admin reindex-memories --all.",
331
+ ),
332
+ ),
333
+ }
334
+
335
+ _override: GraphStore | None = None
336
+ _instances: dict[str, GraphStore] = {}
337
+
338
+
339
+ def set_graph_store(store: GraphStore | None) -> None:
340
+ """Install a store for this process (tests, embedding); None restores the setting."""
341
+ global _override
342
+ _override = store
343
+
344
+
345
+ def get_graph_store() -> GraphStore:
346
+ if _override is not None:
347
+ return _override
348
+ from albert.config import get_settings
349
+
350
+ name = get_settings().graph_store
351
+ if name not in _instances:
352
+ if name == "postgres":
353
+ from albert.graph import PostgresGraphStore
354
+
355
+ _instances[name] = PostgresGraphStore()
356
+ elif name == "falkordb":
357
+ from albert.graph_cypher import FalkorDBGraphStore
358
+
359
+ settings = get_settings()
360
+ _instances[name] = FalkorDBGraphStore(
361
+ settings.falkordb_url, graph_name=settings.falkordb_graph
362
+ )
363
+ elif name == "neo4j":
364
+ from albert.graph_cypher import Neo4jGraphStore
365
+
366
+ settings = get_settings()
367
+ assert settings.neo4j_password is not None # enforced by Settings
368
+ _instances[name] = Neo4jGraphStore(
369
+ settings.neo4j_url,
370
+ user=settings.neo4j_user,
371
+ password=settings.neo4j_password.get_secret_value(),
372
+ database=settings.neo4j_database,
373
+ )
374
+ else: # the setting's validator refuses anything not shipped
375
+ raise RuntimeError(f"Graph store {name!r} is not available in this build")
376
+ return _instances[name]
@@ -0,0 +1,45 @@
1
+ {
2
+ "schema": "com.jiggai.albert.host-target",
3
+ "schema_version": 1,
4
+ "descriptor_version": "1.0.0",
5
+ "target_id": "claude-code",
6
+ "enabled": true,
7
+ "package": {
8
+ "distribution": "albert-memory",
9
+ "version": "0.4.0",
10
+ "artifact_provenance": "github-oidc-dsse+sha256"
11
+ },
12
+ "host": {
13
+ "family": "claude-code",
14
+ "tested": "2.1.312",
15
+ "supported": ">=2.1.78,<2.2.0"
16
+ },
17
+ "hooks": {
18
+ "fidelity": "reduced",
19
+ "present": ["session_start", "user_prompt", "pre_compaction", "run_complete", "session_end"],
20
+ "absent": ["reliable_failure_delivery"]
21
+ },
22
+ "install": {
23
+ "root": "~/.claude/albert",
24
+ "reload": ["claude", "plugin", "validate", "--strict"],
25
+ "uninstall": ["claude", "plugin", "uninstall", "albert-memory", "--scope", "user"]
26
+ },
27
+ "credentials": {
28
+ "acquisition": ["hidden_prompt", "private_stdin", "private_fd"],
29
+ "storage": "owned_file_0600",
30
+ "forbidden_surfaces": ["args", "ordinary_env", "host_config", "logs", "diagnostics", "artifacts"]
31
+ },
32
+ "ownership": {
33
+ "marker": "albert-memory",
34
+ "scope": "target-owned-tree-and-entry"
35
+ },
36
+ "lifecycle": {
37
+ "upgrade": true,
38
+ "rotate": true,
39
+ "revoke": true,
40
+ "rollback": true,
41
+ "direct_brain": true
42
+ },
43
+ "probes": ["host_config", "runtime", "brain_ready", "capture_recall"],
44
+ "capabilities": ["capture", "direct_brain", "recall", "reload", "revoke", "rollback", "rotate", "uninstall", "upgrade"]
45
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "schema": "com.jiggai.albert.host-target",
3
+ "schema_version": 1,
4
+ "descriptor_version": "1.0.0",
5
+ "target_id": "codex",
6
+ "enabled": true,
7
+ "package": {
8
+ "distribution": "albert-memory",
9
+ "version": "0.4.0",
10
+ "artifact_provenance": "github-oidc-dsse+sha256"
11
+ },
12
+ "host": {
13
+ "family": "codex",
14
+ "tested": "0.154.0",
15
+ "supported": ">=0.154.0,<0.155.0"
16
+ },
17
+ "hooks": {
18
+ "fidelity": "reduced",
19
+ "present": ["session_start", "user_prompt", "pre_compaction", "run_complete"],
20
+ "absent": ["failure", "session_end"]
21
+ },
22
+ "install": {
23
+ "root": "~/.codex/albert",
24
+ "reload": ["codex", "--version"],
25
+ "uninstall": ["albert-codex-lifecycle", "uninstall"]
26
+ },
27
+ "credentials": {
28
+ "acquisition": ["hidden_prompt", "private_stdin", "private_fd"],
29
+ "storage": "owned_file_0600",
30
+ "forbidden_surfaces": ["args", "ordinary_env", "host_config", "logs", "diagnostics", "artifacts"]
31
+ },
32
+ "ownership": {
33
+ "marker": "albert-memory",
34
+ "scope": "target-owned-tree-and-entry"
35
+ },
36
+ "lifecycle": {
37
+ "upgrade": true,
38
+ "rotate": true,
39
+ "revoke": true,
40
+ "rollback": true,
41
+ "direct_brain": true
42
+ },
43
+ "probes": ["host_config", "runtime", "brain_ready", "capture_recall"],
44
+ "capabilities": ["capture", "direct_brain", "recall", "reload", "revoke", "rollback", "rotate", "uninstall", "upgrade"]
45
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "schema": "com.jiggai.albert.host-target",
3
+ "schema_version": 1,
4
+ "descriptor_version": "1.0.0",
5
+ "target_id": "openclaw",
6
+ "enabled": true,
7
+ "package": {
8
+ "distribution": "albert-memory",
9
+ "version": "0.4.0",
10
+ "artifact_provenance": "github-oidc-dsse+sha256"
11
+ },
12
+ "host": {
13
+ "family": "openclaw",
14
+ "tested": "2026.9.6",
15
+ "supported": ">=2026.9.6,<2027.0.0"
16
+ },
17
+ "hooks": {
18
+ "fidelity": "full",
19
+ "present": ["session_start", "user_prompt", "pre_compaction", "run_complete", "session_end"],
20
+ "absent": []
21
+ },
22
+ "install": {
23
+ "root": "~/.openclaw/albert",
24
+ "reload": ["openclaw", "plugins", "reload", "albert-memory"],
25
+ "uninstall": ["openclaw", "plugins", "uninstall", "albert-memory", "--force"]
26
+ },
27
+ "credentials": {
28
+ "acquisition": ["hidden_prompt", "private_stdin", "private_fd"],
29
+ "storage": "owned_file_0600",
30
+ "forbidden_surfaces": ["args", "ordinary_env", "host_config", "logs", "diagnostics", "artifacts"]
31
+ },
32
+ "ownership": {
33
+ "marker": "albert-memory",
34
+ "scope": "target-owned-tree-and-entry"
35
+ },
36
+ "lifecycle": {
37
+ "upgrade": true,
38
+ "rotate": true,
39
+ "revoke": true,
40
+ "rollback": true,
41
+ "direct_brain": true
42
+ },
43
+ "probes": ["host_config", "runtime", "brain_ready", "capture_recall"],
44
+ "capabilities": ["capture", "direct_brain", "recall", "reload", "revoke", "rollback", "rotate", "uninstall", "upgrade"]
45
+ }