superlocalmemory 2.7.6 → 2.8.0

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 (170) hide show
  1. package/CHANGELOG.md +120 -155
  2. package/README.md +115 -89
  3. package/api_server.py +2 -12
  4. package/docs/PATTERN-LEARNING.md +64 -199
  5. package/docs/example_graph_usage.py +4 -6
  6. package/install.sh +59 -0
  7. package/mcp_server.py +83 -7
  8. package/package.json +1 -8
  9. package/scripts/generate-thumbnails.py +3 -5
  10. package/skills/slm-build-graph/SKILL.md +1 -1
  11. package/skills/slm-list-recent/SKILL.md +1 -1
  12. package/skills/slm-recall/SKILL.md +1 -1
  13. package/skills/slm-remember/SKILL.md +1 -1
  14. package/skills/slm-show-patterns/SKILL.md +1 -1
  15. package/skills/slm-status/SKILL.md +1 -1
  16. package/skills/slm-switch-profile/SKILL.md +1 -1
  17. package/src/agent_registry.py +7 -18
  18. package/src/auth_middleware.py +3 -5
  19. package/src/auto_backup.py +3 -7
  20. package/src/behavioral/__init__.py +49 -0
  21. package/src/behavioral/behavioral_listener.py +203 -0
  22. package/src/behavioral/behavioral_patterns.py +275 -0
  23. package/src/behavioral/cross_project_transfer.py +206 -0
  24. package/src/behavioral/outcome_inference.py +194 -0
  25. package/src/behavioral/outcome_tracker.py +193 -0
  26. package/src/behavioral/tests/__init__.py +4 -0
  27. package/src/behavioral/tests/test_behavioral_integration.py +108 -0
  28. package/src/behavioral/tests/test_behavioral_patterns.py +150 -0
  29. package/src/behavioral/tests/test_cross_project_transfer.py +142 -0
  30. package/src/behavioral/tests/test_mcp_behavioral.py +139 -0
  31. package/src/behavioral/tests/test_mcp_report_outcome.py +117 -0
  32. package/src/behavioral/tests/test_outcome_inference.py +107 -0
  33. package/src/behavioral/tests/test_outcome_tracker.py +96 -0
  34. package/src/cache_manager.py +4 -6
  35. package/src/compliance/__init__.py +48 -0
  36. package/src/compliance/abac_engine.py +149 -0
  37. package/src/compliance/abac_middleware.py +116 -0
  38. package/src/compliance/audit_db.py +215 -0
  39. package/src/compliance/audit_logger.py +148 -0
  40. package/src/compliance/retention_manager.py +289 -0
  41. package/src/compliance/retention_scheduler.py +186 -0
  42. package/src/compliance/tests/__init__.py +4 -0
  43. package/src/compliance/tests/test_abac_enforcement.py +95 -0
  44. package/src/compliance/tests/test_abac_engine.py +124 -0
  45. package/src/compliance/tests/test_abac_mcp_integration.py +118 -0
  46. package/src/compliance/tests/test_audit_db.py +123 -0
  47. package/src/compliance/tests/test_audit_logger.py +98 -0
  48. package/src/compliance/tests/test_mcp_audit.py +128 -0
  49. package/src/compliance/tests/test_mcp_retention_policy.py +125 -0
  50. package/src/compliance/tests/test_retention_manager.py +131 -0
  51. package/src/compliance/tests/test_retention_scheduler.py +99 -0
  52. package/src/db_connection_manager.py +2 -12
  53. package/src/embedding_engine.py +61 -669
  54. package/src/embeddings/__init__.py +47 -0
  55. package/src/embeddings/cache.py +70 -0
  56. package/src/embeddings/cli.py +113 -0
  57. package/src/embeddings/constants.py +47 -0
  58. package/src/embeddings/database.py +91 -0
  59. package/src/embeddings/engine.py +247 -0
  60. package/src/embeddings/model_loader.py +145 -0
  61. package/src/event_bus.py +3 -13
  62. package/src/graph/__init__.py +36 -0
  63. package/src/graph/build_helpers.py +74 -0
  64. package/src/graph/cli.py +87 -0
  65. package/src/graph/cluster_builder.py +188 -0
  66. package/src/graph/cluster_summary.py +148 -0
  67. package/src/graph/constants.py +47 -0
  68. package/src/graph/edge_builder.py +162 -0
  69. package/src/graph/entity_extractor.py +95 -0
  70. package/src/graph/graph_core.py +226 -0
  71. package/src/graph/graph_search.py +231 -0
  72. package/src/graph/hierarchical.py +207 -0
  73. package/src/graph/schema.py +99 -0
  74. package/src/graph_engine.py +45 -1451
  75. package/src/hnsw_index.py +3 -7
  76. package/src/hybrid_search.py +36 -683
  77. package/src/learning/__init__.py +27 -12
  78. package/src/learning/adaptive_ranker.py +50 -12
  79. package/src/learning/cross_project_aggregator.py +2 -12
  80. package/src/learning/engagement_tracker.py +2 -12
  81. package/src/learning/feature_extractor.py +175 -43
  82. package/src/learning/feedback_collector.py +7 -12
  83. package/src/learning/learning_db.py +180 -12
  84. package/src/learning/project_context_manager.py +2 -12
  85. package/src/learning/source_quality_scorer.py +2 -12
  86. package/src/learning/synthetic_bootstrap.py +2 -12
  87. package/src/learning/tests/__init__.py +2 -0
  88. package/src/learning/tests/test_adaptive_ranker.py +2 -6
  89. package/src/learning/tests/test_adaptive_ranker_v28.py +60 -0
  90. package/src/learning/tests/test_aggregator.py +2 -6
  91. package/src/learning/tests/test_auto_retrain_v28.py +35 -0
  92. package/src/learning/tests/test_e2e_ranking_v28.py +82 -0
  93. package/src/learning/tests/test_feature_extractor_v28.py +93 -0
  94. package/src/learning/tests/test_feedback_collector.py +2 -6
  95. package/src/learning/tests/test_learning_db.py +2 -6
  96. package/src/learning/tests/test_learning_db_v28.py +110 -0
  97. package/src/learning/tests/test_learning_init_v28.py +48 -0
  98. package/src/learning/tests/test_outcome_signals.py +48 -0
  99. package/src/learning/tests/test_project_context.py +2 -6
  100. package/src/learning/tests/test_schema_migration.py +319 -0
  101. package/src/learning/tests/test_signal_inference.py +11 -13
  102. package/src/learning/tests/test_source_quality.py +2 -6
  103. package/src/learning/tests/test_synthetic_bootstrap.py +3 -7
  104. package/src/learning/tests/test_workflow_miner.py +2 -6
  105. package/src/learning/workflow_pattern_miner.py +2 -12
  106. package/src/lifecycle/__init__.py +54 -0
  107. package/src/lifecycle/bounded_growth.py +239 -0
  108. package/src/lifecycle/compaction_engine.py +226 -0
  109. package/src/lifecycle/lifecycle_engine.py +302 -0
  110. package/src/lifecycle/lifecycle_evaluator.py +225 -0
  111. package/src/lifecycle/lifecycle_scheduler.py +130 -0
  112. package/src/lifecycle/retention_policy.py +285 -0
  113. package/src/lifecycle/tests/__init__.py +4 -0
  114. package/src/lifecycle/tests/test_bounded_growth.py +193 -0
  115. package/src/lifecycle/tests/test_compaction.py +179 -0
  116. package/src/lifecycle/tests/test_lifecycle_engine.py +137 -0
  117. package/src/lifecycle/tests/test_lifecycle_evaluation.py +177 -0
  118. package/src/lifecycle/tests/test_lifecycle_scheduler.py +127 -0
  119. package/src/lifecycle/tests/test_lifecycle_search.py +109 -0
  120. package/src/lifecycle/tests/test_mcp_compact.py +149 -0
  121. package/src/lifecycle/tests/test_mcp_lifecycle_status.py +114 -0
  122. package/src/lifecycle/tests/test_retention_policy.py +162 -0
  123. package/src/mcp_tools_v28.py +280 -0
  124. package/src/memory-profiles.py +2 -12
  125. package/src/memory-reset.py +2 -12
  126. package/src/memory_compression.py +2 -12
  127. package/src/memory_store_v2.py +76 -20
  128. package/src/migrate_v1_to_v2.py +2 -12
  129. package/src/pattern_learner.py +29 -975
  130. package/src/patterns/__init__.py +24 -0
  131. package/src/patterns/analyzers.py +247 -0
  132. package/src/patterns/learner.py +267 -0
  133. package/src/patterns/scoring.py +167 -0
  134. package/src/patterns/store.py +223 -0
  135. package/src/patterns/terminology.py +138 -0
  136. package/src/provenance_tracker.py +4 -14
  137. package/src/query_optimizer.py +4 -6
  138. package/src/rate_limiter.py +2 -6
  139. package/src/search/__init__.py +20 -0
  140. package/src/search/cli.py +77 -0
  141. package/src/search/constants.py +26 -0
  142. package/src/search/engine.py +239 -0
  143. package/src/search/fusion.py +122 -0
  144. package/src/search/index_loader.py +112 -0
  145. package/src/search/methods.py +162 -0
  146. package/src/search_engine_v2.py +4 -6
  147. package/src/setup_validator.py +7 -13
  148. package/src/subscription_manager.py +2 -12
  149. package/src/tree/__init__.py +59 -0
  150. package/src/tree/builder.py +183 -0
  151. package/src/tree/nodes.py +196 -0
  152. package/src/tree/queries.py +252 -0
  153. package/src/tree/schema.py +76 -0
  154. package/src/tree_manager.py +10 -711
  155. package/src/trust/__init__.py +45 -0
  156. package/src/trust/constants.py +66 -0
  157. package/src/trust/queries.py +157 -0
  158. package/src/trust/schema.py +95 -0
  159. package/src/trust/scorer.py +299 -0
  160. package/src/trust/signals.py +95 -0
  161. package/src/trust_scorer.py +39 -697
  162. package/src/webhook_dispatcher.py +2 -12
  163. package/ui/app.js +1 -1
  164. package/ui/js/agents.js +1 -1
  165. package/ui_server.py +2 -14
  166. package/ATTRIBUTION.md +0 -140
  167. package/docs/ARCHITECTURE-V2.5.md +0 -190
  168. package/docs/GRAPH-ENGINE.md +0 -503
  169. package/docs/architecture-diagram.drawio +0 -405
  170. package/docs/plans/2026-02-13-benchmark-suite.md +0 -1349
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- """
3
- SuperLocalMemory V2 - Learning System (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
14
4
  """
15
5
  Learning System — Feature detection and graceful import.
16
6
 
@@ -180,6 +170,31 @@ def get_status() -> dict:
180
170
  except Exception:
181
171
  status["learning_db_stats"] = None
182
172
 
173
+ # v2.8 engine status (lifecycle, behavioral, compliance)
174
+ v28_engines = {}
175
+ try:
176
+ from lifecycle import get_status as lifecycle_status
177
+ ls = lifecycle_status()
178
+ v28_engines["lifecycle"] = {"available": ls.get("lifecycle_available", False), "detail": ls}
179
+ except (ImportError, Exception):
180
+ v28_engines["lifecycle"] = {"available": False, "detail": None}
181
+
182
+ try:
183
+ from behavioral import get_status as behavioral_status
184
+ bs = behavioral_status()
185
+ v28_engines["behavioral"] = {"available": bs.get("behavioral_available", False), "detail": bs}
186
+ except (ImportError, Exception):
187
+ v28_engines["behavioral"] = {"available": False, "detail": None}
188
+
189
+ try:
190
+ from compliance import get_status as compliance_status
191
+ cs = compliance_status()
192
+ v28_engines["compliance"] = {"available": cs.get("compliance_available", False), "detail": cs}
193
+ except (ImportError, Exception):
194
+ v28_engines["compliance"] = {"available": False, "detail": None}
195
+
196
+ status["v28_engines"] = v28_engines
197
+
183
198
  return status
184
199
 
185
200
 
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- """
3
- SuperLocalMemory V2 - Adaptive Ranker (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
14
4
  """
15
5
  AdaptiveRanker — Three-phase adaptive re-ranking engine.
16
6
 
@@ -105,6 +95,16 @@ _RULE_BOOST = {
105
95
  'recency_penalty_max': 0.8, # Old memory (> 365 days)
106
96
  'high_importance': 1.15, # Importance >= 8
107
97
  'high_access': 1.1, # Accessed 5+ times
98
+ # v2.8: Lifecycle + behavioral boosts
99
+ 'lifecycle_active': 1.0,
100
+ 'lifecycle_warm': 0.85,
101
+ 'lifecycle_cold': 0.6,
102
+ 'outcome_success_high': 1.3,
103
+ 'outcome_failure_high': 0.7,
104
+ 'behavioral_match_strong': 1.25,
105
+ 'cross_project_boost': 1.15,
106
+ 'high_trust_creator': 1.1,
107
+ 'low_trust_creator': 0.8,
108
108
  }
109
109
 
110
110
  # LightGBM training parameters — tuned for small, personal datasets
@@ -432,6 +432,44 @@ class AdaptiveRanker:
432
432
  elif avg_signal < 0.3 and avg_signal > 0.0:
433
433
  boost *= 0.85 # Penalize memories with negative feedback
434
434
 
435
+ # Feature [12]: lifecycle_state (v2.8)
436
+ if len(features) > 12:
437
+ lifecycle_state = features[12]
438
+ if lifecycle_state >= 0.9:
439
+ boost *= _RULE_BOOST.get('lifecycle_active', 1.0)
440
+ elif lifecycle_state >= 0.6:
441
+ boost *= _RULE_BOOST.get('lifecycle_warm', 0.85)
442
+ elif lifecycle_state >= 0.3:
443
+ boost *= _RULE_BOOST.get('lifecycle_cold', 0.6)
444
+
445
+ # Feature [13]: outcome_success_rate (v2.8)
446
+ if len(features) > 13:
447
+ success_rate = features[13]
448
+ if success_rate >= 0.8:
449
+ boost *= _RULE_BOOST.get('outcome_success_high', 1.3)
450
+ elif success_rate <= 0.2:
451
+ boost *= _RULE_BOOST.get('outcome_failure_high', 0.7)
452
+
453
+ # Feature [15]: behavioral_match (v2.8)
454
+ if len(features) > 15:
455
+ behavioral = features[15]
456
+ if behavioral >= 0.7:
457
+ boost *= _RULE_BOOST.get('behavioral_match_strong', 1.25)
458
+
459
+ # Feature [16]: cross_project_score (v2.8)
460
+ if len(features) > 16:
461
+ cross_project = features[16]
462
+ if cross_project >= 0.5:
463
+ boost *= _RULE_BOOST.get('cross_project_boost', 1.15)
464
+
465
+ # Feature [18]: trust_at_creation (v2.8)
466
+ if len(features) > 18:
467
+ trust = features[18]
468
+ if trust >= 0.9:
469
+ boost *= _RULE_BOOST.get('high_trust_creator', 1.1)
470
+ elif trust <= 0.3:
471
+ boost *= _RULE_BOOST.get('low_trust_creator', 0.8)
472
+
435
473
  # Apply boost to score
436
474
  result['score'] = base_score * boost
437
475
 
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- """
3
- SuperLocalMemory V2 - Cross-Project Aggregator (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
14
4
  """
15
5
  CrossProjectAggregator — Layer 1: Transferable Tech Preferences.
16
6
 
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- """
3
- SuperLocalMemory V2 - Engagement Tracker (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
14
4
  """
15
5
  EngagementTracker — Local-only engagement metrics.
16
6
 
@@ -1,36 +1,34 @@
1
1
  #!/usr/bin/env python3
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
2
4
  """
3
- SuperLocalMemory V2 - Feature Extractor (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
14
- """
15
- FeatureExtractor — Extracts 12-dimensional feature vectors for candidate memories.
5
+ FeatureExtractor Extracts 20-dimensional feature vectors for candidate memories.
16
6
 
17
7
  Each memory retrieved during recall gets a feature vector that feeds into
18
8
  the AdaptiveRanker. In Phase 1 (rule-based), features drive boosting weights.
19
9
  In Phase 2 (ML), features become LightGBM input columns.
20
10
 
21
- Feature Vector (12 dimensions):
22
- [0] bm25_score — Existing retrieval score from search results
23
- [1] tfidf_score — TF-IDF cosine similarity from search results
24
- [2] tech_match — Does memory match user's tech preferences?
25
- [3] project_match — Is memory from the current project?
26
- [4] workflow_fit — Does memory fit current workflow phase?
27
- [5] source_quality — Quality score of the source that created this memory
28
- [6] importance_norm — Normalized importance (importance / 10.0)
29
- [7] recency_score — Exponential decay based on age (180-day half-life)
30
- [8] access_frequency — How often this memory was accessed (capped at 1.0)
31
- [9] pattern_confidence — Max Beta-Binomial confidence from learned patterns
32
- [10] signal_count — Number of feedback signals for this memory (v2.7.4)
33
- [11] avg_signal_value — Average signal value for this memory (v2.7.4)
11
+ Feature Vector (20 dimensions):
12
+ [0] bm25_score — Existing retrieval score from search results
13
+ [1] tfidf_score — TF-IDF cosine similarity from search results
14
+ [2] tech_match — Does memory match user's tech preferences?
15
+ [3] project_match — Is memory from the current project?
16
+ [4] workflow_fit — Does memory fit current workflow phase?
17
+ [5] source_quality — Quality score of the source that created this memory
18
+ [6] importance_norm — Normalized importance (importance / 10.0)
19
+ [7] recency_score — Exponential decay based on age (180-day half-life)
20
+ [8] access_frequency — How often this memory was accessed (capped at 1.0)
21
+ [9] pattern_confidence — Max Beta-Binomial confidence from learned patterns
22
+ [10] signal_count — Number of feedback signals for this memory (v2.7.4)
23
+ [11] avg_signal_value — Average signal value for this memory (v2.7.4)
24
+ [12] lifecycle_state — Encoded lifecycle state (v2.8)
25
+ [13] outcome_success_rate — Success rate from behavioral outcomes (v2.8)
26
+ [14] outcome_count — Number of outcomes recorded (v2.8)
27
+ [15] behavioral_match — Match against known success patterns (v2.8)
28
+ [16] cross_project_score — Cross-project transfer confidence (v2.8)
29
+ [17] retention_priority — Retention policy priority (v2.8)
30
+ [18] trust_at_creation — Trust score of creator agent (v2.8)
31
+ [19] lifecycle_aware_decay — Modified recency decay with lifecycle (v2.8)
34
32
 
35
33
  Design Principles:
36
34
  - All features normalized to [0.0, 1.0] range for ML compatibility
@@ -40,6 +38,7 @@ Design Principles:
40
38
  - Thread-safe: no shared mutable state after set_context()
41
39
 
42
40
  v2.7.4: Expanded from 10 to 12 features. Auto-retrain triggered on mismatch.
41
+ v2.8.0: Expanded from 12 to 20 features. Lifecycle, behavioral, compliance dimensions.
43
42
  """
44
43
 
45
44
  import logging
@@ -67,6 +66,14 @@ FEATURE_NAMES = [
67
66
  'pattern_confidence', # 9: Max Beta-Binomial confidence from learned patterns
68
67
  'signal_count', # 10: Number of feedback signals for this memory (v2.7.4)
69
68
  'avg_signal_value', # 11: Average signal value for this memory (v2.7.4)
69
+ 'lifecycle_state', # 12: Encoded lifecycle state (v2.8)
70
+ 'outcome_success_rate', # 13: Success rate from behavioral outcomes (v2.8)
71
+ 'outcome_count', # 14: Number of outcomes recorded (v2.8)
72
+ 'behavioral_match', # 15: Match against known success patterns (v2.8)
73
+ 'cross_project_score', # 16: Cross-project transfer confidence (v2.8)
74
+ 'retention_priority', # 17: Retention policy priority (v2.8)
75
+ 'trust_at_creation', # 18: Trust score of creator agent (v2.8)
76
+ 'lifecycle_aware_decay', # 19: Modified recency decay with lifecycle (v2.8)
70
77
  ]
71
78
 
72
79
  NUM_FEATURES = len(FEATURE_NAMES)
@@ -108,7 +115,7 @@ _MAX_ACCESS_COUNT = 10
108
115
 
109
116
  class FeatureExtractor:
110
117
  """
111
- Extracts 12-dimensional feature vectors for candidate memories.
118
+ Extracts 20-dimensional feature vectors for candidate memories.
112
119
 
113
120
  Usage:
114
121
  extractor = FeatureExtractor()
@@ -120,7 +127,7 @@ class FeatureExtractor:
120
127
  signal_stats={'42': {'count': 5, 'avg_value': 0.8}},
121
128
  )
122
129
  features = extractor.extract_batch(memories, query="search optimization")
123
- # features is List[List[float]], shape (n_memories, 12)
130
+ # features is List[List[float]], shape (n_memories, 20)
124
131
  """
125
132
 
126
133
  FEATURE_NAMES = FEATURE_NAMES
@@ -194,30 +201,42 @@ class FeatureExtractor:
194
201
 
195
202
  def extract_features(self, memory: dict, query: str) -> List[float]:
196
203
  """
197
- Extract 12-dimensional feature vector for a single memory.
204
+ Extract 20-dimensional feature vector for a single memory.
198
205
 
199
206
  Args:
200
207
  memory: Memory dict from search results. Expected keys:
201
208
  id, content, score, match_type, importance, created_at,
202
209
  access_count, project_name, tags, created_by (optional).
210
+ v2.8 optional keys: lifecycle_state, outcome_success_rate,
211
+ outcome_count, behavioral_match, cross_project_score,
212
+ retention_priority, trust_at_creation.
203
213
  query: The recall query string.
204
214
 
205
215
  Returns:
206
- List of 12 floats in [0.0, 1.0] range, one per feature.
216
+ List of 20 floats in [0.0, 1.0] range, one per feature.
207
217
  """
208
218
  return [
209
- self._compute_bm25_score(memory),
210
- self._compute_tfidf_score(memory),
211
- self._compute_tech_match(memory),
212
- self._compute_project_match(memory),
213
- self._compute_workflow_fit(memory),
214
- self._compute_source_quality(memory),
215
- self._compute_importance_norm(memory),
216
- self._compute_recency_score(memory),
217
- self._compute_access_frequency(memory),
218
- self._compute_pattern_confidence(memory),
219
- self._compute_signal_count(memory),
220
- self._compute_avg_signal_value(memory),
219
+ self._compute_bm25_score(memory), # 0
220
+ self._compute_tfidf_score(memory), # 1
221
+ self._compute_tech_match(memory), # 2
222
+ self._compute_project_match(memory), # 3
223
+ self._compute_workflow_fit(memory), # 4
224
+ self._compute_source_quality(memory), # 5
225
+ self._compute_importance_norm(memory), # 6
226
+ self._compute_recency_score(memory), # 7
227
+ self._compute_access_frequency(memory), # 8
228
+ self._compute_pattern_confidence(memory), # 9
229
+ self._compute_signal_count(memory), # 10
230
+ self._compute_avg_signal_value(memory), # 11
231
+ # v2.8 features: lifecycle, behavioral, compliance
232
+ self._compute_lifecycle_state(memory), # 12
233
+ self._compute_outcome_success_rate(memory), # 13
234
+ self._compute_outcome_count(memory), # 14
235
+ self._compute_behavioral_match(memory), # 15
236
+ self._compute_cross_project_score(memory), # 16
237
+ self._compute_retention_priority(memory), # 17
238
+ self._compute_trust_at_creation(memory), # 18
239
+ self._compute_lifecycle_aware_decay(memory), # 19
221
240
  ]
222
241
 
223
242
  def extract_batch(
@@ -233,7 +252,7 @@ class FeatureExtractor:
233
252
  query: The recall query string.
234
253
 
235
254
  Returns:
236
- List of feature vectors (List[List[float]]), shape (n, 12).
255
+ List of feature vectors (List[List[float]]), shape (n, 20).
237
256
  Returns empty list if memories is empty.
238
257
  """
239
258
  if not memories:
@@ -561,6 +580,119 @@ class FeatureExtractor:
561
580
 
562
581
  return max(0.0, min(max_confidence, 1.0))
563
582
 
583
+ # ========================================================================
584
+ # v2.8 Feature Computations: Lifecycle, Behavioral, Compliance
585
+ # ========================================================================
586
+
587
+ def _compute_lifecycle_state(self, memory: dict) -> float:
588
+ """
589
+ Encode lifecycle state as numeric value.
590
+
591
+ State mapping:
592
+ active = 1.0 (fully available, highest priority)
593
+ warm = 0.7 (less frequently accessed, still relevant)
594
+ cold = 0.4 (rarely accessed, compressed)
595
+ archived = 0.1 (long-term storage, minimal priority)
596
+ tombstoned = 0.0 (pending deletion)
597
+
598
+ Default: 'active' (1.0) — backward compatible with pre-v2.8 memories
599
+ that have no lifecycle_state field.
600
+ """
601
+ state_map = {
602
+ 'active': 1.0,
603
+ 'warm': 0.7,
604
+ 'cold': 0.4,
605
+ 'archived': 0.1,
606
+ 'tombstoned': 0.0,
607
+ }
608
+ return state_map.get(memory.get('lifecycle_state', 'active'), 1.0)
609
+
610
+ def _compute_outcome_success_rate(self, memory: dict) -> float:
611
+ """
612
+ Success rate from behavioral outcomes.
613
+
614
+ Reads directly from the memory dict — the behavioral engine
615
+ enriches memories with this field during recall.
616
+
617
+ Default: 0.5 (neutral — no outcome data available).
618
+ """
619
+ return float(memory.get('outcome_success_rate', 0.5))
620
+
621
+ def _compute_outcome_count(self, memory: dict) -> float:
622
+ """
623
+ Number of outcomes recorded, normalized to [0.0, 1.0].
624
+
625
+ Capped at 20 outcomes (count / 20.0). Memories with more
626
+ behavioral observations are better calibrated.
627
+
628
+ Default: 0 outcomes (returns 0.0).
629
+ """
630
+ count = memory.get('outcome_count', 0)
631
+ try:
632
+ count = int(count)
633
+ except (ValueError, TypeError):
634
+ count = 0
635
+ return min(count / 20.0, 1.0)
636
+
637
+ def _compute_behavioral_match(self, memory: dict) -> float:
638
+ """
639
+ How well this memory matches known success patterns.
640
+
641
+ The behavioral engine computes this by comparing the memory's
642
+ characteristics against patterns extracted from successful outcomes.
643
+
644
+ Default: 0.0 (no behavioral match data available).
645
+ """
646
+ return float(memory.get('behavioral_match', 0.0))
647
+
648
+ def _compute_cross_project_score(self, memory: dict) -> float:
649
+ """
650
+ Cross-project transfer confidence.
651
+
652
+ Measures how likely this memory's knowledge transfers successfully
653
+ across project boundaries (e.g., a Python pattern useful in any project).
654
+
655
+ Default: 0.0 (no cross-project data available).
656
+ """
657
+ return float(memory.get('cross_project_score', 0.0))
658
+
659
+ def _compute_retention_priority(self, memory: dict) -> float:
660
+ """
661
+ Retention policy priority.
662
+
663
+ 1.0 = protected by retention policy (must not be deleted)
664
+ 0.5 = default (no special retention rules)
665
+ 0.0 = eligible for aggressive cleanup
666
+
667
+ Default: 0.5 (standard retention).
668
+ """
669
+ return float(memory.get('retention_priority', 0.5))
670
+
671
+ def _compute_trust_at_creation(self, memory: dict) -> float:
672
+ """
673
+ Trust score of the agent that created this memory.
674
+
675
+ Human-created memories default to 0.8 (high trust).
676
+ Agent-created memories can have lower trust until validated.
677
+
678
+ Default: 0.8 (assumes human creator for backward compatibility).
679
+ """
680
+ return float(memory.get('trust_at_creation', 0.8))
681
+
682
+ def _compute_lifecycle_aware_decay(self, memory: dict) -> float:
683
+ """
684
+ Modified recency decay that factors in lifecycle state.
685
+
686
+ Combines the standard exponential recency decay with the lifecycle
687
+ state encoding. This means archived memories decay faster than
688
+ active memories of the same age, creating a compound signal.
689
+
690
+ Formula: recency_score * lifecycle_state_value
691
+ """
692
+ recency = self._compute_recency_score(memory)
693
+ lifecycle = self._compute_lifecycle_state(memory)
694
+ return recency * lifecycle
695
+
564
696
 
565
697
  # ============================================================================
566
698
  # Module-level convenience functions
@@ -1,16 +1,6 @@
1
1
  #!/usr/bin/env python3
2
- """
3
- SuperLocalMemory V2 - Feedback Collector (v2.7)
4
- Copyright (c) 2026 Varun Pratap Bhardwaj
5
- Licensed under MIT License
6
-
7
- Repository: https://github.com/varun369/SuperLocalMemoryV2
8
- Author: Varun Pratap Bhardwaj (Solution Architect)
9
-
10
- NOTICE: This software is protected by MIT License.
11
- Attribution must be preserved in all copies or derivatives.
12
- """
13
-
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (c) 2026 SuperLocalMemory (superlocalmemory.com)
14
4
  """
15
5
  FeedbackCollector -- Multi-channel feedback collection for the LightGBM re-ranker.
16
6
 
@@ -120,6 +110,11 @@ class FeedbackCollector:
120
110
  "implicit_negative_post_delete": 0.0,
121
111
  "implicit_positive_cross_tool": 0.8,
122
112
  "passive_decay": 0.0,
113
+ # v2.8.0: Outcome-based signals from behavioral learning
114
+ "outcome_success": 1.0,
115
+ "outcome_partial": 0.5,
116
+ "outcome_failure": 0.0,
117
+ "outcome_retry": 0.2,
123
118
  }
124
119
 
125
120
  # Usefulness string -> signal type mapping