JiuwenMemory 0.1.0__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 (252) hide show
  1. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/PKG-INFO +545 -0
  2. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/SOURCES.txt +250 -0
  3. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/dependency_links.txt +1 -0
  4. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/entry_points.txt +2 -0
  5. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/requires.txt +72 -0
  6. jiuwenmemory-0.1.0/JiuwenMemory.egg-info/top_level.txt +1 -0
  7. jiuwenmemory-0.1.0/LICENSE +202 -0
  8. jiuwenmemory-0.1.0/PKG-INFO +545 -0
  9. jiuwenmemory-0.1.0/README.md +469 -0
  10. jiuwenmemory-0.1.0/jiuwen_memory/__init__.py +23 -0
  11. jiuwenmemory-0.1.0/jiuwen_memory/common/__init__.py +13 -0
  12. jiuwenmemory-0.1.0/jiuwen_memory/common/clients/__init__.py +6 -0
  13. jiuwenmemory-0.1.0/jiuwen_memory/common/clients/client_registry.py +238 -0
  14. jiuwenmemory-0.1.0/jiuwen_memory/common/exception/__init__.py +0 -0
  15. jiuwenmemory-0.1.0/jiuwen_memory/common/exception/codes.py +968 -0
  16. jiuwenmemory-0.1.0/jiuwen_memory/common/exception/errors.py +332 -0
  17. jiuwenmemory-0.1.0/jiuwen_memory/common/exception/status_mapping.py +133 -0
  18. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/__init__.py +243 -0
  19. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/base_impl.py +164 -0
  20. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/default/__init__.py +29 -0
  21. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/default/config_provider.py +209 -0
  22. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/default/constant.py +26 -0
  23. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/default/default_impl.py +532 -0
  24. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/events.py +953 -0
  25. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/log_config.py +166 -0
  26. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/log_levels.py +65 -0
  27. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/loguru/__init__.py +8 -0
  28. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/loguru/config_provider.py +326 -0
  29. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/loguru/constant.py +68 -0
  30. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/loguru/loguru_impl.py +501 -0
  31. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/manager.py +214 -0
  32. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/protocol.py +75 -0
  33. jiuwenmemory-0.1.0/jiuwen_memory/common/logging/utils.py +127 -0
  34. jiuwenmemory-0.1.0/jiuwen_memory/common/schema/__init__.py +8 -0
  35. jiuwenmemory-0.1.0/jiuwen_memory/common/schema/card.py +25 -0
  36. jiuwenmemory-0.1.0/jiuwen_memory/common/schema/param.py +248 -0
  37. jiuwenmemory-0.1.0/jiuwen_memory/common/security/__init__.py +0 -0
  38. jiuwenmemory-0.1.0/jiuwen_memory/common/security/crypt_utils.py +114 -0
  39. jiuwenmemory-0.1.0/jiuwen_memory/common/security/path_checker.py +68 -0
  40. jiuwenmemory-0.1.0/jiuwen_memory/common/security/ssl_utils.py +128 -0
  41. jiuwenmemory-0.1.0/jiuwen_memory/common/security/url_utils.py +148 -0
  42. jiuwenmemory-0.1.0/jiuwen_memory/common/security/user_config.py +105 -0
  43. jiuwenmemory-0.1.0/jiuwen_memory/common/utils/__init__.py +0 -0
  44. jiuwenmemory-0.1.0/jiuwen_memory/common/utils/header_utils.py +32 -0
  45. jiuwenmemory-0.1.0/jiuwen_memory/common/utils/schema_utils.py +526 -0
  46. jiuwenmemory-0.1.0/jiuwen_memory/common/utils/singleton.py +16 -0
  47. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/__init__.py +93 -0
  48. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/headers_helper.py +46 -0
  49. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model.py +368 -0
  50. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/__init__.py +81 -0
  51. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/base_model_client.py +518 -0
  52. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/dashscope_model_client.py +579 -0
  53. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/deepseek_model_client.py +83 -0
  54. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/inference_affinity_model_client.py +846 -0
  55. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/intelli_router_model_client.py +482 -0
  56. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/openai_model_client.py +714 -0
  57. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/openrouter_model_client.py +46 -0
  58. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/model_clients/siliconflow_model_client.py +662 -0
  59. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/output_parsers/__init__.py +11 -0
  60. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/output_parsers/json_output_parser.py +239 -0
  61. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/output_parsers/markdown_output_parser.py +481 -0
  62. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/output_parsers/output_parser.py +33 -0
  63. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/__init__.py +20 -0
  64. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/config.py +87 -0
  65. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/generation_response.py +45 -0
  66. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/message.py +126 -0
  67. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/message_chunk.py +274 -0
  68. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/mode_info.py +33 -0
  69. jiuwenmemory-0.1.0/jiuwen_memory/foundation/llm/schema/tool_call.py +22 -0
  70. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/__init__.py +13 -0
  71. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/__init__.py +0 -0
  72. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/assembler.py +149 -0
  73. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/variables/__init__.py +0 -0
  74. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/variables/dictable.py +100 -0
  75. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/variables/textable.py +74 -0
  76. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/assemble/variables/variable.py +37 -0
  77. jiuwenmemory-0.1.0/jiuwen_memory/foundation/prompt/template.py +80 -0
  78. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/__init__.py +210 -0
  79. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_db_store.py +28 -0
  80. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_embedding.py +45 -0
  81. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_kv_store.py +214 -0
  82. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_memory_index.py +273 -0
  83. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_message_store.py +172 -0
  84. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_reranker.py +71 -0
  85. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/base_vector_store.py +601 -0
  86. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/db/__init__.py +0 -0
  87. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/db/default_db_store.py +13 -0
  88. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/db/gauss_db_store.py +30 -0
  89. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/db/gauss_dialect.py +117 -0
  90. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/__init__.py +31 -0
  91. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/base.py +95 -0
  92. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/base_graph_store.py +202 -0
  93. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/config.py +80 -0
  94. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/constants.py +19 -0
  95. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/database_config.py +52 -0
  96. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/graph_object.py +134 -0
  97. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/index_field.py +480 -0
  98. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/milvus/__init__.py +35 -0
  99. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/milvus/generate_milvus_schema.py +156 -0
  100. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/milvus/milvus_support.py +696 -0
  101. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/result_ranking.py +107 -0
  102. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/graph/utils.py +242 -0
  103. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/index/simple_memory_index.py +488 -0
  104. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/kv/__init__.py +8 -0
  105. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/kv/db_based_kv_store.py +348 -0
  106. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/kv/in_memory_kv_store.py +161 -0
  107. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/kv/shelve_store.py +235 -0
  108. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/query/__init__.py +72 -0
  109. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/query/base.py +270 -0
  110. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/query/chroma_query_func.py +198 -0
  111. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/query/milvus_query_func.py +131 -0
  112. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/query/registry.py +21 -0
  113. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/__init__.py +0 -0
  114. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/chroma_vector_store.py +798 -0
  115. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/es_vector_store.py +614 -0
  116. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/gauss_vector_store.py +832 -0
  117. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/milvus_vector_store.py +1067 -0
  118. jiuwenmemory-0.1.0/jiuwen_memory/foundation/store/vector/utils.py +369 -0
  119. jiuwenmemory-0.1.0/jiuwen_memory/foundation/tool/__init__.py +3 -0
  120. jiuwenmemory-0.1.0/jiuwen_memory/foundation/tool/schema.py +14 -0
  121. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/__init__.py +18 -0
  122. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/codec/__init__.py +0 -0
  123. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/codec/aes_storage_codec.py +57 -0
  124. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/common/__init__.py +1 -0
  125. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/common/base.py +24 -0
  126. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/common/distributed_lock.py +45 -0
  127. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/common/kv_prefix_registry.py +86 -0
  128. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/config/__init__.py +8 -0
  129. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/config/config.py +74 -0
  130. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/config/graph.py +94 -0
  131. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/external/__init__.py +15 -0
  132. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/external/agentarts_memory_provider.py +321 -0
  133. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/external/mem0_provider.py +303 -0
  134. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/external/openjiuwen_memory_provider.py +351 -0
  135. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/external/provider.py +53 -0
  136. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/__init__.py +11 -0
  137. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/__init__.py +7 -0
  138. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/base.py +113 -0
  139. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/custom_types.py +11 -0
  140. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/entity_type_definition.py +56 -0
  141. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/extraction_models.py +108 -0
  142. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/extraction_prompts.py +290 -0
  143. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/parse_response.py +93 -0
  144. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/__init__.py +10 -0
  145. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/__init__.py +7 -0
  146. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_check_missing_cn.pr.md +12 -0
  147. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_conversation_cn.pr.md +37 -0
  148. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_dedupe_entity_cn.pr.md +23 -0
  149. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_dedupe_relation_cn.pr.md +33 -0
  150. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_document_cn.pr.md +38 -0
  151. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_entity_merge_cn.pr.md +40 -0
  152. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_json_cn.pr.md +30 -0
  153. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_relation_cn.pr.md +49 -0
  154. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_relation_filter_cn.pr.md +26 -0
  155. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_summary_create_cn.pr.md +39 -0
  156. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/entity_extraction_timezone_cn.pr.md +14 -0
  157. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/cn/prompts.yaml +32 -0
  158. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/__init__.py +7 -0
  159. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_check_missing_en.pr.md +12 -0
  160. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_conversation_en.pr.md +37 -0
  161. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_dedupe_entity_en.pr.md +23 -0
  162. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_dedupe_relation_en.pr.md +35 -0
  163. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_document_en.pr.md +38 -0
  164. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_entity_merge_en.pr.md +40 -0
  165. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_json_en.pr.md +30 -0
  166. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_relation_en.pr.md +49 -0
  167. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_relation_filter_en.pr.md +26 -0
  168. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_summary_create_en.pr.md +39 -0
  169. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/entity_extraction_timezone_en.pr.md +14 -0
  170. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/en/prompts.yaml +32 -0
  171. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/entity_extraction/__init__.py +15 -0
  172. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/entity_extraction/base.py +142 -0
  173. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/entity_extraction/cn.py +91 -0
  174. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/entity_extraction/en.py +96 -0
  175. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/extraction/prompts/manager.py +109 -0
  176. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/__init__.py +0 -0
  177. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/base.py +1139 -0
  178. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/local_storage/__init__.py +10 -0
  179. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/parse_llm_response.py +282 -0
  180. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/postprocess_graph_objects.py +190 -0
  181. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/states.py +338 -0
  182. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/utils.py +86 -0
  183. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/graph/graph_memory/validate_input.py +82 -0
  184. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/long_term_memory.py +2339 -0
  185. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/__init__.py +0 -0
  186. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/__init__.py +0 -0
  187. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/base_memory_manager.py +155 -0
  188. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/fragment_memory_manager.py +449 -0
  189. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/middle_mem_manager.py +199 -0
  190. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/summary_manager.py +230 -0
  191. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/variable_manager.py +246 -0
  192. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/index/write_manager.py +94 -0
  193. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/__init__.py +0 -0
  194. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/data_id_manager.py +17 -0
  195. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/db_model.py +110 -0
  196. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/memory_unit.py +66 -0
  197. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/message_manager.py +105 -0
  198. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/scope_user_mapping_manager.py +41 -0
  199. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/semantic_store.py +310 -0
  200. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/sql_db_store.py +226 -0
  201. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/sql_message_store.py +306 -0
  202. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/mem_model/user_mem_store.py +260 -0
  203. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/search/__init__.py +0 -0
  204. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/search/search_manager.py +232 -0
  205. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/update/__init__.py +0 -0
  206. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/manage/update/mem_update_checker.py +297 -0
  207. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/__init__.py +0 -0
  208. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migration_plan.py +136 -0
  209. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/__init__.py +0 -0
  210. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/index_version_migrator.py +209 -0
  211. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/kv_migrator.py +291 -0
  212. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/memory_meta_manager.py +43 -0
  213. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/message_migrator.py +233 -0
  214. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/sql_migrator.py +338 -0
  215. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/migrator/vector_migrator.py +98 -0
  216. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/operation/__init__.py +0 -0
  217. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/operation/base_operation.py +35 -0
  218. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/operation/operation_registry.py +152 -0
  219. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/operation/operations.py +206 -0
  220. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/migration/run_migrations.py +162 -0
  221. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/__init__.py +0 -0
  222. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/dreaming/__init__.py +27 -0
  223. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/dreaming/orchestrator.py +100 -0
  224. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/dreaming/source.py +108 -0
  225. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/dreaming/store.py +127 -0
  226. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/dreaming/sweeper.py +159 -0
  227. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/extract/__init__.py +0 -0
  228. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/extract/common.py +25 -0
  229. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/extract/generation.py +447 -0
  230. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/extract/long_term_memory_extractor.py +122 -0
  231. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/extract/memory_analyzer.py +139 -0
  232. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/process/refine/__init__.py +0 -0
  233. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/__init__.py +0 -0
  234. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/continuity_check_system_prompt.md +16 -0
  235. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/dreaming_extraction.md +23 -0
  236. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/fragment_memory_prompt.md +109 -0
  237. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/memory_analysis_prompt.md +61 -0
  238. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/memory_update_check.md +53 -0
  239. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/prompt_applier.py +131 -0
  240. jiuwenmemory-0.1.0/jiuwen_memory/memory_core/prompts/semantic_validation.md +43 -0
  241. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/__init__.py +0 -0
  242. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/common/__init__.py +0 -0
  243. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/common/callbacks.py +61 -0
  244. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/common/config.py +81 -0
  245. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/embedding/__init__.py +0 -0
  246. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/embedding/api_embedding.py +358 -0
  247. jiuwenmemory-0.1.0/jiuwen_memory/retrieval/embedding/base.py +11 -0
  248. jiuwenmemory-0.1.0/jiuwen_memory/server/__init__.py +0 -0
  249. jiuwenmemory-0.1.0/jiuwen_memory/server/memory_server.py +459 -0
  250. jiuwenmemory-0.1.0/jiuwen_memory/server/store_factory.py +144 -0
  251. jiuwenmemory-0.1.0/pyproject.toml +152 -0
  252. jiuwenmemory-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,545 @@
1
+ Metadata-Version: 2.4
2
+ Name: JiuwenMemory
3
+ Version: 0.1.0
4
+ Summary: JiuwenMemory is a long-term memory module for AI agents, providing memory extraction, storage, retrieval, and migration capabilities.
5
+ Project-URL: Homepage, https://openjiuwen.com
6
+ Project-URL: Repository, https://gitcode.com/openJiuwen/agent-memory.git
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Programming Language :: Python :: Implementation :: CPython
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: <3.14,>=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: aiohttp>=3.11.12
19
+ Requires-Dist: httpx>=0.24
20
+ Requires-Dist: requests>=2.32.3
21
+ Requires-Dist: pydantic>=2.0
22
+ Requires-Dist: sqlalchemy>=2.0.41
23
+ Requires-Dist: sqlmodel>=0.0.37
24
+ Requires-Dist: alembic>=1.13.1
25
+ Requires-Dist: openai>=1.108.0
26
+ Requires-Dist: dashscope>=1.25.6
27
+ Requires-Dist: pymilvus<2.6.10,>=2.6.2
28
+ Requires-Dist: pycryptodome>=3.23.0
29
+ Requires-Dist: pyyaml>=6.0
30
+ Requires-Dist: tqdm>=4.0
31
+ Requires-Dist: oauthlib>=3.3.1
32
+ Requires-Dist: python-dotenv>=1.2.1
33
+ Requires-Dist: anyio>=4.0.0
34
+ Requires-Dist: loguru>=0.7.3
35
+ Requires-Dist: tenacity>=9.1.2
36
+ Requires-Dist: python-dateutil>=2.9.0
37
+ Requires-Dist: filelock>=3.20.1
38
+ Requires-Dist: aiofiles>=25.1.0
39
+ Requires-Dist: charset-normalizer>=3.4.4
40
+ Provides-Extra: chromadb
41
+ Requires-Dist: chromadb>=1.5.4; extra == "chromadb"
42
+ Requires-Dist: opentelemetry-proto>=1.33.0; extra == "chromadb"
43
+ Requires-Dist: protobuf<7.0,>=5.0; extra == "chromadb"
44
+ Provides-Extra: gaussvector
45
+ Requires-Dist: psycopg2-binary>=2.9.10; extra == "gaussvector"
46
+ Provides-Extra: elasticsearch
47
+ Requires-Dist: elasticsearch[async]<9,>=8; extra == "elasticsearch"
48
+ Provides-Extra: postgres
49
+ Requires-Dist: asyncpg>=0.30.0; extra == "postgres"
50
+ Provides-Extra: mysql
51
+ Requires-Dist: aiomysql>=0.3.2; extra == "mysql"
52
+ Provides-Extra: gaussdb
53
+ Requires-Dist: async-gaussdb~=0.30.0; extra == "gaussdb"
54
+ Requires-Dist: asyncpg>=0.29.0; extra == "gaussdb"
55
+ Provides-Extra: sqlite
56
+ Requires-Dist: aiosqlite>=0.22.1; extra == "sqlite"
57
+ Requires-Dist: greenlet>=3.1.1; extra == "sqlite"
58
+ Provides-Extra: redis
59
+ Requires-Dist: redis>=7.1.0; extra == "redis"
60
+ Provides-Extra: mem0
61
+ Requires-Dist: mem0ai>=1.0.0; extra == "mem0"
62
+ Provides-Extra: agentarts
63
+ Requires-Dist: agentarts-sdk<0.2,>=0.1.2; extra == "agentarts"
64
+ Provides-Extra: server
65
+ Requires-Dist: uvicorn>=0.30.0; extra == "server"
66
+ Requires-Dist: fastapi>=0.110.0; extra == "server"
67
+ Requires-Dist: python-dotenv>=1.2.1; extra == "server"
68
+ Provides-Extra: all-storage
69
+ Requires-Dist: JiuwenMemory[gaussdb,mysql,postgres,redis,sqlite]; extra == "all-storage"
70
+ Provides-Extra: all-vector
71
+ Requires-Dist: JiuwenMemory[chromadb,elasticsearch,gaussvector]; extra == "all-vector"
72
+ Provides-Extra: default
73
+ Provides-Extra: all
74
+ Requires-Dist: JiuwenMemory[all-storage,all-vector,server]; extra == "all"
75
+ Dynamic: license-file
76
+
77
+ # JiuwenMemory
78
+
79
+ [中文版](README.zh.md) | [English Version](README.md)
80
+
81
+ ## 1 Introduction
82
+
83
+ **JiuwenMemory** is an **AutoGenetic Memory** system open-sourced by the **openJiuwen community** and designed specifically for Agents — enabling a cognitive leap from "**information storage**" to "**autonomous growth**" for memory. Its core philosophy: in an AutoGenetic memory system, every memory acts like a **gene segment**, and the key technical capabilities are built around genetic memory's **precision, efficiency, and cross-organism replication**.
84
+
85
+ Agent conversational systems rely on limited context windows — once the Token limit is exceeded or a session restarts, information vanishes entirely. The team categorizes this "amnesia" into four perennial problems: users forced to repeat questions, lack of personalization, contradictory cross-session decisions, and experience perpetually stuck at zero with no accumulation. As large-model applications enter deeper waters, what determines an Agent's experience ceiling is no longer just "getting the right answer," but "being able to continuously remember the same person."
86
+
87
+ > "Model capabilities determine the 'lower bound of intelligence' for Agents; memory systems determine the 'upper bound of experience.'"
88
+
89
+ **JiuwenMemory** restructures AI memory from **passive information storage** into **governable, cross-platform shared, and self-evolving** core data assets — empowering Agents with the ability to truly "remember, understand, and serve users."
90
+
91
+ ## 2 Why Choose JiuwenMemory?
92
+
93
+ ### 🧠 Precise Memory Construction & Self-Evolution
94
+
95
+ - **Layered Memory Architecture (L0–L3)**: Four-tier progressive architecture — L0 Raw Information → L1 Summary Memory → L2 Structured Memory → L3 User Profile — with independent persistent storage per layer, progressively increasing information density and resolving long-dialogue memory loss and preference overwrite issues. Supports automatic extraction of UserProfile, SemanticMemory, EpisodicMemory, Variable, and Summary, with flexible custom variable definitions and prohibited variable configurations for precise user need matching.
96
+
97
+ - **Auto Dreaming (Sleep-Time Memory Consolidation)**: Three-stage sleep paradigm inspired by cognitive neuroscience (Light Sleep screening → REM extraction & classification → Deep Sleep deduplication & conflict resolution), with background daemon scheduling, busy-retreat deferment, and checkpoint-based incremental scanning for linearly controllable Token costs.
98
+
99
+ - **MemoryTurbo Acceleration**: Conversations write to cache instantly for immediate updates while memory extraction runs asynchronously in the background; small models merge conversations by topic for group extraction, ensuring coherence and significantly amortizing large model call costs.
100
+
101
+ - **Graph Memory (Knowledge Graph)**: Supports CONVERSATION/DOCUMENT/JSON multi-source writing, LLM-powered automatic entity and relationship extraction with merge deduplication, graph-structure retrieval, BFS expansion, and parallel Entity/Relationship/Episode retrieval with rerank scoring for precise knowledge localization.
102
+
103
+ ### 🔍 Efficient Memory Retrieval & Storage
104
+
105
+ - **Semantic Retrieval & Conflict Detection**: Unified cross-type vector semantic retrieval; `MemUpdateChecker` uses LLM to analyze semantic conflicts and intelligently decide ADD/DELETE strategies; LLM outputs UPDATE/DELETE directives validated via semantic checks before execution, ensuring memory consistency and controllable operations.
106
+
107
+ - **Full-Stack Storage Backend System**: Coverage across five storage categories — KV (InMemoryKV/ShelveStore/DbBasedKV/Redis), Vector (ChromaDB/Milvus/Elasticsearch/GaussVector), Relational (SQLite/PostgreSQL/MySQL/GaussDB), Message (SqlMessageStore), and Graph (Milvus GraphStore) — adapting from local single-node to cloud cluster scenarios.
108
+
109
+ - **Data Migration Framework**: Supports versioned schema migration for KV/vector/SQL/message/index stores and cross-BaseMemoryIndex batch data migration, with an operation registry for custom migration extensions.
110
+
111
+ ### 🔌 Ecosystem Integration & Extensibility
112
+
113
+ - **Dual-Dimension Decoupled Adapter Layer**: Plugin dimension (hook-based memory injection, supporting OpenClaw/openJiuwen) and Provider dimension (unified `MemoryProvider` interface with JiuwenMemory/Mem0) extend independently, enabling N × M free combination.
114
+
115
+ - **REST API Service & OpenClaw Plugin**: FastAPI complete REST API + bearer-token authentication for rapid backend integration; OpenClaw JavaScript lifecycle plugin for automatic memory storage and recall — zero-config, ready to use.
116
+
117
+ ### 🔒 Security & Privacy Hardening
118
+
119
+ - **AES-256-GCM Encryption**: Transparent encryption for memory data and API Keys to safeguard privacy, with automatic encryption protection for sensitive information to prevent unauthorized access.
120
+
121
+ - **Distributed Lock & Concurrency Consistency**: Distributed lock mechanism based on KV storage, ensuring atomicity and consistency of user-level data operations under multi-instance concurrent scenarios.
122
+
123
+ - **Multi-Tenant Security Isolation**: Independent LLM/embedding/extraction rule configuration per `scope_id` with encrypted storage, achieving secure isolation of both data and configuration across tenants.
124
+
125
+ ## 3 Quick Start
126
+
127
+ ### Installation
128
+
129
+ - Operating System: Compatible with Windows, Linux, and macOS.
130
+ - Python Version: Python version should be 3.11 or higher, but lower than 3.14. Please check your Python version before use, Python 3.11.4 is recommended.
131
+
132
+ **Install from PyPI**
133
+
134
+ ```bash
135
+ pip install -U JiuwenMemory
136
+ ```
137
+
138
+ **Install Optional Storage Backends**
139
+
140
+ ```bash
141
+ # SQLite support
142
+ pip install JiuwenMemory[sqlite]
143
+
144
+ # PostgreSQL support
145
+ pip install JiuwenMemory[postgres]
146
+
147
+ # MySQL support
148
+ pip install JiuwenMemory[mysql]
149
+
150
+ # GaussDB support
151
+ pip install JiuwenMemory[gaussdb]
152
+
153
+ # Redis support
154
+ pip install JiuwenMemory[redis]
155
+
156
+ # ChromaDB vector store
157
+ pip install JiuwenMemory[chromadb]
158
+
159
+ # Memory server (includes uvicorn + fastapi; enables `memory-server` CLI command)
160
+ pip install JiuwenMemory[server]
161
+
162
+ # Install all storage backends (includes server)
163
+ pip install JiuwenMemory[all]
164
+ ```
165
+
166
+ ### Example
167
+
168
+ Let's create a simple long-term memory instance, register storage backends, add conversation messages, and retrieve memories:
169
+
170
+ ```python
171
+ import asyncio
172
+ import tempfile
173
+ from sqlalchemy.ext.asyncio import create_async_engine
174
+ from jiuwen_memory.memory_core import LongTermMemory
175
+ from jiuwen_memory.memory_core.config.config import MemoryEngineConfig, MemoryScopeConfig, AgentMemoryConfig, DreamingConfig
176
+ from jiuwen_memory.foundation.llm.schema.config import ModelClientConfig, ModelRequestConfig
177
+ from jiuwen_memory.foundation.llm import UserMessage, AssistantMessage
178
+ from jiuwen_memory.foundation.store.kv.in_memory_kv_store import InMemoryKVStore
179
+ from jiuwen_memory.foundation.store.db.default_db_store import DefaultDbStore
180
+ from jiuwen_memory.foundation.store.vector.chroma_vector_store import ChromaVectorStore
181
+ from jiuwen_memory.retrieval.embedding.api_embedding import APIEmbedding
182
+ from jiuwen_memory.retrieval.common.config import EmbeddingConfig
183
+
184
+ # ============== Configuration: set directly in code, no .env required ==============
185
+ # LLM configuration
186
+ MODEL_PROVIDER = "xxxx"
187
+ API_BASE = "xxxx"
188
+ API_KEY = "xxxx"
189
+ MODEL_NAME = "xxxx"
190
+
191
+ # Embedding configuration
192
+ EMBED_MODEL_NAME = "xxxx"
193
+ EMBED_API_BASE = "xxxx"
194
+ EMBED_API_KEY = "xxxx"
195
+ # ====================================================================================
196
+
197
+
198
+ async def main():
199
+ # Get the LongTermMemory singleton
200
+ memory = LongTermMemory()
201
+
202
+ # Create LLM configuration
203
+ model_client_config = ModelClientConfig(
204
+ client_provider=MODEL_PROVIDER,
205
+ api_key=API_KEY,
206
+ api_base=API_BASE,
207
+ verify_ssl=False,
208
+ )
209
+ model_config = ModelRequestConfig(
210
+ model=MODEL_NAME
211
+ )
212
+
213
+ # Create storage backends (example uses in-memory KV, SQLite, and ChromaDB)
214
+ kv_store = InMemoryKVStore()
215
+ engine = create_async_engine("sqlite+aiosqlite:///./memory.db")
216
+ db_store = DefaultDbStore(engine)
217
+ vector_store = ChromaVectorStore(persist_directory=tempfile.mkdtemp())
218
+
219
+ # Create embedding model
220
+ embedding_config = EmbeddingConfig(
221
+ model_name=EMBED_MODEL_NAME,
222
+ base_url=EMBED_API_BASE,
223
+ api_key=EMBED_API_KEY,
224
+ )
225
+ embedding_model = APIEmbedding(config=embedding_config)
226
+
227
+ # Register storage backends
228
+ await memory.register_store(
229
+ kv_store=kv_store,
230
+ db_store=db_store,
231
+ vector_store=vector_store,
232
+ embedding_model=embedding_model,
233
+ )
234
+
235
+ # Configure memory engine
236
+ engine_config = MemoryEngineConfig(
237
+ default_model_cfg=model_config,
238
+ default_model_client_cfg=model_client_config,
239
+ )
240
+ memory.set_config(engine_config)
241
+
242
+ # Configure scope
243
+ scope_config = MemoryScopeConfig(
244
+ model_cfg=model_config,
245
+ model_client_cfg=model_client_config,
246
+ embedding_cfg=embedding_config,
247
+ )
248
+ await memory.set_scope_config(scope_id="my_app", memory_scope_config=scope_config)
249
+
250
+ # Configure agent memory
251
+ agent_config = AgentMemoryConfig(
252
+ enable_long_term_mem=True,
253
+ enable_user_profile=True,
254
+ enable_semantic_memory=True,
255
+ enable_episodic_memory=True,
256
+ enable_summary_memory=True,
257
+ )
258
+
259
+ # Feed the conversation turn by turn — each turn is stored and extracted online in real time.
260
+ conversation = [
261
+ ("I'm a data analyst; I use pandas on our sales data, but my pipeline has gotten slow.",
262
+ "You could try Polars — it's usually 5-10x faster than pandas and great for large datasets."),
263
+ ("I also enjoy basketball and reading sci-fi novels.",
264
+ "Nice balance! For hard sci-fi, Liu Cixin's 'The Three-Body Problem' is worth a read."),
265
+ ("This afternoon I played basketball with friends at the park, it was really fun.",
266
+ "Sounds like a great afternoon!"),
267
+ ]
268
+ for user_text, assistant_text in conversation:
269
+ await memory.add_messages(
270
+ messages=[UserMessage(content=user_text), AssistantMessage(content=assistant_text)],
271
+ agent_config=agent_config,
272
+ user_id="user_001",
273
+ scope_id="my_app",
274
+ session_id="session_001",
275
+ )
276
+
277
+ query = "how to speed up data processing"
278
+
279
+ # Print all of this user's memories, then run one semantic search.
280
+ async def show():
281
+ print(" memories:")
282
+ page = await memory.get_user_mem_by_page(user_id="user_001", scope_id="my_app", page_size=50)
283
+ for m in page:
284
+ print(f" [{m.type.value}] {m.content}")
285
+ print(" search:")
286
+ for res in await memory.search_user_mem(query=query, num=5, user_id="user_001", scope_id="my_app"):
287
+ print(f" {res.mem_info.content} (relevance: {res.score:.2f})")
288
+
289
+ await show()
290
+
291
+ asyncio.run(main())
292
+ ```
293
+
294
+ Expected Output (memory content is LLM-generated, so wording will vary):
295
+ ```
296
+ memories:
297
+ [user_profile] User is a data analyst
298
+ [user_profile] User uses pandas on sales data
299
+ [user_profile] User enjoys basketball
300
+ [user_profile] User enjoys reading sci-fi novels
301
+ [episodic_memory] User played basketball with friends at the park on the afternoon of 2026-06-18 # date reflects the run date and will vary
302
+ search:
303
+ User uses pandas on sales data (relevance: 0.80)
304
+ ```
305
+
306
+ > Dreaming writes the same memory types through the same path as online extraction — so its
307
+ > output is ordinary `user_profile` / `semantic_memory` / `episodic_memory`, retrieved by the
308
+ > same `search_user_mem`. Its added value here is the **Polars tip**: a reusable fact the
309
+ > assistant supplied that the narrow per-turn window skipped, which the full-session sweep
310
+ > consolidates into memory.
311
+
312
+ ## 4 Architecture Design
313
+
314
+ **JiuwenMemory** serves as the core module of the memory architecture. In this open-source version, the core capabilities include:
315
+
316
+ * **Memory Processing Layer**: Through intelligent analysis of conversation messages, automatically extracts five types of memory — user profile (UserProfile), semantic memory (SemanticMemory), episodic memory (EpisodicMemory), variable (Variable), and summary (Summary) — and supports custom extraction rules and instruct-based memory operations (add, update, delete).
317
+
318
+ * **Memory Management Layer**: Provides differentiated management strategies for different memory types, including FragmentMemoryManager, VariableManager, and SummaryManager, coordinated through WriteManager and SearchManager for unified read/write operations.
319
+
320
+ * **Storage Foundation Layer**: Provides abstract interfaces for four types of storage — KV store, vector store, relational database, and message store — supporting flexible integration with multiple storage backends, and ensuring smooth data schema upgrades through the versioned migration framework.
321
+
322
+ * **Graph Memory Layer**: Graph Memory uses LLMs to extract entities (Entity), relations (Relation), and source episodes (Episode) from conversations, documents, or JSON strings, then performs entity merging, relation deduplication, and graph-structured retrieval. It is currently used as an independent module and is not wired into the `LongTermMemory.add_messages` pipeline.
323
+
324
+ * **External Integration Layer**: Through the MemoryProvider abstract interface, supports seamless integration with third-party memory services such as Mem0, AgentArts, openJiuwen, and openViking, providing unified tool calling and session synchronization mechanisms.
325
+
326
+ ## 5 Features
327
+
328
+ ### **Layered Memory System (L0–L3)**
329
+
330
+ **JiuwenMemory** introduces a four-tier progressive architecture with independent persistent storage per layer, progressively increasing information density and resolving long-dialogue memory loss and preference overwrite issues:
331
+
332
+ - **L0 — Raw Information**: Original conversation messages stored verbatim as the foundation layer.
333
+ - **L1 — Summary Memory**: Per-turn and incremental summaries that compress conversation context.
334
+ - **L2 — Structured Memory**: Automatically extracted SemanticMemory, EpisodicMemory, and Variable units — factual knowledge and event records organized by type.
335
+ - **L3 — User Profile**: Consolidated affirmative/negative statements about the user (identity, preferences, relationships, assets, etc.), forming a personalized long-term portrait.
336
+
337
+ Supports flexible custom variable definitions and prohibited variable configurations for precise user need matching.
338
+
339
+ ### **Dreaming (Sleep-Time Memory Consolidation)**
340
+
341
+ Online extraction (`add_messages`) only ever sees a single turn. **Dreaming** is an optional background service that periodically re-reads a user's stored sessions, distills durable knowledge from them, and writes it back through the same path as online extraction — dreamed memories are ordinary user profile / semantic / episodic units, with no new memory type or storage field.
342
+
343
+ - **Three-stage sleep paradigm**: Inspired by cognitive neuroscience — Light Sleep screening → REM extraction & classification → Deep Sleep deduplication & conflict resolution — mirroring how human memory consolidates during sleep.
344
+ - **Fire-and-forget lifecycle**: `start_dreaming(scope_id, user_id, config=DreamingConfig(enabled=True))` launches a background scheduler (idempotent per `(scope_id, user_id)`); `stop_dreaming()` stops it. Disabled by default.
345
+ - **Tunable via `DreamingConfig`**: sweep interval (`interval_seconds`), session pre-filters (`min_session_rounds`, `max_sessions_per_sweep`), and extraction caps (`max_compress_tokens`, `max_items_per_session`).
346
+ - **Busy-retreat deferment**: Automatically backs off when the system is under heavy load, avoiding interference with online serving.
347
+ - **Checkpointed and concurrency-safe**: Incremental scanning with checkpoint-based progress tracking that survives restarts; writes take the same user-level lock as `add_messages` and reuse semantic conflict detection, so online and offline writes never collide or duplicate.
348
+
349
+ ### **MemoryTurbo Acceleration**
350
+
351
+ Conversations write to cache instantly for immediate updates while memory extraction runs asynchronously in the background. Small models merge conversations by topic for group extraction, ensuring coherence and significantly amortizing large model call costs — the memory flywheel spins faster with less fuel.
352
+
353
+ - **Momentum Decoupling**: Breaks the serial pipeline — raw conversations write to the cache-layer vector store instantly for immediate updates, while memory extraction runs asynchronously in the background based on priority and compute load, reducing perceived user latency by 92%.
354
+ - **Centrifugal Semantic Clustering**: Before asynchronous extraction, a small model groups and merges conversations by topic for batch extraction. This preserves topic coherence and avoids semantic drift caused by multiple separate LLM calls; compared to traditional per-turn extraction, it significantly amortizes both the number of extraction calls and Token consumption.
355
+ - **Early Retrieval & Precision Guarantee**: Retrieval is available even before background extraction completes — cached raw conversations carry vector embeddings and are searchable. Results are merged from both the cache layer and the extraction layer, ensuring reduced latency without sacrificing precision.
356
+
357
+ ### **Semantic Retrieval and Conflict Detection**
358
+
359
+ - **Vector Semantic Search**: Unified cross-memory-type vector retrieval based on embedding models, with similarity threshold filtering and ranking mechanisms.
360
+ - **MemUpdateChecker**: Uses LLM to analyze semantic conflicts and intelligently decide ADD/DELETE strategies — before writing new memories, automatically detects semantic conflicts with existing memories to ensure memory consistency.
361
+ - **Instruct-based Memory Operations**: Supports updating and deleting existing memories through LLM output UPDATE/DELETE instructions, validated via semantic checks before execution, ensuring operational accuracy and controllable operations.
362
+
363
+ ### **Graph Memory (Knowledge Graph Memory)**
364
+
365
+ Graph Memory is an independent knowledge graph memory module. It turns input content into a graph of entities, relations, and source episodes, suitable for relationship retrieval, entity tracking, and graph expansion recall.
366
+
367
+ - **Multi-source writes**: Supports conversation, document, and JSON-string `EpisodeType` inputs, and stores the original source as an Episode.
368
+ - **Entity and relation extraction**: Uses an LLM to extract entity declarations, entity summaries, attributes, relations, and relation validity times.
369
+ - **Merging and deduplication**: Recalls existing entities and relations during writes, performs entity merging, relation filtering, and semantic deduplication.
370
+ - **Graph-structured retrieval**: Searches entity, relation, and Episode collections in parallel, with configurable hybrid ranking, rerank, and BFS expansion for entity/relation results.
371
+
372
+ [→ Graph Memory API Docs](docs/en/API%20Docs/graph_memory.md)
373
+
374
+ ### **Flexible Storage Backends and Data Migration**
375
+
376
+ - **Full-Stack Storage Backends**: Coverage across five storage categories — KV (InMemoryKV/ShelveStore/DbBasedKV/Redis), Vector (ChromaDB/Milvus/Elasticsearch/GaussVector), Relational (SQLite/PostgreSQL/MySQL/GaussDB), Message (SqlMessageStore), and Graph (Milvus GraphStore) — adapting from local single-node to cloud cluster scenarios.
377
+ - **Versioned Migration**: A complete migration framework supporting SQL schema changes, vector field renaming, KV data updates, message data transformation, and index field operations.
378
+ - **Cross-index Migration**: Supports batch migration of memory data between different BaseMemoryIndex instances for smooth storage engine switching, with an operation registry for custom migration extensions.
379
+
380
+ ### **Security and Concurrency Control**
381
+
382
+ - **AES-256-GCM Encryption**: Transparent encryption for memory data and API Keys to safeguard privacy, with automatic encryption protection for sensitive information.
383
+ - **Distributed Lock**: Distributed lock mechanism based on KV storage, ensuring atomicity and consistency of user-level data operations under multi-instance concurrent scenarios.
384
+ - **Multi-Tenant Scope Isolation**: Supports memory data isolation by `scope_id`, with each scope independently configurable for LLM, embedding model, and extraction rules — configuration data is encrypted and stored separately for multi-tenant security isolation.
385
+
386
+ ### **Dual-Dimension Decoupled Adapter Layer**
387
+
388
+ JiuwenMemory decouples Agent platforms from the memory engine through two independent dimensions:
389
+
390
+ - **Plugin Dimension**: Hook-based memory injection, supporting JiuwenSwarm/OpenClaw/openJiuwen — injects relevant context before agent replies and captures exchanges after replies.
391
+ - **Provider Dimension**: Unified `MemoryProvider` interface, supporting JiuwenMemory/Mem0/openViking/AgentArts — any provider can be swapped without changing agent code.
392
+
393
+ The two dimensions extend independently, enabling N × M free combination of platforms and providers.
394
+
395
+ ### **Multi-Model LLM Clients**
396
+
397
+ Supports OpenAI, DashScope, DeepSeek, SiliconFlow, OpenRouter, InferenceAffinity, IntelliRouter, and more — flexible selection of the optimal inference engine for your deployment scenario.
398
+
399
+ ## 6 Memory Service & OpenClaw Plugin
400
+
401
+ A ready-to-run memory backend and an OpenClaw plugin that give agents persistent, searchable memory — zero extra code.
402
+
403
+ ### Memory Service
404
+
405
+ One command to start a local memory engine backed by REST APIs:
406
+
407
+ - **Memory CRUD** — add messages, update/delete memories, manage key-value variables.
408
+ - **Semantic search** — retrieves memories by meaning, not keywords.
409
+ - **Zero config** — install `JiuwenMemory[server]`, drop your LLM + embedding keys into `~/.jiuwenmemory/.env`, and run `memory-server`.
410
+
411
+ ```bash
412
+ # Install the memory server
413
+ pip install JiuwenMemory[server]
414
+
415
+ # Create config directory and edit .env (see server/.env.example in the source repo for a template)
416
+ mkdir -p ~/.jiuwenmemory
417
+ cp server/.env.example ~/.jiuwenmemory/.env # or create manually
418
+ vim ~/.jiuwenmemory/.env # fill in API keys and backend config
419
+
420
+ # Start the server
421
+ memory-server
422
+
423
+ # Source-code launch (still works during development)
424
+ python -m server.memory_server
425
+ ```
426
+
427
+ Configuration and data are stored under `~/.jiuwenmemory/`:
428
+
429
+ ```
430
+ ~/.jiuwenmemory/
431
+ ├── .env ← environment config (LLM / embedding / storage backends)
432
+ ├── memory_data/ ← data directory (SQLite / ChromaDB, auto-created)
433
+ ```
434
+
435
+ ### OpenClaw Plugin
436
+
437
+ Auto-memory for OpenClaw agents — remembers what users said and recalls it before every reply.
438
+
439
+ - **Recall before reply** — injects relevant context so the agent never starts from scratch.
440
+ - **Store after reply** — captures every exchange and extracts structured memories in the background.
441
+
442
+ [→ Full setup guide](agent-memory-plugin/JiuwenMemory-OpenClaw/README.md)
443
+
444
+ ## 7 Project Structure
445
+
446
+ ```
447
+ agent-memory/
448
+ ├── jiuwen_memory/ # Main package
449
+ │ ├── memory_core/ # Core memory module
450
+ │ │ ├── long_term_memory.py # Long-term memory engine entry
451
+ │ │ ├── config/ # Configuration management
452
+ │ │ │ ├── config.py # Engine config, scope config, agent config
453
+ │ │ │ └── graph.py # Graph Memory write and search strategy config
454
+ │ │ ├── manage/ # Memory management
455
+ │ │ │ ├── index/ # Memory managers
456
+ │ │ │ │ ├── base_memory_manager.py # Base manager class
457
+ │ │ │ │ ├── fragment_memory_manager.py # Fragment memory manager
458
+ │ │ │ │ ├── variable_manager.py # Variable manager
459
+ │ │ │ │ ├── summary_manager.py # Summary manager
460
+ │ │ │ │ └── write_manager.py # Write manager
461
+ │ │ │ ├── search/ # Search management
462
+ │ │ │ │ └── search_manager.py # Search manager
463
+ │ │ │ ├── update/ # Update detection
464
+ │ │ │ └── mem_model/ # Data models
465
+ │ │ │ ├── memory_unit.py # Memory unit definitions
466
+ │ │ │ ├── db_model.py # Database models
467
+ │ │ │ └── sql_db_store.py # SQL database store
468
+ │ │ ├── process/ # Memory processing
469
+ │ │ │ ├── extract/ # Memory extraction
470
+ │ │ │ │ ├── generation.py # Memory generator
471
+ │ │ │ │ ├── long_term_memory_extractor.py # Long-term memory extractor
472
+ │ │ │ │ └── memory_analyzer.py # Memory analyzer
473
+ │ │ │ ├── dreaming/ # Offline memory consolidation
474
+ │ │ │ │ ├── orchestrator.py # Background sweep scheduler
475
+ │ │ │ │ ├── source.py # Session source (reads message store)
476
+ │ │ │ │ ├── sweeper.py # Compress -> extract -> promote pipeline
477
+ │ │ │ │ └── store.py # Writes distilled knowledge as memory units
478
+ │ │ │ └── refine/ # Memory refinement
479
+ │ │ ├── graph/ # Knowledge graph memory
480
+ │ │ │ ├── graph_memory/ # GraphMemory write, search, and state management
481
+ │ │ │ └── extraction/ # Entity/relation extraction models and prompts
482
+ │ │ ├── prompts/ # Prompt management
483
+ │ │ │ └── prompt_applier.py # Prompt template engine
484
+ │ │ ├── codec/ # Encoding/decoding
485
+ │ │ │ └── aes_storage_codec.py # AES encryption codec
486
+ │ │ ├── migration/ # Data migration
487
+ │ │ │ ├── migration_plan.py # Migration plan and registry
488
+ │ │ │ ├── migrator/ # Various migrators
489
+ │ │ │ └── operation/ # Migration operation definitions
490
+ │ │ ├── external/ # External integrations
491
+ │ │ │ ├── provider.py # MemoryProvider abstract interface
492
+ │ │ │ ├── mem0_provider.py # Mem0 integration
493
+ │ │ │ ├── agentarts_memory_provider.py # AgentArts integration
494
+ │ │ │ ├── openjiuwen_memory_provider.py # openJiuwen integration
495
+ │ │ │ └── openviking_memory_provider.py # openViking integration
496
+ │ │ └── common/ # Common utilities
497
+ │ │ ├── distributed_lock.py # Distributed lock
498
+ │ │ └── kv_prefix_registry.py # KV prefix registry
499
+ │ ├── foundation/ # Foundation capabilities
500
+ │ │ ├── llm/ # LLM invocation
501
+ │ │ │ ├── model.py # Unified model interface
502
+ │ │ │ └── model_clients/ # Various model clients
503
+ │ │ ├── store/ # Storage abstractions
504
+ │ │ │ ├── base_kv_store.py # KV store base class
505
+ │ │ │ ├── base_vector_store.py # Vector store base class
506
+ │ │ │ ├── base_db_store.py # Database store base class
507
+ │ │ │ ├── base_message_store.py # Message store base class
508
+ │ │ │ ├── base_memory_index.py # Memory index base class
509
+ │ │ │ └── graph/ # Graph store abstraction and Milvus implementation
510
+ │ │ ├── prompt/ # Prompt templates
511
+ │ │ └── tool/ # Tool definitions
512
+ │ ├── retrieval/ # Retrieval capabilities
513
+ │ │ └── embedding/ # Embedding models
514
+ │ ├── common/ # Common components
515
+ │ │ ├── security/ # Security utilities
516
+ │ │ ├── logging/ # Logging management
517
+ │ │ ├── exception/ # Exception handling
518
+ │ │ └── utils/ # General utilities
519
+ │ ├── server/ # Memory service (FastAPI)
520
+ │ │ ├── __init__.py # Package init
521
+ │ │ ├── memory_server.py # HTTP API server (CLI entry point main())
522
+ │ │ ├── store_factory.py # Storage backend factory
523
+ │ │ └── .env.example # Environment config template
524
+ │ └── agent-memory-plugin/ # OpenClaw lifecycle plugin
525
+ │ ├── lib/ # Plugin library
526
+ │ │ └── openjiuwen-memory-api.js # Memory API client
527
+ │ ├── openjiuwen-memory-index.js # Plugin entry point
528
+ │ ├── openclaw.plugin.json # Plugin manifest
529
+ │ ├── package.json # npm package config
530
+ │ └── README.md # Plugin documentation
531
+ ├── docs/ # Documentation
532
+ └── tests/ # Test cases
533
+ ```
534
+
535
+ ## Contributing
536
+
537
+ We welcome all forms of contributions, including but not limited to:
538
+ - Submitting issues and feature suggestions
539
+ - Improving documentation
540
+ - Submitting code
541
+ - Sharing usage experiences
542
+
543
+ ## Open Source License
544
+
545
+ This project is licensed under the Apache-2.0 License.