hy-memory 2.0.6__tar.gz → 2.0.7__tar.gz

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 (143) hide show
  1. {hy_memory-2.0.6/hy_memory.egg-info → hy_memory-2.0.7}/PKG-INFO +1 -1
  2. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/client.py +8 -1
  3. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/fact_reconciler.py +5 -1
  4. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/reconciler.py +1 -0
  5. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/store.py +41 -5
  6. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/types.py +14 -0
  7. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/writer.py +8 -1
  8. {hy_memory-2.0.6 → hy_memory-2.0.7/hy_memory.egg-info}/PKG-INFO +1 -1
  9. {hy_memory-2.0.6 → hy_memory-2.0.7}/pyproject.toml +1 -1
  10. {hy_memory-2.0.6 → hy_memory-2.0.7}/LICENSE +0 -0
  11. {hy_memory-2.0.6 → hy_memory-2.0.7}/MANIFEST.in +0 -0
  12. {hy_memory-2.0.6 → hy_memory-2.0.7}/README.md +0 -0
  13. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/__init__.py +0 -0
  14. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/__init__.py +0 -0
  15. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/abstractor.py +0 -0
  16. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/emotion_analyzer.py +0 -0
  17. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/episode_summary.py +0 -0
  18. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/extractor.py +0 -0
  19. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/intention_detector.py +0 -0
  20. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/llm_provider.py +0 -0
  21. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/mem_agent.py +0 -0
  22. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/prompts_zh.py +0 -0
  23. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/reconciler.py +0 -0
  24. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/reflector.py +0 -0
  25. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/tools/__init__.py +0 -0
  26. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/tools/base.py +0 -0
  27. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/agent/tools/basic_profile.py +0 -0
  28. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/__init__.py +0 -0
  29. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/chain_store.py +0 -0
  30. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/extractor.py +0 -0
  31. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/judge.py +0 -0
  32. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/lexical.py +0 -0
  33. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/preproc.py +0 -0
  34. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/coding/prompts_zh.py +0 -0
  35. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/config.py +0 -0
  36. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/core/__init__.py +0 -0
  37. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/core/embed_service.py +0 -0
  38. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/core/merger.py +0 -0
  39. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/core/scorer.py +0 -0
  40. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/core/workload.py +0 -0
  41. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/__init__.py +0 -0
  42. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/cache.py +0 -0
  43. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/cache_base.py +0 -0
  44. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/cache_mysql.py +0 -0
  45. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/cache_sqlite.py +0 -0
  46. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/graph_store.py +0 -0
  47. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/graph_store_base.py +0 -0
  48. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/graph_store_kuzu.py +0 -0
  49. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/graph_store_neo4j.py +0 -0
  50. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/history_store.py +0 -0
  51. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/kv_store.py +0 -0
  52. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/rdb.py +0 -0
  53. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/vector_store.py +0 -0
  54. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/vector_store_base.py +0 -0
  55. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/vector_store_chroma.py +0 -0
  56. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/vector_store_faiss.py +0 -0
  57. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/data/vector_store_qdrant.py +0 -0
  58. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/embedding.py +0 -0
  59. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/inspector.py +0 -0
  60. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/metrics.py +0 -0
  61. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/models/__init__.py +0 -0
  62. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/models/memory.py +0 -0
  63. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/models/requests.py +0 -0
  64. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/__init__.py +0 -0
  65. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_graph/__init__.py +0 -0
  66. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_graph/projector.py +0 -0
  67. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_graph/rerank.py +0 -0
  68. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_graph/topic_summary.py +0 -0
  69. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/__init__.py +0 -0
  70. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/bm25.py +0 -0
  71. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/bm25_fastembed.py +0 -0
  72. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/candidate_guards.py +0 -0
  73. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/config.py +0 -0
  74. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/date_view.py +0 -0
  75. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/dedup.py +0 -0
  76. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/diversity.py +0 -0
  77. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/entities.py +0 -0
  78. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/entity_store.py +0 -0
  79. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/evolution.py +0 -0
  80. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/hierarchy_bundle.py +0 -0
  81. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/intent.py +0 -0
  82. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/intention.py +0 -0
  83. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/lemmatize.py +0 -0
  84. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/local_rerank.py +0 -0
  85. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/memory_format.py +0 -0
  86. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/multi_seed_bundle.py +0 -0
  87. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/ner.py +0 -0
  88. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/profile_evidence.py +0 -0
  89. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/profile_owner_gate.py +0 -0
  90. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/query_expand.py +0 -0
  91. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/reconcile_retrieval.py +0 -0
  92. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/record_date_view.py +0 -0
  93. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/retrieval_clauses.py +0 -0
  94. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/rrf.py +0 -0
  95. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/scoring.py +0 -0
  96. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/series_tail_guard.py +0 -0
  97. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/session_episode.py +0 -0
  98. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/strength.py +0 -0
  99. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/supplemental_propositions.py +0 -0
  100. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/tag_index.py +0 -0
  101. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/temporal.py +0 -0
  102. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/topic_candidates.py +0 -0
  103. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/trace.py +0 -0
  104. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/underflow.py +0 -0
  105. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/_retrieval/user_level_l0.py +0 -0
  106. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/balanced_catalog.py +0 -0
  107. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/base.py +0 -0
  108. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/cross_domain_sweeper.py +0 -0
  109. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/reader.py +0 -0
  110. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/reader_base.py +0 -0
  111. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/reader_hybrid.py +0 -0
  112. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/reader_legacy.py +0 -0
  113. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/registry.py +0 -0
  114. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/specific_supplement.py +0 -0
  115. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/system2_agent.py +0 -0
  116. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/system2_tools.py +0 -0
  117. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/system2_writer.py +0 -0
  118. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/user_profile_scope.py +0 -0
  119. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/pipelines/writer.py +0 -0
  120. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/retrieval.py +0 -0
  121. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/runtime.py +0 -0
  122. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/server.py +0 -0
  123. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/snapshot.py +0 -0
  124. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/structure.py +0 -0
  125. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/async_executor.py +0 -0
  126. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/clone_references.py +0 -0
  127. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/keyword_ties.py +0 -0
  128. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/lang_detect.py +0 -0
  129. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/log_setup.py +0 -0
  130. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/metrics.py +0 -0
  131. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/model_call_context.py +0 -0
  132. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/pipeline_log_writer.py +0 -0
  133. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/pipeline_observability.py +0 -0
  134. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/source_filter.py +0 -0
  135. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/time_window.py +0 -0
  136. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/token_count.py +0 -0
  137. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/trace_file_writer.py +0 -0
  138. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory/utils/tracer.py +0 -0
  139. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory.egg-info/SOURCES.txt +0 -0
  140. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory.egg-info/dependency_links.txt +0 -0
  141. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory.egg-info/requires.txt +0 -0
  142. {hy_memory-2.0.6 → hy_memory-2.0.7}/hy_memory.egg-info/top_level.txt +0 -0
  143. {hy_memory-2.0.6 → hy_memory-2.0.7}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hy-memory
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: HY Memory - Industrial-grade dual-system cognitive memory framework
5
5
  Author: alvinfei
6
6
  License-Expression: Apache-2.0
@@ -1544,6 +1544,7 @@ class HyMemoryClient:
1544
1544
  # LLM 写的"这个结论一路怎么改成现在这样",直接进提示词;
1545
1545
  # 没被覆盖过就是空串。不参与检索——召回认的是 statement 的当前值。
1546
1546
  "fact_chain_summary": fact.fact_chain_summary,
1547
+ "memory_at": _epoch_seconds(fact.memory_at),
1547
1548
  "created_at": fact.created_at.isoformat() if fact.created_at else None,
1548
1549
  "score": round(float(score), 4),
1549
1550
  "source": fact.source,
@@ -1652,6 +1653,8 @@ class HyMemoryClient:
1652
1653
  "score": (round(float(score_by_id[d.experience_id]), 4)
1653
1654
  if d.experience_id in score_by_id else None),
1654
1655
  "confidence": d.confidence,
1656
+ "memory_at": _epoch_seconds(d.memory_at),
1657
+ "created_at": d.created_at.isoformat() if d.created_at else None,
1655
1658
  "updated_at": d.updated_at.isoformat() if d.updated_at else None,
1656
1659
  "source": d.source,
1657
1660
  "extraction_source": d.extraction_source,
@@ -1953,6 +1956,7 @@ class HyMemoryClient:
1953
1956
  "content" chat 正文;经验为 "task\nsolution";事实为 statement
1954
1957
  "score" RRF 融合分;"lane_score" 为该路原始分;"lane_rank" 为该路名次
1955
1958
  "source", "created_at", "updated_at"(秒级 epoch,取不到为 None)
1959
+ "memory_at" 对话时间(秒级 epoch),各路原有字段,三路同名同格式
1956
1960
  chat 路内部名次:normal → schema → proactive 依次排;working/coding 路
1957
1961
  内部名次:事实与经验各按原顺序交替(事实在前),两层谁也不压谁。
1958
1962
  """
@@ -2144,7 +2148,8 @@ class HyMemoryClient:
2144
2148
  "limit", "offset", "request_id", "elapsed_ms"}
2145
2149
  每条带 "scene"、"kind"(chat | experience)、"memory_id"、"content"
2146
2150
  (经验为 "task\nsolution")、"source"、"status"、"created_at"、
2147
- "updated_at"(秒级 epoch),以及该路原有字段。
2151
+ "updated_at"(秒级 epoch),以及该路原有字段(含对话时间
2152
+ "memory_at",秒级 epoch,三路同名同格式)。
2148
2153
  """
2149
2154
  return self._loop_thread.run(
2150
2155
  self.async_list_memories(
@@ -2967,6 +2972,7 @@ class HyMemoryClient:
2967
2972
  session_id=session_id,
2968
2973
  request_id=request_id,
2969
2974
  source=source,
2975
+ memory_at=memory_at,
2970
2976
  )
2971
2977
  # Public receipt always identifies the productivity namespace.
2972
2978
  resp["variant"] = scene_variant
@@ -5920,6 +5926,7 @@ class HyMemoryClient:
5920
5926
  "source_fact_ids": list(d.source_fact_ids),
5921
5927
  "confidence": d.confidence,
5922
5928
  "status": MemoryStatus.ACTIVE.value,
5929
+ "memory_at": _epoch_seconds(d.memory_at),
5923
5930
  "created_at": d.created_at.isoformat() if d.created_at else None,
5924
5931
  "updated_at": d.updated_at.isoformat() if d.updated_at else None,
5925
5932
  "source": d.source,
@@ -454,9 +454,10 @@ class WorkingFactReconciler:
454
454
  workspace_id: Optional[str] = None,
455
455
  branch: Optional[str] = None,
456
456
  source: str = "default",
457
+ memory_at: Optional[datetime] = None,
457
458
  ) -> Tuple[List[WorkingFact], List[FactReconcileOp]]:
458
459
  """
459
- 执行 reconcile + 持久化。
460
+ 执行 reconcile + 持久化。memory_at 是这段对话的时间,记到新事实上。
460
461
 
461
462
  Returns:
462
463
  (真正落库的新事实, 执行过的 ops)。LLM 挂掉时退化为全 INSERT 不覆盖,
@@ -493,6 +494,7 @@ class WorkingFactReconciler:
493
494
  workspace_id=workspace_id,
494
495
  branch=branch,
495
496
  source=source,
497
+ memory_at=memory_at,
496
498
  )
497
499
  logger.info(
498
500
  f"[fact-reconcile] drafts={len(drafts)} inserted={len(facts)} "
@@ -781,6 +783,7 @@ class WorkingFactReconciler:
781
783
  workspace_id: Optional[str],
782
784
  branch: Optional[str] = None,
783
785
  source: str = "default",
786
+ memory_at: Optional[datetime] = None,
784
787
  ) -> Tuple[List[WorkingFact], List[FactReconcileOp]]:
785
788
  inserted: List[WorkingFact] = []
786
789
  ops: List[FactReconcileOp] = []
@@ -801,6 +804,7 @@ class WorkingFactReconciler:
801
804
  subject=draft.subject,
802
805
  details=draft.details,
803
806
  status="active",
807
+ memory_at=memory_at,
804
808
  )
805
809
 
806
810
  allowed = {c.fact_id for c in (candidates[idx] if idx < len(candidates) else [])}
@@ -577,6 +577,7 @@ class CodingMemoryReconciler:
577
577
  confidence=d.confidence,
578
578
  source=d.source,
579
579
  extraction_source=d.extraction_source,
580
+ memory_at=d.memory_at,
580
581
  )
581
582
 
582
583
 
@@ -86,6 +86,7 @@ CREATE TABLE IF NOT EXISTS coding_memory_meta (
86
86
  confidence REAL NOT NULL DEFAULT 0.7,
87
87
  source TEXT NOT NULL DEFAULT 'default',
88
88
  extraction_source TEXT NOT NULL DEFAULT 'auto_extract',
89
+ memory_at INTEGER,
89
90
  created_at TEXT NOT NULL,
90
91
  updated_at TEXT NOT NULL
91
92
  );
@@ -109,6 +110,7 @@ CREATE TABLE IF NOT EXISTS working_fact (
109
110
  derived_experience_ids TEXT NOT NULL DEFAULT '[]',
110
111
  status TEXT NOT NULL DEFAULT 'active',
111
112
  fact_chain_summary TEXT NOT NULL DEFAULT '',
113
+ memory_at INTEGER,
112
114
  created_at TEXT NOT NULL
113
115
  );
114
116
  -- 反查前驱(谁的 fact_link 指向我)走这个索引,写演变总结时要顺着链往回走
@@ -164,6 +166,8 @@ _ADDED_COLUMNS = {
164
166
  "coding_memory_meta": {
165
167
  "source_fact_ids": "TEXT NOT NULL DEFAULT '[]'",
166
168
  "extraction_source": "TEXT NOT NULL DEFAULT 'auto_extract'",
169
+ # 对话时间,秒级 epoch(同 chat)。老库里的行是 NULL:那时没存过。
170
+ "memory_at": "INTEGER",
167
171
  },
168
172
  # 早期版本存过一列 fact_chain(机械累积的历代说法),已废弃:同样的信息顺着
169
173
  # fact_link 反查就有。老库里那一列留着不管,有默认值不影响插入。
@@ -177,6 +181,7 @@ _ADDED_COLUMNS = {
177
181
  "subject": "TEXT NOT NULL DEFAULT ''",
178
182
  "details": "TEXT NOT NULL DEFAULT ''",
179
183
  "source": "TEXT NOT NULL DEFAULT 'default'",
184
+ "memory_at": "INTEGER",
180
185
  },
181
186
  }
182
187
 
@@ -290,6 +295,29 @@ def _parse_dt(s: Optional[str]) -> Optional[datetime]:
290
295
  return None
291
296
 
292
297
 
298
+ def _from_epoch(value: Any) -> Optional[datetime]:
299
+ """memory_at 列(秒级 epoch)→ datetime;NULL 或坏值返回 None。"""
300
+ if value is None:
301
+ return None
302
+ try:
303
+ return datetime.fromtimestamp(int(value))
304
+ except Exception:
305
+ return None
306
+
307
+
308
+ def _to_epoch(value: Optional[datetime]) -> Optional[int]:
309
+ return int(value.timestamp()) if isinstance(value, datetime) else None
310
+
311
+
312
+ def _later(a: Optional[datetime], b: Optional[datetime]) -> Optional[datetime]:
313
+ """两个对话时间取较晚的;一边缺就取另一边。"""
314
+ if a is None:
315
+ return b
316
+ if b is None:
317
+ return a
318
+ return a if _to_epoch(a) >= _to_epoch(b) else b
319
+
320
+
293
321
  def _row_to_memory(row: sqlite3.Row) -> CodingMemory:
294
322
  """SQLite row → CodingMemory"""
295
323
  return CodingMemory(
@@ -308,6 +336,7 @@ def _row_to_memory(row: sqlite3.Row) -> CodingMemory:
308
336
  confidence=row["confidence"],
309
337
  source=row["source"],
310
338
  extraction_source=row["extraction_source"],
339
+ memory_at=_from_epoch(row["memory_at"]),
311
340
  created_at=_parse_dt(row["created_at"]),
312
341
  updated_at=_parse_dt(row["updated_at"]),
313
342
  )
@@ -334,6 +363,7 @@ def _row_to_fact(row: sqlite3.Row) -> WorkingFact:
334
363
  # 老库刚 ADD COLUMN 时可能取不到这一列,用 keys() 兜一下
335
364
  fact_chain_summary=(row["fact_chain_summary"] or ""
336
365
  if "fact_chain_summary" in row.keys() else ""),
366
+ memory_at=_from_epoch(row["memory_at"]),
337
367
  created_at=_parse_dt(row["created_at"]),
338
368
  )
339
369
 
@@ -597,6 +627,8 @@ class CodingMemoryStore:
597
627
  memory.updated_at = datetime.utcnow()
598
628
  if memory.created_at is None:
599
629
  memory.created_at = prev.created_at
630
+ # 合并后的经验讲的是两段对话,对话时间取较晚的那段
631
+ memory.memory_at = _later(prev.memory_at, memory.memory_at)
600
632
  await _run_in_pool(self._upsert_sql_sync, memory)
601
633
  # 删旧 VDB
602
634
  await self._delete_vec_keys_by_count(memory.experience_id, prev_key_count)
@@ -1199,8 +1231,8 @@ class CodingMemoryStore:
1199
1231
  experience_id, user_id, agent_id, task, search_keys, solution,
1200
1232
  boundary_envs, workspace_id, branch, session_id,
1201
1233
  files, source_fact_ids, confidence, source, extraction_source,
1202
- created_at, updated_at
1203
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1234
+ memory_at, created_at, updated_at
1235
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1204
1236
  ON CONFLICT(experience_id) DO UPDATE SET
1205
1237
  user_id = excluded.user_id,
1206
1238
  agent_id = excluded.agent_id,
@@ -1216,6 +1248,7 @@ class CodingMemoryStore:
1216
1248
  confidence = excluded.confidence,
1217
1249
  source = excluded.source,
1218
1250
  extraction_source = excluded.extraction_source,
1251
+ memory_at = excluded.memory_at,
1219
1252
  updated_at = excluded.updated_at
1220
1253
  """,
1221
1254
  (
@@ -1226,6 +1259,7 @@ class CodingMemoryStore:
1226
1259
  json.dumps(memory.files, ensure_ascii=False),
1227
1260
  json.dumps(memory.source_fact_ids, ensure_ascii=False),
1228
1261
  memory.confidence, memory.source, memory.extraction_source,
1262
+ _to_epoch(memory.memory_at),
1229
1263
  (memory.created_at or datetime.utcnow()).isoformat(),
1230
1264
  (memory.updated_at or datetime.utcnow()).isoformat(),
1231
1265
  ),
@@ -1366,8 +1400,8 @@ class CodingMemoryStore:
1366
1400
  fact_id, user_id, agent_id, session_id, workspace_id, branch,
1367
1401
  source, statement, files, subject, details,
1368
1402
  fact_link, derived_experience_ids,
1369
- status, fact_chain_summary, created_at
1370
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1403
+ status, fact_chain_summary, memory_at, created_at
1404
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1371
1405
  ON CONFLICT(fact_id) DO UPDATE SET
1372
1406
  user_id = excluded.user_id,
1373
1407
  agent_id = excluded.agent_id,
@@ -1382,7 +1416,8 @@ class CodingMemoryStore:
1382
1416
  fact_link = excluded.fact_link,
1383
1417
  derived_experience_ids = excluded.derived_experience_ids,
1384
1418
  status = excluded.status,
1385
- fact_chain_summary = excluded.fact_chain_summary
1419
+ fact_chain_summary = excluded.fact_chain_summary,
1420
+ memory_at = excluded.memory_at
1386
1421
  """,
1387
1422
  (
1388
1423
  fact.fact_id, fact.user_id, fact.agent_id,
@@ -1395,6 +1430,7 @@ class CodingMemoryStore:
1395
1430
  json.dumps(fact.derived_experience_ids, ensure_ascii=False),
1396
1431
  fact.status,
1397
1432
  fact.fact_chain_summary or "",
1433
+ _to_epoch(fact.memory_at),
1398
1434
  (fact.created_at or datetime.utcnow()).isoformat(),
1399
1435
  ),
1400
1436
  )
@@ -25,6 +25,11 @@ FactStatus = Literal["active", "superseded"]
25
25
  MAX_FACT_CHAIN_ENTRIES = 8
26
26
 
27
27
 
28
+ def _epoch(value: Optional[datetime]) -> Optional[int]:
29
+ """memory_at 对外是秒级 epoch,与 chat 一致。"""
30
+ return int(value.timestamp()) if isinstance(value, datetime) else None
31
+
32
+
28
33
  # ================================================================
29
34
  # 草稿(LLM extract 阶段输出)
30
35
  # ================================================================
@@ -53,6 +58,8 @@ class CodingMemoryDraft:
53
58
  files: List[str] = field(default_factory=list)
54
59
  source: str = "default"
55
60
  extraction_source: str = "auto_extract"
61
+ # 对话时间(SDK 注入,同 chat 的 memory_at)
62
+ memory_at: Optional[datetime] = None
56
63
 
57
64
  def __post_init__(self) -> None:
58
65
  from ..utils.source_filter import normalize_source
@@ -73,6 +80,7 @@ class CodingMemoryDraft:
73
80
  "files": list(self.files),
74
81
  "source": self.source,
75
82
  "extraction_source": self.extraction_source,
83
+ "memory_at": _epoch(self.memory_at),
76
84
  }
77
85
 
78
86
 
@@ -111,6 +119,9 @@ class CodingMemory:
111
119
  extraction_source: str = "auto_extract"
112
120
 
113
121
  # 时间
122
+ # memory_at 是对话时间(同 chat),created_at / updated_at 是写库时间。
123
+ # UPDATE 合并时取两者中较晚的那个对话时间,见 store.update。
124
+ memory_at: Optional[datetime] = None
114
125
  created_at: Optional[datetime] = None
115
126
  updated_at: Optional[datetime] = None
116
127
 
@@ -135,6 +146,7 @@ class CodingMemory:
135
146
  "confidence": self.confidence,
136
147
  "source": self.source,
137
148
  "extraction_source": self.extraction_source,
149
+ "memory_at": _epoch(self.memory_at),
138
150
  "created_at": self.created_at.isoformat() if self.created_at else None,
139
151
  "updated_at": self.updated_at.isoformat() if self.updated_at else None,
140
152
  }
@@ -249,6 +261,7 @@ class WorkingFact:
249
261
  fact_chain_summary: str = ""
250
262
 
251
263
  # 时间
264
+ memory_at: Optional[datetime] = None # 对话时间(同 chat),没传时是收到请求的时间
252
265
  created_at: Optional[datetime] = None # 产生时间,新的优先
253
266
 
254
267
  def __post_init__(self) -> None:
@@ -272,6 +285,7 @@ class WorkingFact:
272
285
  "derived_experience_ids": list(self.derived_experience_ids),
273
286
  "status": self.status,
274
287
  "fact_chain_summary": self.fact_chain_summary,
288
+ "memory_at": _epoch(self.memory_at),
275
289
  "created_at": self.created_at.isoformat() if self.created_at else None,
276
290
  }
277
291
 
@@ -18,6 +18,7 @@ CodingWriter - 写入端协调器
18
18
  import logging
19
19
  import time
20
20
  import uuid
21
+ from datetime import datetime
21
22
  from typing import Any, Dict, List, Optional
22
23
 
23
24
  from ..agent.llm_provider import LLMProvider
@@ -79,9 +80,11 @@ class CodingWriter:
79
80
  session_id: Optional[str] = None,
80
81
  request_id: Optional[str] = None,
81
82
  source: str = "default",
83
+ memory_at: Optional[datetime] = None,
82
84
  ) -> Dict[str, Any]:
83
85
  """
84
- working/coding 段写入端到端。返回响应 dict(兼容 client.add 返回结构):
86
+ working/coding 段写入端到端。memory_at 是对话时间,记到这次写出的经验和
87
+ 事实上;不传则用收到请求的时间(与 chat 链路一致)。返回响应 dict(兼容 client.add 返回结构):
85
88
  {
86
89
  "success": True,
87
90
  "scene": "productivity",
@@ -101,6 +104,8 @@ class CodingWriter:
101
104
  """
102
105
  request_id = request_id or str(uuid.uuid4())
103
106
  t0 = time.perf_counter()
107
+ if memory_at is None:
108
+ memory_at = datetime.now()
104
109
 
105
110
  if not messages:
106
111
  return self._empty_response(request_id, t0)
@@ -172,6 +177,7 @@ class CodingWriter:
172
177
  # extractor 只负责内容;调用来源由 SDK 入口注入,不能交给 LLM 生成。
173
178
  for draft in drafts:
174
179
  draft.source = source
180
+ draft.memory_at = memory_at
175
181
 
176
182
  # 3. 经验层 reconcile + 持久化
177
183
  ops: List[ReconcileOp] = (
@@ -197,6 +203,7 @@ class CodingWriter:
197
203
  workspace_id=workspace_id,
198
204
  branch=branch,
199
205
  source=source,
206
+ memory_at=memory_at,
200
207
  )
201
208
 
202
209
  experience_ids = [op.target_experience_id for op in ops
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hy-memory
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: HY Memory - Industrial-grade dual-system cognitive memory framework
5
5
  Author: alvinfei
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hy-memory"
7
- version = "2.0.6"
7
+ version = "2.0.7"
8
8
  description = "HY Memory - Industrial-grade dual-system cognitive memory framework"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes