neo4j-agent-memory 0.3.17 → 0.3.19

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.
@@ -1,7 +1,34 @@
1
+ // :param {
2
+ // nowIso: "2026-01-04T22:07:53.086Z",
3
+ // agentId: "agent-123",
4
+ // halfLifeSeconds: 86400,
5
+ // aMin: 1.0,
6
+ // bMin: 1.0,
7
+ // w: 1.0,
8
+ // y: 1.0,
9
+ // items: [
10
+ // "mem_8cd773c2-208c-45ad-97ea-1b2337dca751",
11
+ // "mem_64fbcc73-0b5c-4041-8b6b-66514ffaf1d0",
12
+ // "mem_e55b80e2-6156-47bc-a964-9aef596f74a6",
13
+ // "mem_13189119-e3ad-4769-9f2b-2d3e3b8bc07f",
14
+ // "mem_137c3ff7-a81d-453d-8048-5c1b736db6ca",
15
+ // "mem_c0ea5643-3c61-4607-ba9f-67f4c2bb01ee",
16
+ // "mem_aa15e7b6-7f94-445a-9c52-3eb24a315215",
17
+ // "mem_e93e7bb8-b43c-44f5-a5d3-87545d67be59",
18
+ // "mem_b81e3709-35ae-4cab-931d-612dcc2cd43d",
19
+ // "mem_ce8a5b62-7ddb-4618-8a6c-93ed3b425f27",
20
+ // "mem_737df25b-7944-4dee-a7aa-86af93567663"
21
+ // ]
22
+ // }
1
23
  WITH datetime($nowIso) AS now
2
- UNWIND $items AS item
24
+
25
+ UNWIND $items AS memoryId
26
+ WITH now, memoryId
27
+ WHERE memoryId IS NOT NULL AND memoryId <> ""
28
+
3
29
  MATCH (a:Agent {id: $agentId})
4
- MATCH (m:Memory {id: item.memoryId})
30
+ MATCH (m:Memory {id: memoryId})
31
+
5
32
  MERGE (a)-[r:RECALLS]->(m)
6
33
  ON CREATE SET
7
34
  r.a = 1.0,
@@ -11,32 +38,33 @@ ON CREATE SET
11
38
  r.successes = 0,
12
39
  r.failures = 0
13
40
 
14
- WITH now, r, item,
15
- // elapsed seconds, safe
16
- CASE WHEN duration.inSeconds(coalesce(r.updatedAt, now), now).seconds > 0
17
- THEN duration.inSeconds(coalesce(r.updatedAt, now), now).seconds
18
- ELSE 0 END AS dt
41
+ WITH now, r,
42
+ CASE
43
+ WHEN duration.inSeconds(coalesce(r.updatedAt, now), now).seconds > 0
44
+ THEN duration.inSeconds(coalesce(r.updatedAt, now), now).seconds
45
+ ELSE 0
46
+ END AS dt
19
47
 
20
- WITH now, r, item,
48
+ WITH now, r,
21
49
  0.5 ^ (dt / $halfLifeSeconds) AS gamma,
22
- coalesce(r.a, CASE WHEN $aMin > coalesce(r.strength, 0.5) * 2.0 THEN $aMin ELSE coalesce(r.strength, 0.5) * 2.0 END) AS aPrev,
23
- coalesce(r.b, CASE WHEN $bMin > (1.0 - coalesce(r.strength, 0.5)) * 2.0 THEN $bMin ELSE (1.0 - coalesce(r.strength, 0.5)) * 2.0 END) AS bPrev
50
+ coalesce(r.a, $aMin) AS aPrev,
51
+ coalesce(r.b, $bMin) AS bPrev
24
52
 
25
- WITH now, r, item, gamma,
53
+ WITH now, r, gamma,
26
54
  ($aMin + gamma * (aPrev - $aMin)) AS a0,
27
55
  ($bMin + gamma * (bPrev - $bMin)) AS b0
28
56
 
29
- WITH now, r, item,
30
- (a0 + item.w * item.y) AS a1,
31
- (b0 + item.w * (1.0 - item.y)) AS b1
57
+ WITH now, r,
58
+ (a0 + $w * $y) AS a1,
59
+ (b0 + $w * (1.0 - $y)) AS b1
32
60
 
33
61
  SET r.a = a1,
34
62
  r.b = b1,
35
63
  r.strength = a1 / (a1 + b1),
36
64
  r.evidence = a1 + b1,
37
65
  r.updatedAt = now,
38
- r.uses = coalesce(r.uses,0) + 1,
39
- r.successes = coalesce(r.successes,0) + CASE WHEN item.y >= 0.5 THEN 1 ELSE 0 END,
40
- r.failures = coalesce(r.failures,0) + CASE WHEN item.y < 0.5 THEN 1 ELSE 0 END
66
+ r.uses = coalesce(r.uses, 0) + 1,
67
+ r.successes = coalesce(r.successes, 0) + CASE WHEN $y >= 0.5 THEN 1 ELSE 0 END,
68
+ r.failures = coalesce(r.failures, 0) + CASE WHEN $y < 0.5 THEN 1 ELSE 0 END
41
69
 
42
70
  RETURN count(*) AS updated;
@@ -1,28 +1,36 @@
1
- // Parameters:
1
+ // Parameters (Neo4j Browser :param)
2
+ // :param { kind: null, limit: 50, agentId: "" }
3
+
2
4
  // - $kind: Optional memory kind filter ("semantic" | "procedural" | "episodic")
3
5
  // - $limit: Max number of memories to return
4
6
  // - $agentId: Optional agent id to filter by RECALLS edges
7
+
5
8
  WITH
6
- $kind AS kind,
9
+ coalesce($kind, null) AS kind,
7
10
  coalesce($limit, 50) AS limit,
8
- $agentId AS agentId
11
+ coalesce($agentId, "") AS agentId
9
12
 
10
- CALL {
11
- WITH kind, agentId
13
+ CALL (kind, agentId) {
14
+ // If agentId provided -> only recalled by that agent
12
15
  WITH kind, agentId
13
16
  WHERE agentId IS NOT NULL AND agentId <> ""
14
17
  MATCH (:Agent {id: agentId})-[:RECALLS]->(m:Memory)
15
18
  WHERE kind IS NULL OR m.kind = kind
16
19
  RETURN m
20
+
17
21
  UNION
22
+
23
+ // If agentId absent -> all memories
18
24
  WITH kind, agentId
19
25
  WHERE agentId IS NULL OR agentId = ""
20
26
  MATCH (m:Memory)
21
27
  WHERE kind IS NULL OR m.kind = kind
22
28
  RETURN m
23
29
  }
24
- WITH m
30
+
31
+ WITH m, limit
25
32
  ORDER BY m.updatedAt DESC
33
+
26
34
  WITH collect(
27
35
  m {
28
36
  .id,
@@ -36,4 +44,5 @@ WITH collect(
36
44
  .updatedAt
37
45
  }
38
46
  ) AS rows, limit
47
+
39
48
  RETURN rows[0..limit] AS memories;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo4j-agent-memory",
3
- "version": "0.3.17",
3
+ "version": "0.3.19",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",