alma-memory 0.5.1__py3-none-any.whl → 0.7.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 (111) hide show
  1. alma/__init__.py +296 -226
  2. alma/compression/__init__.py +33 -0
  3. alma/compression/pipeline.py +980 -0
  4. alma/confidence/__init__.py +47 -47
  5. alma/confidence/engine.py +540 -540
  6. alma/confidence/types.py +351 -351
  7. alma/config/loader.py +157 -157
  8. alma/consolidation/__init__.py +23 -23
  9. alma/consolidation/engine.py +678 -678
  10. alma/consolidation/prompts.py +84 -84
  11. alma/core.py +1189 -430
  12. alma/domains/__init__.py +30 -30
  13. alma/domains/factory.py +359 -359
  14. alma/domains/schemas.py +448 -448
  15. alma/domains/types.py +272 -272
  16. alma/events/__init__.py +75 -75
  17. alma/events/emitter.py +285 -284
  18. alma/events/storage_mixin.py +246 -246
  19. alma/events/types.py +126 -126
  20. alma/events/webhook.py +425 -425
  21. alma/exceptions.py +49 -49
  22. alma/extraction/__init__.py +31 -31
  23. alma/extraction/auto_learner.py +265 -265
  24. alma/extraction/extractor.py +420 -420
  25. alma/graph/__init__.py +106 -106
  26. alma/graph/backends/__init__.py +32 -32
  27. alma/graph/backends/kuzu.py +624 -624
  28. alma/graph/backends/memgraph.py +432 -432
  29. alma/graph/backends/memory.py +236 -236
  30. alma/graph/backends/neo4j.py +417 -417
  31. alma/graph/base.py +159 -159
  32. alma/graph/extraction.py +198 -198
  33. alma/graph/store.py +860 -860
  34. alma/harness/__init__.py +35 -35
  35. alma/harness/base.py +386 -386
  36. alma/harness/domains.py +705 -705
  37. alma/initializer/__init__.py +37 -37
  38. alma/initializer/initializer.py +418 -418
  39. alma/initializer/types.py +250 -250
  40. alma/integration/__init__.py +62 -62
  41. alma/integration/claude_agents.py +444 -444
  42. alma/integration/helena.py +423 -423
  43. alma/integration/victor.py +471 -471
  44. alma/learning/__init__.py +101 -86
  45. alma/learning/decay.py +878 -0
  46. alma/learning/forgetting.py +1446 -1446
  47. alma/learning/heuristic_extractor.py +390 -390
  48. alma/learning/protocols.py +374 -374
  49. alma/learning/validation.py +346 -346
  50. alma/mcp/__init__.py +123 -45
  51. alma/mcp/__main__.py +156 -156
  52. alma/mcp/resources.py +122 -122
  53. alma/mcp/server.py +955 -591
  54. alma/mcp/tools.py +3254 -509
  55. alma/observability/__init__.py +91 -84
  56. alma/observability/config.py +302 -302
  57. alma/observability/guidelines.py +170 -0
  58. alma/observability/logging.py +424 -424
  59. alma/observability/metrics.py +583 -583
  60. alma/observability/tracing.py +440 -440
  61. alma/progress/__init__.py +21 -21
  62. alma/progress/tracker.py +607 -607
  63. alma/progress/types.py +250 -250
  64. alma/retrieval/__init__.py +134 -53
  65. alma/retrieval/budget.py +525 -0
  66. alma/retrieval/cache.py +1304 -1061
  67. alma/retrieval/embeddings.py +202 -202
  68. alma/retrieval/engine.py +850 -427
  69. alma/retrieval/modes.py +365 -0
  70. alma/retrieval/progressive.py +560 -0
  71. alma/retrieval/scoring.py +344 -344
  72. alma/retrieval/trust_scoring.py +637 -0
  73. alma/retrieval/verification.py +797 -0
  74. alma/session/__init__.py +19 -19
  75. alma/session/manager.py +442 -399
  76. alma/session/types.py +288 -288
  77. alma/storage/__init__.py +101 -90
  78. alma/storage/archive.py +233 -0
  79. alma/storage/azure_cosmos.py +1259 -1259
  80. alma/storage/base.py +1083 -583
  81. alma/storage/chroma.py +1443 -1443
  82. alma/storage/constants.py +103 -103
  83. alma/storage/file_based.py +614 -614
  84. alma/storage/migrations/__init__.py +21 -21
  85. alma/storage/migrations/base.py +321 -321
  86. alma/storage/migrations/runner.py +323 -323
  87. alma/storage/migrations/version_stores.py +337 -337
  88. alma/storage/migrations/versions/__init__.py +11 -11
  89. alma/storage/migrations/versions/v1_0_0.py +373 -373
  90. alma/storage/migrations/versions/v1_1_0_workflow_context.py +551 -0
  91. alma/storage/pinecone.py +1080 -1080
  92. alma/storage/postgresql.py +1948 -1559
  93. alma/storage/qdrant.py +1306 -1306
  94. alma/storage/sqlite_local.py +3041 -1457
  95. alma/testing/__init__.py +46 -46
  96. alma/testing/factories.py +301 -301
  97. alma/testing/mocks.py +389 -389
  98. alma/types.py +292 -264
  99. alma/utils/__init__.py +19 -0
  100. alma/utils/tokenizer.py +521 -0
  101. alma/workflow/__init__.py +83 -0
  102. alma/workflow/artifacts.py +170 -0
  103. alma/workflow/checkpoint.py +311 -0
  104. alma/workflow/context.py +228 -0
  105. alma/workflow/outcomes.py +189 -0
  106. alma/workflow/reducers.py +393 -0
  107. {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/METADATA +210 -72
  108. alma_memory-0.7.0.dist-info/RECORD +112 -0
  109. alma_memory-0.5.1.dist-info/RECORD +0 -93
  110. {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/WHEEL +0 -0
  111. {alma_memory-0.5.1.dist-info → alma_memory-0.7.0.dist-info}/top_level.txt +0 -0
alma/graph/base.py CHANGED
@@ -1,159 +1,159 @@
1
- """
2
- ALMA Graph Memory - Abstract Backend Interface.
3
-
4
- Defines the abstract base class for graph database backends,
5
- enabling pluggable graph storage implementations.
6
- """
7
-
8
- from abc import ABC, abstractmethod
9
- from typing import List, Optional
10
-
11
- from alma.graph.store import Entity, Relationship
12
-
13
-
14
- class GraphBackend(ABC):
15
- """
16
- Abstract base class for graph database backends.
17
-
18
- This interface defines the contract that all graph storage implementations
19
- must follow, enabling ALMA to work with different graph databases like
20
- Neo4j, Amazon Neptune, or in-memory stores.
21
- """
22
-
23
- @abstractmethod
24
- def add_entity(self, entity: Entity) -> str:
25
- """
26
- Add or update an entity in the graph.
27
-
28
- Args:
29
- entity: The entity to add or update.
30
-
31
- Returns:
32
- The entity ID.
33
- """
34
- pass
35
-
36
- @abstractmethod
37
- def add_relationship(self, relationship: Relationship) -> str:
38
- """
39
- Add or update a relationship between entities.
40
-
41
- Args:
42
- relationship: The relationship to add or update.
43
-
44
- Returns:
45
- The relationship ID.
46
- """
47
- pass
48
-
49
- @abstractmethod
50
- def get_entity(self, entity_id: str) -> Optional[Entity]:
51
- """
52
- Get an entity by its ID.
53
-
54
- Args:
55
- entity_id: The unique identifier of the entity.
56
-
57
- Returns:
58
- The entity if found, None otherwise.
59
- """
60
- pass
61
-
62
- @abstractmethod
63
- def get_entities(
64
- self,
65
- entity_type: Optional[str] = None,
66
- project_id: Optional[str] = None,
67
- agent: Optional[str] = None,
68
- limit: int = 100,
69
- ) -> List[Entity]:
70
- """
71
- Get entities with optional filtering.
72
-
73
- Args:
74
- entity_type: Filter by entity type (person, organization, etc.).
75
- project_id: Filter by project ID.
76
- agent: Filter by agent name.
77
- limit: Maximum number of entities to return.
78
-
79
- Returns:
80
- List of matching entities.
81
- """
82
- pass
83
-
84
- @abstractmethod
85
- def get_relationships(self, entity_id: str) -> List[Relationship]:
86
- """
87
- Get all relationships for an entity.
88
-
89
- Args:
90
- entity_id: The entity ID to get relationships for.
91
-
92
- Returns:
93
- List of relationships where the entity is source or target.
94
- """
95
- pass
96
-
97
- @abstractmethod
98
- def search_entities(
99
- self,
100
- query: str,
101
- embedding: Optional[List[float]] = None,
102
- top_k: int = 10,
103
- ) -> List[Entity]:
104
- """
105
- Search for entities by name or using vector similarity.
106
-
107
- Args:
108
- query: Text query to search for in entity names.
109
- embedding: Optional embedding vector for semantic search.
110
- top_k: Maximum number of results to return.
111
-
112
- Returns:
113
- List of matching entities, ordered by relevance.
114
- """
115
- pass
116
-
117
- @abstractmethod
118
- def delete_entity(self, entity_id: str) -> bool:
119
- """
120
- Delete an entity and all its relationships.
121
-
122
- Args:
123
- entity_id: The entity ID to delete.
124
-
125
- Returns:
126
- True if the entity was deleted, False if not found.
127
- """
128
- pass
129
-
130
- @abstractmethod
131
- def delete_relationship(self, relationship_id: str) -> bool:
132
- """
133
- Delete a specific relationship.
134
-
135
- Args:
136
- relationship_id: The relationship ID to delete.
137
-
138
- Returns:
139
- True if the relationship was deleted, False if not found.
140
- """
141
- pass
142
-
143
- @abstractmethod
144
- def close(self) -> None:
145
- """
146
- Close the backend connection and release resources.
147
-
148
- Should be called when the backend is no longer needed.
149
- """
150
- pass
151
-
152
- def __enter__(self):
153
- """Context manager entry."""
154
- return self
155
-
156
- def __exit__(self, exc_type, exc_val, exc_tb):
157
- """Context manager exit - ensures close is called."""
158
- self.close()
159
- return False
1
+ """
2
+ ALMA Graph Memory - Abstract Backend Interface.
3
+
4
+ Defines the abstract base class for graph database backends,
5
+ enabling pluggable graph storage implementations.
6
+ """
7
+
8
+ from abc import ABC, abstractmethod
9
+ from typing import List, Optional
10
+
11
+ from alma.graph.store import Entity, Relationship
12
+
13
+
14
+ class GraphBackend(ABC):
15
+ """
16
+ Abstract base class for graph database backends.
17
+
18
+ This interface defines the contract that all graph storage implementations
19
+ must follow, enabling ALMA to work with different graph databases like
20
+ Neo4j, Amazon Neptune, or in-memory stores.
21
+ """
22
+
23
+ @abstractmethod
24
+ def add_entity(self, entity: Entity) -> str:
25
+ """
26
+ Add or update an entity in the graph.
27
+
28
+ Args:
29
+ entity: The entity to add or update.
30
+
31
+ Returns:
32
+ The entity ID.
33
+ """
34
+ pass
35
+
36
+ @abstractmethod
37
+ def add_relationship(self, relationship: Relationship) -> str:
38
+ """
39
+ Add or update a relationship between entities.
40
+
41
+ Args:
42
+ relationship: The relationship to add or update.
43
+
44
+ Returns:
45
+ The relationship ID.
46
+ """
47
+ pass
48
+
49
+ @abstractmethod
50
+ def get_entity(self, entity_id: str) -> Optional[Entity]:
51
+ """
52
+ Get an entity by its ID.
53
+
54
+ Args:
55
+ entity_id: The unique identifier of the entity.
56
+
57
+ Returns:
58
+ The entity if found, None otherwise.
59
+ """
60
+ pass
61
+
62
+ @abstractmethod
63
+ def get_entities(
64
+ self,
65
+ entity_type: Optional[str] = None,
66
+ project_id: Optional[str] = None,
67
+ agent: Optional[str] = None,
68
+ limit: int = 100,
69
+ ) -> List[Entity]:
70
+ """
71
+ Get entities with optional filtering.
72
+
73
+ Args:
74
+ entity_type: Filter by entity type (person, organization, etc.).
75
+ project_id: Filter by project ID.
76
+ agent: Filter by agent name.
77
+ limit: Maximum number of entities to return.
78
+
79
+ Returns:
80
+ List of matching entities.
81
+ """
82
+ pass
83
+
84
+ @abstractmethod
85
+ def get_relationships(self, entity_id: str) -> List[Relationship]:
86
+ """
87
+ Get all relationships for an entity.
88
+
89
+ Args:
90
+ entity_id: The entity ID to get relationships for.
91
+
92
+ Returns:
93
+ List of relationships where the entity is source or target.
94
+ """
95
+ pass
96
+
97
+ @abstractmethod
98
+ def search_entities(
99
+ self,
100
+ query: str,
101
+ embedding: Optional[List[float]] = None,
102
+ top_k: int = 10,
103
+ ) -> List[Entity]:
104
+ """
105
+ Search for entities by name or using vector similarity.
106
+
107
+ Args:
108
+ query: Text query to search for in entity names.
109
+ embedding: Optional embedding vector for semantic search.
110
+ top_k: Maximum number of results to return.
111
+
112
+ Returns:
113
+ List of matching entities, ordered by relevance.
114
+ """
115
+ pass
116
+
117
+ @abstractmethod
118
+ def delete_entity(self, entity_id: str) -> bool:
119
+ """
120
+ Delete an entity and all its relationships.
121
+
122
+ Args:
123
+ entity_id: The entity ID to delete.
124
+
125
+ Returns:
126
+ True if the entity was deleted, False if not found.
127
+ """
128
+ pass
129
+
130
+ @abstractmethod
131
+ def delete_relationship(self, relationship_id: str) -> bool:
132
+ """
133
+ Delete a specific relationship.
134
+
135
+ Args:
136
+ relationship_id: The relationship ID to delete.
137
+
138
+ Returns:
139
+ True if the relationship was deleted, False if not found.
140
+ """
141
+ pass
142
+
143
+ @abstractmethod
144
+ def close(self) -> None:
145
+ """
146
+ Close the backend connection and release resources.
147
+
148
+ Should be called when the backend is no longer needed.
149
+ """
150
+ pass
151
+
152
+ def __enter__(self):
153
+ """Context manager entry."""
154
+ return self
155
+
156
+ def __exit__(self, exc_type, exc_val, exc_tb):
157
+ """Context manager exit - ensures close is called."""
158
+ self.close()
159
+ return False