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
@@ -0,0 +1,170 @@
1
+ """
2
+ ALMA Logging Level Guidelines.
3
+
4
+ This module documents the standardized logging levels for ALMA.
5
+ All modules should follow these guidelines for consistent logging.
6
+
7
+ Logging Level Standards
8
+ =======================
9
+
10
+ DEBUG
11
+ -----
12
+ Use for detailed diagnostic information useful during development
13
+ and debugging. This level should NOT be enabled in production under
14
+ normal circumstances.
15
+
16
+ Examples:
17
+ - Cache hits/misses for individual queries
18
+ - Internal state changes (e.g., "Updated work item: {item_id}")
19
+ - Function entry/exit with parameters
20
+ - Detailed timing breakdowns
21
+ - Query/embedding details
22
+
23
+ INFO
24
+ ----
25
+ Use for high-level operation completion and significant lifecycle events.
26
+ These logs confirm that things are working as expected.
27
+
28
+ Examples:
29
+ - Service startup/shutdown
30
+ - Memory retrieval/learning operations completed (with summary metrics)
31
+ - Scheduled job execution completed
32
+ - Configuration loaded successfully
33
+ - Database/storage connections established
34
+ - Batch operations completed with counts
35
+
36
+ WARNING
37
+ -------
38
+ Use for recoverable issues that may indicate problems but don't prevent
39
+ operation. The system continues to function but something unexpected happened.
40
+
41
+ Examples:
42
+ - Agent has no defined scope, using defaults
43
+ - Optional feature unavailable (e.g., "aiohttp not installed")
44
+ - Failed to retrieve optional data (e.g., git commands timeout)
45
+ - Near-quota conditions
46
+ - Deprecated feature usage
47
+ - Retry attempts
48
+ - Missing optional configuration
49
+
50
+ ERROR
51
+ -----
52
+ Use for failures that need attention. These indicate that an operation
53
+ failed and likely requires investigation or intervention.
54
+
55
+ Examples:
56
+ - Storage operation failures
57
+ - Failed to process required data
58
+ - Authentication/authorization failures
59
+ - Configuration errors preventing operation
60
+ - Unrecoverable API errors
61
+ - Data corruption detected
62
+ - Resource exhaustion
63
+
64
+ CRITICAL
65
+ --------
66
+ Use for severe failures that may cause application shutdown or
67
+ complete loss of functionality. These require immediate attention.
68
+
69
+ Examples:
70
+ - Database connection permanently lost
71
+ - Critical configuration missing
72
+ - Unrecoverable system state
73
+ - Security breach detected
74
+
75
+ Implementation Notes
76
+ ====================
77
+
78
+ 1. Logger Initialization:
79
+ - Use standard logging: logger = logging.getLogger(__name__)
80
+ - For structured logging features, also use: structured_logger = get_logger(__name__)
81
+
82
+ 2. Message Format:
83
+ - Start with action or subject (e.g., "Memory retrieval completed", "Failed to save heuristic")
84
+ - Include relevant context as structured fields
85
+ - Keep messages concise but informative
86
+
87
+ 3. Structured Logging:
88
+ - Use structured_logger for operations that benefit from structured fields
89
+ - Pass context as keyword arguments for JSON serialization
90
+ - Example: structured_logger.info("Retrieved memories", agent=agent, count=count)
91
+
92
+ 4. Exception Logging:
93
+ - Use logger.error(..., exc_info=True) or logger.exception() for exceptions
94
+ - Include context about what operation was being attempted
95
+
96
+ 5. Performance Logging:
97
+ - Log duration for operations > 100ms at INFO level
98
+ - Log internal operation timing at DEBUG level
99
+
100
+ Examples
101
+ ========
102
+
103
+ # DEBUG - Internal diagnostics
104
+ logger.debug(f"Cache hit for query: {query[:50]}...")
105
+ logger.debug(f"Updated heuristic: {heuristic_id}")
106
+ logger.debug(f"Saved outcome: {outcome.id}")
107
+
108
+ # INFO - Operation completions
109
+ logger.info(f"Memory retrieval completed: {count} items in {duration_ms}ms")
110
+ logger.info(f"Cleanup scheduler started (interval: {interval}s)")
111
+ logger.info("ChromaDB storage closed")
112
+
113
+ # WARNING - Recoverable issues
114
+ logger.warning(f"Agent '{agent}' has no defined scope, using defaults")
115
+ logger.warning("aiohttp not installed - webhook delivery unavailable")
116
+ logger.warning(f"Failed to retrieve memories: {e}")
117
+
118
+ # ERROR - Failures requiring attention
119
+ logger.error(f"Failed to save heuristic {heuristic_id}: {e}")
120
+ logger.error(f"Redis connection error: {e}")
121
+ logger.error("Config file not found, cannot proceed")
122
+ """
123
+
124
+ # Log level constants for programmatic use
125
+ import logging
126
+
127
+ # Map of operation types to recommended log levels
128
+ OPERATION_LOG_LEVELS = {
129
+ # Storage operations
130
+ "save_success": logging.DEBUG,
131
+ "save_failure": logging.ERROR,
132
+ "batch_save_success": logging.DEBUG,
133
+ "delete_success": logging.DEBUG,
134
+ "delete_failure": logging.ERROR,
135
+ # Retrieval operations
136
+ "cache_hit": logging.DEBUG,
137
+ "cache_miss": logging.DEBUG,
138
+ "cache_invalidate": logging.DEBUG,
139
+ "retrieval_complete": logging.INFO,
140
+ # Learning operations
141
+ "learn_complete": logging.INFO,
142
+ "heuristic_updated": logging.DEBUG,
143
+ # Lifecycle events
144
+ "service_start": logging.INFO,
145
+ "service_stop": logging.INFO,
146
+ "connection_established": logging.INFO,
147
+ "config_loaded": logging.INFO,
148
+ # Warnings
149
+ "missing_scope": logging.WARNING,
150
+ "optional_feature_unavailable": logging.WARNING,
151
+ "retry_attempt": logging.WARNING,
152
+ "deprecation": logging.WARNING,
153
+ # Errors
154
+ "operation_failure": logging.ERROR,
155
+ "connection_failure": logging.ERROR,
156
+ "validation_failure": logging.ERROR,
157
+ }
158
+
159
+
160
+ def get_recommended_level(operation: str) -> int:
161
+ """
162
+ Get the recommended log level for a given operation type.
163
+
164
+ Args:
165
+ operation: The operation type (e.g., "save_success", "cache_hit")
166
+
167
+ Returns:
168
+ Logging level constant (e.g., logging.DEBUG, logging.INFO)
169
+ """
170
+ return OPERATION_LOG_LEVELS.get(operation, logging.INFO)