hy-memory 2.0.5.dev1__py3-none-any.whl → 2.0.5.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hy_memory/client.py +194 -0
- {hy_memory-2.0.5.dev1.dist-info → hy_memory-2.0.5.dev2.dist-info}/METADATA +1 -1
- {hy_memory-2.0.5.dev1.dist-info → hy_memory-2.0.5.dev2.dist-info}/RECORD +6 -6
- {hy_memory-2.0.5.dev1.dist-info → hy_memory-2.0.5.dev2.dist-info}/WHEEL +0 -0
- {hy_memory-2.0.5.dev1.dist-info → hy_memory-2.0.5.dev2.dist-info}/licenses/LICENSE +0 -0
- {hy_memory-2.0.5.dev1.dist-info → hy_memory-2.0.5.dev2.dist-info}/top_level.txt +0 -0
hy_memory/client.py
CHANGED
|
@@ -2936,6 +2936,49 @@ class HyMemoryClient:
|
|
|
2936
2936
|
include_runtime_diag=True,
|
|
2937
2937
|
)
|
|
2938
2938
|
|
|
2939
|
+
def import_memory_exact(
|
|
2940
|
+
self,
|
|
2941
|
+
content: str,
|
|
2942
|
+
*,
|
|
2943
|
+
memory_id: str,
|
|
2944
|
+
user_id: str,
|
|
2945
|
+
agent_id: str = "default_agent",
|
|
2946
|
+
session_id: str = "default_session",
|
|
2947
|
+
source: str = "default",
|
|
2948
|
+
layer: Any = "l2_fact",
|
|
2949
|
+
status: Any = "active",
|
|
2950
|
+
owner: Optional[str] = None,
|
|
2951
|
+
tags: Optional[List[str]] = None,
|
|
2952
|
+
supersedes: Optional[List[str]] = None,
|
|
2953
|
+
superseded_by: Optional[List[str]] = None,
|
|
2954
|
+
is_latest: bool = True,
|
|
2955
|
+
memory_at: Optional[datetime] = None,
|
|
2956
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
2957
|
+
request_id: Optional[str] = None,
|
|
2958
|
+
) -> Dict[str, Any]:
|
|
2959
|
+
"""Import one existing semantic memory without extraction/reconcile."""
|
|
2960
|
+
return self._loop_thread.run(
|
|
2961
|
+
self.async_import_memory_exact(
|
|
2962
|
+
content,
|
|
2963
|
+
memory_id=memory_id,
|
|
2964
|
+
user_id=user_id,
|
|
2965
|
+
agent_id=agent_id,
|
|
2966
|
+
session_id=session_id,
|
|
2967
|
+
source=source,
|
|
2968
|
+
layer=layer,
|
|
2969
|
+
status=status,
|
|
2970
|
+
owner=owner,
|
|
2971
|
+
tags=tags,
|
|
2972
|
+
supersedes=supersedes,
|
|
2973
|
+
superseded_by=superseded_by,
|
|
2974
|
+
is_latest=is_latest,
|
|
2975
|
+
memory_at=memory_at,
|
|
2976
|
+
metadata=metadata,
|
|
2977
|
+
request_id=request_id,
|
|
2978
|
+
),
|
|
2979
|
+
include_runtime_diag=True,
|
|
2980
|
+
)
|
|
2981
|
+
|
|
2939
2982
|
def get_raw(self, raw_id: str) -> Optional[Dict[str, Any]]:
|
|
2940
2983
|
"""Read one SDK raw record through the explicit raw API."""
|
|
2941
2984
|
return self._loop_thread.run(self.async_get_raw(raw_id))
|
|
@@ -3223,6 +3266,157 @@ class HyMemoryClient:
|
|
|
3223
3266
|
raise RuntimeError("raw import changed the requested identity")
|
|
3224
3267
|
return {"success": True, "raw_id": node_id, "request_id": request_id}
|
|
3225
3268
|
|
|
3269
|
+
@_ensure_internal_loop
|
|
3270
|
+
async def async_import_memory_exact(
|
|
3271
|
+
self,
|
|
3272
|
+
content: str,
|
|
3273
|
+
*,
|
|
3274
|
+
memory_id: str,
|
|
3275
|
+
user_id: str,
|
|
3276
|
+
agent_id: str = "default_agent",
|
|
3277
|
+
session_id: str = "default_session",
|
|
3278
|
+
source: str = "default",
|
|
3279
|
+
layer: Any = "l2_fact",
|
|
3280
|
+
status: Any = "active",
|
|
3281
|
+
owner: Optional[str] = None,
|
|
3282
|
+
tags: Optional[List[str]] = None,
|
|
3283
|
+
supersedes: Optional[List[str]] = None,
|
|
3284
|
+
superseded_by: Optional[List[str]] = None,
|
|
3285
|
+
is_latest: bool = True,
|
|
3286
|
+
memory_at: Optional[datetime] = None,
|
|
3287
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
3288
|
+
request_id: Optional[str] = None,
|
|
3289
|
+
) -> Dict[str, Any]:
|
|
3290
|
+
"""Import a canonical memory node exactly, with no model invocation."""
|
|
3291
|
+
from .models.memory import MemoryLayer, MemoryStatus
|
|
3292
|
+
from .utils.source_filter import normalize_source
|
|
3293
|
+
|
|
3294
|
+
if not content or not memory_id or not user_id:
|
|
3295
|
+
raise ValueError("content, memory_id and user_id are required")
|
|
3296
|
+
normalized_layer = (
|
|
3297
|
+
layer if isinstance(layer, MemoryLayer) else MemoryLayer.from_string(str(layer))
|
|
3298
|
+
)
|
|
3299
|
+
if normalized_layer == MemoryLayer.L1_RAW:
|
|
3300
|
+
raise ValueError("use import_raw for L1_RAW")
|
|
3301
|
+
normalized_status = (
|
|
3302
|
+
status if isinstance(status, MemoryStatus) else MemoryStatus(str(status).lower())
|
|
3303
|
+
)
|
|
3304
|
+
request_id = request_id or str(uuid.uuid4())
|
|
3305
|
+
replay = await self._claim_write_outcome(
|
|
3306
|
+
request_id=request_id,
|
|
3307
|
+
user_id=user_id,
|
|
3308
|
+
agent_id=agent_id,
|
|
3309
|
+
session_id=session_id,
|
|
3310
|
+
operation="import_memory_exact",
|
|
3311
|
+
)
|
|
3312
|
+
if replay is not None:
|
|
3313
|
+
return replay
|
|
3314
|
+
try:
|
|
3315
|
+
result = await self._async_import_memory_exact_impl(
|
|
3316
|
+
content,
|
|
3317
|
+
memory_id=memory_id,
|
|
3318
|
+
user_id=user_id,
|
|
3319
|
+
agent_id=agent_id,
|
|
3320
|
+
session_id=session_id,
|
|
3321
|
+
source=normalize_source(source),
|
|
3322
|
+
layer=normalized_layer,
|
|
3323
|
+
status=normalized_status,
|
|
3324
|
+
owner=owner,
|
|
3325
|
+
tags=tags or [],
|
|
3326
|
+
supersedes=supersedes or [],
|
|
3327
|
+
superseded_by=superseded_by or [],
|
|
3328
|
+
is_latest=is_latest,
|
|
3329
|
+
memory_at=memory_at,
|
|
3330
|
+
metadata=metadata,
|
|
3331
|
+
request_id=request_id,
|
|
3332
|
+
)
|
|
3333
|
+
except BaseException:
|
|
3334
|
+
await self._mark_write_outcome_unknown(request_id)
|
|
3335
|
+
raise
|
|
3336
|
+
await self._finish_write_outcome(request_id, "succeeded", result)
|
|
3337
|
+
return result
|
|
3338
|
+
|
|
3339
|
+
async def _async_import_memory_exact_impl(
|
|
3340
|
+
self,
|
|
3341
|
+
content: str,
|
|
3342
|
+
*,
|
|
3343
|
+
memory_id: str,
|
|
3344
|
+
user_id: str,
|
|
3345
|
+
agent_id: str,
|
|
3346
|
+
session_id: str,
|
|
3347
|
+
source: str,
|
|
3348
|
+
layer,
|
|
3349
|
+
status,
|
|
3350
|
+
owner: Optional[str],
|
|
3351
|
+
tags: List[str],
|
|
3352
|
+
supersedes: List[str],
|
|
3353
|
+
superseded_by: List[str],
|
|
3354
|
+
is_latest: bool,
|
|
3355
|
+
memory_at: Optional[datetime],
|
|
3356
|
+
metadata: Optional[Dict[str, Any]],
|
|
3357
|
+
request_id: str,
|
|
3358
|
+
) -> Dict[str, Any]:
|
|
3359
|
+
from .models.memory import MemoryNode, SourceType
|
|
3360
|
+
|
|
3361
|
+
existing = await self._vector_store.get_by_id(memory_id)
|
|
3362
|
+
if existing is not None:
|
|
3363
|
+
identity = (
|
|
3364
|
+
existing.content == content,
|
|
3365
|
+
existing.user_id == user_id,
|
|
3366
|
+
existing.agent_id == agent_id,
|
|
3367
|
+
existing.session_id == session_id,
|
|
3368
|
+
existing.source == source,
|
|
3369
|
+
existing.layer == layer,
|
|
3370
|
+
existing.status == status,
|
|
3371
|
+
existing.owner == owner,
|
|
3372
|
+
list(existing.tags or []) == tags,
|
|
3373
|
+
list(existing.supersedes or []) == supersedes,
|
|
3374
|
+
list(existing.superseded_by or []) == superseded_by,
|
|
3375
|
+
existing.is_latest == is_latest,
|
|
3376
|
+
)
|
|
3377
|
+
if not all(identity):
|
|
3378
|
+
raise ValueError("memory_id is already bound to different memory content")
|
|
3379
|
+
return {
|
|
3380
|
+
"success": True,
|
|
3381
|
+
"memory_id": memory_id,
|
|
3382
|
+
"memory_ids": [memory_id],
|
|
3383
|
+
"request_id": request_id,
|
|
3384
|
+
"replayed": True,
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
custom = dict(metadata or {})
|
|
3388
|
+
custom["request_id"] = request_id
|
|
3389
|
+
custom["input_kind"] = "memory_exact_import"
|
|
3390
|
+
embedding = await self._embed_service.embed(content)
|
|
3391
|
+
node = MemoryNode(
|
|
3392
|
+
node_id=memory_id,
|
|
3393
|
+
user_id=user_id,
|
|
3394
|
+
agent_id=agent_id,
|
|
3395
|
+
session_id=session_id,
|
|
3396
|
+
source=source,
|
|
3397
|
+
layer=layer,
|
|
3398
|
+
content=content,
|
|
3399
|
+
source_type=SourceType.EXPLICIT,
|
|
3400
|
+
status=status,
|
|
3401
|
+
owner=owner,
|
|
3402
|
+
tags=list(tags),
|
|
3403
|
+
supersedes=list(supersedes),
|
|
3404
|
+
superseded_by=list(superseded_by),
|
|
3405
|
+
is_latest=is_latest,
|
|
3406
|
+
embedding=embedding,
|
|
3407
|
+
memory_at=memory_at,
|
|
3408
|
+
custom=custom,
|
|
3409
|
+
)
|
|
3410
|
+
stored_id = await self._vector_store.upsert(node)
|
|
3411
|
+
if stored_id != memory_id:
|
|
3412
|
+
raise RuntimeError("exact memory import changed the requested identity")
|
|
3413
|
+
return {
|
|
3414
|
+
"success": True,
|
|
3415
|
+
"memory_id": memory_id,
|
|
3416
|
+
"memory_ids": [memory_id],
|
|
3417
|
+
"request_id": request_id,
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3226
3420
|
@_ensure_internal_loop
|
|
3227
3421
|
async def async_get_raw(self, raw_id: str) -> Optional[Dict[str, Any]]:
|
|
3228
3422
|
from .models.memory import MemoryLayer
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
hy_memory/__init__.py,sha256=idVBktG5xzToAXl6WDsAmZbBKX3_Q5D5iUtkKcdfmm0,4031
|
|
2
|
-
hy_memory/client.py,sha256=
|
|
2
|
+
hy_memory/client.py,sha256=2posxO_sWtNXPO5w2ixBr2pSXv58JLVdiqEHMK7fTf8,301567
|
|
3
3
|
hy_memory/config.py,sha256=J051sHyMnTysxWajFORNnGhy6SRKq8n6ZVXSS44lhGA,67809
|
|
4
4
|
hy_memory/inspector.py,sha256=Uj-mrxi_Piluq4DGVHCHzMfA1QSJLEOMBpiotDjqJSs,18380
|
|
5
5
|
hy_memory/metrics.py,sha256=sGhhV_aDEuws7ks4c-pI_z5o2rayKkJcNC6J1b9sPQY,16648
|
|
@@ -128,8 +128,8 @@ hy_memory/utils/time_window.py,sha256=MGAAWLyxHHwLrNthmYDdnH5PA-pQP9ZdcoQUfpzJof
|
|
|
128
128
|
hy_memory/utils/token_count.py,sha256=WibfD9KNuERMrcEPNFZTNo0JCpE72XPaUSlD48Wz1mk,2388
|
|
129
129
|
hy_memory/utils/trace_file_writer.py,sha256=bS_Kbzzy49eLr5G7HwBKLZqU9j3P6vGjtBWUWa8MIiY,217
|
|
130
130
|
hy_memory/utils/tracer.py,sha256=dVAwue7zwMax7KQFOfXpD-4pdfrVfiFFxbLhTrqu5XU,12595
|
|
131
|
-
hy_memory-2.0.5.
|
|
132
|
-
hy_memory-2.0.5.
|
|
133
|
-
hy_memory-2.0.5.
|
|
134
|
-
hy_memory-2.0.5.
|
|
135
|
-
hy_memory-2.0.5.
|
|
131
|
+
hy_memory-2.0.5.dev2.dist-info/licenses/LICENSE,sha256=ywv3qL-z2K0y7z9CI4IMqXf6eLeIKEWewwrzNfsrYN0,9650
|
|
132
|
+
hy_memory-2.0.5.dev2.dist-info/METADATA,sha256=W0pOsgjOKa9BsoJ2qbi55MkS__CvV-QReHwqKyKIC0k,18340
|
|
133
|
+
hy_memory-2.0.5.dev2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
134
|
+
hy_memory-2.0.5.dev2.dist-info/top_level.txt,sha256=YipheDT9yI2XTaR3lQcsXb3P9MOkd3uN2JHGtlUbnFU,10
|
|
135
|
+
hy_memory-2.0.5.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|