langgraph-checkpoint-hyperspace 4.2.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.
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 YARlabs
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: langgraph-checkpoint-hyperspace
3
+ Version: 4.2.0
4
+ Summary: Standalone LangGraph CheckpointSaver & Cross-Thread Store backed by HyperspaceDB CSR KAG Graph and Lorentz Hyperbolic Manifolds
5
+ Author-email: YARlabs <hi@yar.ink>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://yar.ink
8
+ Project-URL: Repository, https://github.com/YARlabs/langgraph-checkpoint-hyperspace
9
+ Project-URL: Documentation, https://yar.ink/docs
10
+ Keywords: hyperspacedb,langgraph,checkpoint,ai-agents,knowledge-graph,lorentz-manifold
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: hyperspacedb>=4.2.0
23
+ Provides-Extra: langgraph
24
+ Requires-Dist: langgraph-checkpoint>=2.0.0; extra == "langgraph"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
27
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # `langgraph-checkpoint-hyperspace` — Standalone LangGraph Checkpointer & Store for HyperspaceDB
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/langgraph-checkpoint-hyperspace.svg)](https://pypi.org/project/langgraph-checkpoint-hyperspace/)
33
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
34
+
35
+ A lightweight, zero-monolith **LangGraph CheckpointSaver** and **Cross-Thread Memory Store** backed by **[HyperspaceDB](https://yar.ink)** CSR KAG Topology and Lorentz Hyperbolic Manifolds.
36
+
37
+ Unlike `langchain-hyperspace`, this standalone package has **zero dependency on `langchain` or `langchain-core`**, making it ideal for lean production LangGraph deployments.
38
+
39
+ ---
40
+
41
+ ## Key Capabilities
42
+
43
+ 1. **CSR KAG Execution Lineage & Fork Tracking**
44
+ - Automatically wires `STEP_TRANSITION` edges between consecutive checkpoints and `FORKED_FROM` edges when branching or time-traveling from an earlier state.
45
+ 2. **Lorentz Hyperboloid State Embeddings**
46
+ - Embeds serialized state snapshots onto the upper sheet of the $d$-dimensional Lorentz hyperboloid ($\mathbb{H}^{d-1}$) where radial distance encodes execution step depth.
47
+ 3. **Semantic State Recall & Time-Travel**
48
+ - `saver.search_checkpoints("query")` recalls relevant past states across execution branches using Lorentzian geodesic similarity.
49
+ - `saver.traverse_lineage(thread_id, start_checkpoint_id)` walks the KAG execution graph in $O(1)$ per hop.
50
+
51
+ ---
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install langgraph-checkpoint-hyperspace
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Quick Start
62
+
63
+ ```python
64
+ from langgraph_checkpoint_hyperspace import HyperspaceCheckpointSaver
65
+
66
+ checkpointer = HyperspaceCheckpointSaver(
67
+ host="localhost",
68
+ port=50051,
69
+ collection_name="agent_checkpoints",
70
+ )
71
+
72
+ # Pass directly to any LangGraph StateGraph.compile(checkpointer=checkpointer)
73
+ ```
74
+
75
+ ---
76
+
77
+ ## License
78
+
79
+ Apache-2.0. Copyright © 2026 **YARlabs**.
80
+
@@ -0,0 +1,51 @@
1
+ # `langgraph-checkpoint-hyperspace` — Standalone LangGraph Checkpointer & Store for HyperspaceDB
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/langgraph-checkpoint-hyperspace.svg)](https://pypi.org/project/langgraph-checkpoint-hyperspace/)
4
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
5
+
6
+ A lightweight, zero-monolith **LangGraph CheckpointSaver** and **Cross-Thread Memory Store** backed by **[HyperspaceDB](https://yar.ink)** CSR KAG Topology and Lorentz Hyperbolic Manifolds.
7
+
8
+ Unlike `langchain-hyperspace`, this standalone package has **zero dependency on `langchain` or `langchain-core`**, making it ideal for lean production LangGraph deployments.
9
+
10
+ ---
11
+
12
+ ## Key Capabilities
13
+
14
+ 1. **CSR KAG Execution Lineage & Fork Tracking**
15
+ - Automatically wires `STEP_TRANSITION` edges between consecutive checkpoints and `FORKED_FROM` edges when branching or time-traveling from an earlier state.
16
+ 2. **Lorentz Hyperboloid State Embeddings**
17
+ - Embeds serialized state snapshots onto the upper sheet of the $d$-dimensional Lorentz hyperboloid ($\mathbb{H}^{d-1}$) where radial distance encodes execution step depth.
18
+ 3. **Semantic State Recall & Time-Travel**
19
+ - `saver.search_checkpoints("query")` recalls relevant past states across execution branches using Lorentzian geodesic similarity.
20
+ - `saver.traverse_lineage(thread_id, start_checkpoint_id)` walks the KAG execution graph in $O(1)$ per hop.
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install langgraph-checkpoint-hyperspace
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Quick Start
33
+
34
+ ```python
35
+ from langgraph_checkpoint_hyperspace import HyperspaceCheckpointSaver
36
+
37
+ checkpointer = HyperspaceCheckpointSaver(
38
+ host="localhost",
39
+ port=50051,
40
+ collection_name="agent_checkpoints",
41
+ )
42
+
43
+ # Pass directly to any LangGraph StateGraph.compile(checkpointer=checkpointer)
44
+ ```
45
+
46
+ ---
47
+
48
+ ## License
49
+
50
+ Apache-2.0. Copyright © 2026 **YARlabs**.
51
+
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "langgraph-checkpoint-hyperspace"
7
+ version = "4.2.0"
8
+ description = "Standalone LangGraph CheckpointSaver & Cross-Thread Store backed by HyperspaceDB CSR KAG Graph and Lorentz Hyperbolic Manifolds"
9
+ readme = "README.md"
10
+ license = { text = "Apache-2.0" }
11
+ authors = [{ name = "YARlabs", email = "hi@yar.ink" }]
12
+ requires-python = ">=3.9"
13
+ keywords = [
14
+ "hyperspacedb",
15
+ "langgraph",
16
+ "checkpoint",
17
+ "ai-agents",
18
+ "knowledge-graph",
19
+ "lorentz-manifold",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 5 - Production/Stable",
23
+ "Intended Audience :: Developers",
24
+ "License :: OSI Approved :: Apache Software License",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ ]
31
+ dependencies = [
32
+ "hyperspacedb>=4.2.0",
33
+ ]
34
+
35
+ [project.optional-dependencies]
36
+ langgraph = ["langgraph-checkpoint>=2.0.0"]
37
+ dev = ["pytest>=8.0.0", "pytest-asyncio>=0.23.0"]
38
+
39
+ [project.urls]
40
+ Homepage = "https://yar.ink"
41
+ Repository = "https://github.com/YARlabs/langgraph-checkpoint-hyperspace"
42
+ Documentation = "https://yar.ink/docs"
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ """
2
+ `langgraph-checkpoint-hyperspace` — Standalone LangGraph CheckpointSaver & Store for HyperspaceDB.
3
+ """
4
+
5
+ from .saver import (
6
+ CheckpointTuple,
7
+ HyperspaceCheckpointSaver,
8
+ HyperspaceCrossThreadStore,
9
+ StoreItem,
10
+ )
11
+
12
+ __version__ = "4.2.0"
13
+
14
+ __all__ = [
15
+ "CheckpointTuple",
16
+ "HyperspaceCheckpointSaver",
17
+ "HyperspaceCrossThreadStore",
18
+ "StoreItem",
19
+ "__version__",
20
+ ]
21
+
@@ -0,0 +1,654 @@
1
+ """
2
+ Standalone LangGraph CheckpointSaver & Cross-Thread Store backed by HyperspaceDB v4.2.
3
+
4
+ Zero dependency on `langchain` or `langchain-core` monoliths: relies exclusively on
5
+ `hyperspacedb` (v4.2.0+) and optional `langgraph-checkpoint`.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import json
12
+ import math
13
+ import time
14
+ from dataclasses import dataclass, field
15
+ from typing import Any, AsyncIterator, Callable, Dict, Iterator, List, Optional, Sequence, Tuple
16
+
17
+ from hyperspace import HyperspaceClient
18
+
19
+ try:
20
+ from langgraph.checkpoint.base import (
21
+ BaseCheckpointSaver,
22
+ ChannelVersions,
23
+ Checkpoint,
24
+ CheckpointMetadata,
25
+ CheckpointTuple,
26
+ )
27
+ except ImportError:
28
+ class BaseCheckpointSaver: # type: ignore[no-redef]
29
+ def __init__(self, serde: Any = None) -> None:
30
+ self.serde = serde
31
+
32
+ ChannelVersions = Dict[str, Any] # type: ignore[misc]
33
+ Checkpoint = Dict[str, Any] # type: ignore[misc]
34
+ CheckpointMetadata = Dict[str, Any] # type: ignore[misc]
35
+
36
+ @dataclass
37
+ class CheckpointTuple: # type: ignore[no-redef]
38
+ config: Dict[str, Any]
39
+ checkpoint: Dict[str, Any]
40
+ metadata: Dict[str, Any]
41
+ parent_config: Optional[Dict[str, Any]] = None
42
+ pending_writes: Optional[List[Tuple[str, str, Any]]] = None
43
+
44
+
45
+ @dataclass
46
+ class StoreItem:
47
+ """Item stored in `HyperspaceCrossThreadStore` (compatible with `langgraph.store.base.Item`)."""
48
+
49
+ value: Dict[str, Any]
50
+ key: str
51
+ namespace: Tuple[str, ...]
52
+ created_at: float = field(default_factory=time.time)
53
+ updated_at: float = field(default_factory=time.time)
54
+ score: Optional[float] = None
55
+
56
+
57
+ def _hash_id(raw: str) -> int:
58
+ digest = hashlib.blake2b(raw.encode("utf-8"), digest_size=8).digest()
59
+ return (int.from_bytes(digest, byteorder="big", signed=False) % 2147483646) + 1
60
+
61
+
62
+ def _deterministic_lorentz_state_vector(
63
+ state_text: str, step: int, dimension: int
64
+ ) -> List[float]:
65
+ """
66
+ Embeds serialized state text and execution step onto the upper sheet of the
67
+ d-dimensional Lorentz hyperboloid (-x0^2 + sum(x_i^2) = -1).
68
+ """
69
+ dim = max(4, dimension)
70
+ spatial = [0.0] * (dim - 1)
71
+ digest = hashlib.sha256(state_text.encode("utf-8")).digest()
72
+ for i in range(0, len(digest), 2):
73
+ slot = (digest[i] + i) % (dim - 1)
74
+ sign = 1.0 if (digest[i + 1] & 1) == 0 else -1.0
75
+ spatial[slot] += sign * ((digest[i + 1] / 255.0) * 0.5)
76
+
77
+ norm_sq = sum(x * x for x in spatial)
78
+ radial_radius = min(4.5, 0.15 + max(0, step) * 0.12)
79
+ sinh_r = math.sinh(radial_radius)
80
+
81
+ if norm_sq > 1e-12:
82
+ scale = sinh_r / math.sqrt(norm_sq)
83
+ spatial = [x * scale for x in spatial]
84
+ else:
85
+ spatial[0] = sinh_r
86
+
87
+ scaled_sq = sum(x * x for x in spatial)
88
+ x0 = math.sqrt(1.0 + scaled_sq)
89
+ return [x0] + spatial
90
+
91
+
92
+ class HyperspaceCheckpointSaver(BaseCheckpointSaver):
93
+ """
94
+ Lightweight, standalone LangGraph CheckpointSaver backed by HyperspaceDB CSR KAG Graph.
95
+
96
+ Features:
97
+ - Links consecutive state transitions (`parent_checkpoint_id -> checkpoint_id`) via
98
+ directed `STEP_TRANSITION` edges and branching forks via `FORKED_FROM` edges.
99
+ - Embeds state snapshots onto the Lorentz hyperboloid for semantic state recall
100
+ (`search_checkpoints`) and O(1) time-travel lineage traversal (`traverse_lineage`).
101
+ """
102
+
103
+ def __init__(
104
+ self,
105
+ host: str = "localhost",
106
+ port: int = 50051,
107
+ collection_name: str = "langgraph_checkpoints",
108
+ api_key: Optional[str] = None,
109
+ user_id: Optional[str] = None,
110
+ dimension: int = 33,
111
+ metric: str = "lorentz",
112
+ client: Optional[HyperspaceClient] = None,
113
+ serde: Any = None,
114
+ ) -> None:
115
+ super().__init__(serde=serde)
116
+ self.host = host
117
+ self.port = port
118
+ self.collection_name = collection_name
119
+ self.dimension = dimension
120
+ self.metric = metric
121
+ target = f"{host}:{port}" if ":" not in host else host
122
+ self._owns_client = client is None
123
+ self._client = client or HyperspaceClient(
124
+ host=target, api_key=api_key, user_id=user_id
125
+ )
126
+ self._hot_checkpoints: Dict[int, Dict[str, Any]] = {}
127
+ self._hot_writes: Dict[int, List[Tuple[str, str, Any]]] = {}
128
+ self._parent_children_count: Dict[int, int] = {}
129
+ self._ensure_collection()
130
+
131
+ def _ensure_collection(self) -> None:
132
+ try:
133
+ self._client.create_collection(
134
+ self.collection_name,
135
+ dimension=self.dimension,
136
+ metric=self.metric,
137
+ )
138
+ except Exception:
139
+ pass
140
+
141
+ def _checkpoint_point_id(
142
+ self, thread_id: str, checkpoint_ns: str, checkpoint_id: str
143
+ ) -> int:
144
+ return _hash_id(f"ckpt::{thread_id}::{checkpoint_ns}::{checkpoint_id}")
145
+
146
+ def put(
147
+ self,
148
+ config: Dict[str, Any],
149
+ checkpoint: Checkpoint,
150
+ metadata: CheckpointMetadata,
151
+ new_versions: ChannelVersions,
152
+ ) -> Dict[str, Any]:
153
+ configurable = config.get("configurable", {})
154
+ thread_id = str(configurable.get("thread_id", "default"))
155
+ checkpoint_ns = str(configurable.get("checkpoint_ns", ""))
156
+ parent_checkpoint_id = configurable.get("checkpoint_id")
157
+
158
+ ckpt_dict = (
159
+ dict(checkpoint) if isinstance(checkpoint, dict) else {"data": checkpoint}
160
+ )
161
+ checkpoint_id = str(
162
+ ckpt_dict.get("id") or f"ckpt_{int(time.time() * 1000000)}"
163
+ )
164
+ meta_dict = dict(metadata) if isinstance(metadata, dict) else {}
165
+ step = int(meta_dict.get("step", 0))
166
+ now_ts = time.time()
167
+
168
+ point_id = self._checkpoint_point_id(thread_id, checkpoint_ns, checkpoint_id)
169
+ serialized_ckpt = json.dumps(ckpt_dict, default=str)
170
+ serialized_meta = json.dumps(meta_dict, default=str)
171
+
172
+ vec = _deterministic_lorentz_state_vector(
173
+ serialized_ckpt, step, self.dimension
174
+ )
175
+
176
+ edge_relation = "STEP_TRANSITION"
177
+ if parent_checkpoint_id:
178
+ parent_pid = self._checkpoint_point_id(
179
+ thread_id, checkpoint_ns, str(parent_checkpoint_id)
180
+ )
181
+ children_so_far = self._parent_children_count.get(parent_pid, 0)
182
+ self._parent_children_count[parent_pid] = children_so_far + 1
183
+ if children_so_far >= 1:
184
+ edge_relation = "FORKED_FROM"
185
+
186
+ record_meta: Dict[str, str] = {
187
+ "thread_id": thread_id,
188
+ "checkpoint_ns": checkpoint_ns,
189
+ "checkpoint_id": checkpoint_id,
190
+ "parent_checkpoint_id": str(parent_checkpoint_id or ""),
191
+ "edge_relation": edge_relation,
192
+ "step": str(step),
193
+ "created_at": str(now_ts),
194
+ "checkpoint_json": serialized_ckpt,
195
+ "metadata_json": serialized_meta,
196
+ }
197
+
198
+ self._hot_checkpoints[point_id] = {
199
+ "id": point_id,
200
+ "metadata": record_meta,
201
+ "vector": vec,
202
+ }
203
+
204
+ try:
205
+ self._client.insert(
206
+ id=point_id,
207
+ vector=vec,
208
+ metadata=record_meta,
209
+ collection=self.collection_name,
210
+ )
211
+ if parent_checkpoint_id:
212
+ parent_point_id = self._checkpoint_point_id(
213
+ thread_id, checkpoint_ns, str(parent_checkpoint_id)
214
+ )
215
+ self._client.link(
216
+ source_id=parent_point_id,
217
+ target_id=point_id,
218
+ relation=edge_relation,
219
+ weight=1.0,
220
+ collection=self.collection_name,
221
+ )
222
+ except Exception:
223
+ pass
224
+
225
+ return {
226
+ "configurable": {
227
+ "thread_id": thread_id,
228
+ "checkpoint_ns": checkpoint_ns,
229
+ "checkpoint_id": checkpoint_id,
230
+ }
231
+ }
232
+
233
+ async def aput(
234
+ self,
235
+ config: Dict[str, Any],
236
+ checkpoint: Checkpoint,
237
+ metadata: CheckpointMetadata,
238
+ new_versions: ChannelVersions,
239
+ ) -> Dict[str, Any]:
240
+ return self.put(config, checkpoint, metadata, new_versions)
241
+
242
+ def put_writes(
243
+ self,
244
+ config: Dict[str, Any],
245
+ writes: Sequence[Tuple[str, Any]],
246
+ task_id: str,
247
+ task_path: str = "",
248
+ ) -> None:
249
+ configurable = config.get("configurable", {})
250
+ thread_id = str(configurable.get("thread_id", "default"))
251
+ checkpoint_ns = str(configurable.get("checkpoint_ns", ""))
252
+ checkpoint_id = str(configurable.get("checkpoint_id", ""))
253
+ if not checkpoint_id:
254
+ return
255
+ point_id = self._checkpoint_point_id(thread_id, checkpoint_ns, checkpoint_id)
256
+ bucket = self._hot_writes.setdefault(point_id, [])
257
+ for channel, val in writes:
258
+ bucket.append((task_id, channel, val))
259
+
260
+ async def aput_writes(
261
+ self,
262
+ config: Dict[str, Any],
263
+ writes: Sequence[Tuple[str, Any]],
264
+ task_id: str,
265
+ task_path: str = "",
266
+ ) -> None:
267
+ self.put_writes(config, writes, task_id, task_path)
268
+
269
+ def _hydrate_tuple(self, meta: Dict[str, str], point_id: int) -> CheckpointTuple:
270
+ thread_id = meta.get("thread_id", "default")
271
+ checkpoint_ns = meta.get("checkpoint_ns", "")
272
+ checkpoint_id = meta.get("checkpoint_id", "")
273
+ parent_id = meta.get("parent_checkpoint_id", "")
274
+ ckpt_data = json.loads(meta.get("checkpoint_json") or "{}")
275
+ meta_data = json.loads(meta.get("metadata_json") or "{}")
276
+
277
+ cfg: Dict[str, Any] = {
278
+ "configurable": {
279
+ "thread_id": thread_id,
280
+ "checkpoint_ns": checkpoint_ns,
281
+ "checkpoint_id": checkpoint_id,
282
+ }
283
+ }
284
+ parent_cfg: Optional[Dict[str, Any]] = (
285
+ {
286
+ "configurable": {
287
+ "thread_id": thread_id,
288
+ "checkpoint_ns": checkpoint_ns,
289
+ "checkpoint_id": parent_id,
290
+ }
291
+ }
292
+ if parent_id
293
+ else None
294
+ )
295
+ pending = self._hot_writes.get(point_id, [])
296
+ return CheckpointTuple(
297
+ config=cfg,
298
+ checkpoint=ckpt_data,
299
+ metadata=meta_data,
300
+ parent_config=parent_cfg,
301
+ pending_writes=pending,
302
+ )
303
+
304
+ def get_tuple(self, config: Dict[str, Any]) -> Optional[CheckpointTuple]:
305
+ configurable = config.get("configurable", {})
306
+ thread_id = str(configurable.get("thread_id", "default"))
307
+ checkpoint_ns = str(configurable.get("checkpoint_ns", ""))
308
+ checkpoint_id = configurable.get("checkpoint_id")
309
+
310
+ if checkpoint_id:
311
+ point_id = self._checkpoint_point_id(
312
+ thread_id, checkpoint_ns, str(checkpoint_id)
313
+ )
314
+ if point_id in self._hot_checkpoints:
315
+ return self._hydrate_tuple(
316
+ self._hot_checkpoints[point_id]["metadata"], point_id
317
+ )
318
+ try:
319
+ pts = self._client.get_points(
320
+ [point_id], collection=self.collection_name
321
+ )
322
+ if pts:
323
+ m = pts[0].get("metadata") or {}
324
+ if m.get("checkpoint_json"):
325
+ return self._hydrate_tuple(m, point_id)
326
+ except Exception:
327
+ pass
328
+ return None
329
+
330
+ items = list(self.list(config, limit=1))
331
+ return items[0] if items else None
332
+
333
+ async def aget_tuple(self, config: Dict[str, Any]) -> Optional[CheckpointTuple]:
334
+ return self.get_tuple(config)
335
+
336
+ def list(
337
+ self,
338
+ config: Optional[Dict[str, Any]],
339
+ *,
340
+ filter: Optional[Dict[str, Any]] = None,
341
+ before: Optional[Dict[str, Any]] = None,
342
+ limit: Optional[int] = None,
343
+ ) -> Iterator[CheckpointTuple]:
344
+ configurable = (config or {}).get("configurable", {})
345
+ thread_id = configurable.get("thread_id")
346
+ checkpoint_ns = configurable.get("checkpoint_ns")
347
+ before_id = (
348
+ before.get("configurable", {}).get("checkpoint_id") if before else None
349
+ )
350
+
351
+ records: Dict[int, Dict[str, str]] = {}
352
+ for pid, entry in self._hot_checkpoints.items():
353
+ records[pid] = entry["metadata"]
354
+
355
+ try:
356
+ filters_list: List[Dict[str, Any]] = []
357
+ if thread_id is not None:
358
+ filters_list.append(
359
+ {"type": "match", "key": "thread_id", "value": str(thread_id)}
360
+ )
361
+ if checkpoint_ns is not None:
362
+ filters_list.append(
363
+ {
364
+ "type": "match",
365
+ "key": "checkpoint_ns",
366
+ "value": str(checkpoint_ns),
367
+ }
368
+ )
369
+ scrolled = self._client.scroll(
370
+ limit=max(limit or 100, 100),
371
+ offset=0,
372
+ filters=filters_list if filters_list else None,
373
+ collection=self.collection_name,
374
+ )
375
+ for pt in scrolled:
376
+ pid = int(pt.get("id", 0))
377
+ meta = pt.get("metadata") or {}
378
+ if meta.get("checkpoint_json"):
379
+ records[pid] = meta
380
+ except Exception:
381
+ pass
382
+
383
+ matched: List[Tuple[float, int, Dict[str, str]]] = []
384
+ for pid, meta in records.items():
385
+ if thread_id is not None and meta.get("thread_id") != str(thread_id):
386
+ continue
387
+ if (
388
+ checkpoint_ns is not None
389
+ and meta.get("checkpoint_ns", "") != str(checkpoint_ns)
390
+ ):
391
+ continue
392
+ if before_id and meta.get("checkpoint_id") == str(before_id):
393
+ continue
394
+ if filter:
395
+ meta_parsed = json.loads(meta.get("metadata_json") or "{}")
396
+ if not all(meta_parsed.get(k) == v for k, v in filter.items()):
397
+ continue
398
+ created = float(meta.get("created_at") or 0.0)
399
+ matched.append((created, pid, meta))
400
+
401
+ matched.sort(key=lambda x: x[0], reverse=True)
402
+ if limit is not None:
403
+ matched = matched[:limit]
404
+
405
+ for _, pid, meta in matched:
406
+ yield self._hydrate_tuple(meta, pid)
407
+
408
+ async def alist(
409
+ self,
410
+ config: Optional[Dict[str, Any]],
411
+ *,
412
+ filter: Optional[Dict[str, Any]] = None,
413
+ before: Optional[Dict[str, Any]] = None,
414
+ limit: Optional[int] = None,
415
+ ) -> AsyncIterator[CheckpointTuple]:
416
+ for item in self.list(config, filter=filter, before=before, limit=limit):
417
+ yield item
418
+
419
+ def delete_thread(self, thread_id: str) -> int:
420
+ """Deletes all checkpoints and pending writes belonging to `thread_id`."""
421
+ to_remove = [
422
+ pid
423
+ for pid, entry in self._hot_checkpoints.items()
424
+ if entry["metadata"].get("thread_id") == str(thread_id)
425
+ ]
426
+ for pid in to_remove:
427
+ self._hot_checkpoints.pop(pid, None)
428
+ self._hot_writes.pop(pid, None)
429
+ try:
430
+ self._client.delete(id=pid, collection=self.collection_name)
431
+ except Exception:
432
+ pass
433
+ return len(to_remove)
434
+
435
+ def search_checkpoints(
436
+ self,
437
+ query_state_text: str,
438
+ step_hint: int = 1,
439
+ thread_id: Optional[str] = None,
440
+ limit: int = 5,
441
+ ) -> List[CheckpointTuple]:
442
+ """
443
+ Semantic & hyperbolic search across saved execution checkpoints.
444
+ """
445
+ q_vec = _deterministic_lorentz_state_vector(
446
+ query_state_text, step_hint, self.dimension
447
+ )
448
+ try:
449
+ filters = (
450
+ [{"type": "match", "key": "thread_id", "value": str(thread_id)}]
451
+ if thread_id
452
+ else None
453
+ )
454
+ hits = self._client.search(
455
+ vector=q_vec,
456
+ top_k=limit,
457
+ filters=filters,
458
+ collection=self.collection_name,
459
+ )
460
+ if hits:
461
+ return [
462
+ self._hydrate_tuple(h.get("metadata") or {}, int(h.get("id", 0)))
463
+ for h in hits
464
+ if (h.get("metadata") or {}).get("checkpoint_json")
465
+ ]
466
+ except Exception:
467
+ pass
468
+
469
+ # Local Lorentzian distance fallback over hot checkpoints
470
+ scored: List[Tuple[float, int, Dict[str, str]]] = []
471
+ for pid, entry in self._hot_checkpoints.items():
472
+ meta = entry["metadata"]
473
+ if thread_id and meta.get("thread_id") != str(thread_id):
474
+ continue
475
+ v = entry["vector"]
476
+ spatial_dot = sum(a * b for a, b in zip(q_vec[1:], v[1:]))
477
+ neg_mink = max(1.0, q_vec[0] * v[0] - spatial_dot)
478
+ dist = math.acosh(neg_mink)
479
+ scored.append((dist, pid, meta))
480
+
481
+ scored.sort(key=lambda x: x[0])
482
+ return [self._hydrate_tuple(meta, pid) for _, pid, meta in scored[:limit]]
483
+
484
+ def traverse_lineage(
485
+ self,
486
+ thread_id: str,
487
+ start_checkpoint_id: str,
488
+ checkpoint_ns: str = "",
489
+ max_depth: int = 8,
490
+ ) -> List[CheckpointTuple]:
491
+ """
492
+ Traverses the CSR KAG `STEP_TRANSITION` / `FORKED_FROM` execution graph starting from `start_checkpoint_id`.
493
+ """
494
+ start_pid = self._checkpoint_point_id(
495
+ thread_id, checkpoint_ns, start_checkpoint_id
496
+ )
497
+ try:
498
+ nodes = self._client.traverse(
499
+ start_id=start_pid,
500
+ max_depth=max_depth,
501
+ max_nodes=128,
502
+ collection=self.collection_name,
503
+ )
504
+ out: List[CheckpointTuple] = []
505
+ for n in nodes:
506
+ meta = n.get("metadata") or {}
507
+ if meta.get("checkpoint_json"):
508
+ out.append(self._hydrate_tuple(meta, int(n.get("id", 0))))
509
+ if out:
510
+ return out
511
+ except Exception:
512
+ pass
513
+
514
+ # Local fallback traversal via parent_checkpoint_id links
515
+ result: List[CheckpointTuple] = []
516
+ visited = {start_checkpoint_id}
517
+ frontier = [start_checkpoint_id]
518
+ for _ in range(max_depth + 1):
519
+ if not frontier:
520
+ break
521
+ next_frontier: List[str] = []
522
+ for cid in frontier:
523
+ pid = self._checkpoint_point_id(thread_id, checkpoint_ns, cid)
524
+ if pid in self._hot_checkpoints:
525
+ result.append(
526
+ self._hydrate_tuple(self._hot_checkpoints[pid]["metadata"], pid)
527
+ )
528
+ for cand_pid, entry in self._hot_checkpoints.items():
529
+ m = entry["metadata"]
530
+ if (
531
+ m.get("thread_id") == thread_id
532
+ and m.get("parent_checkpoint_id") == cid
533
+ ):
534
+ child_cid = m.get("checkpoint_id", "")
535
+ if child_cid and child_cid not in visited:
536
+ visited.add(child_cid)
537
+ next_frontier.append(child_cid)
538
+ frontier = next_frontier
539
+ return result
540
+
541
+ def close(self) -> None:
542
+ if self._owns_client and hasattr(self._client, "close"):
543
+ self._client.close()
544
+
545
+
546
+ class HyperspaceCrossThreadStore:
547
+ """
548
+ Standalone LangGraph cross-thread Long-Term Memory Store (`BaseStore` compatible)
549
+ without requiring `langchain-core`.
550
+ """
551
+
552
+ def __init__(
553
+ self,
554
+ host: str = "localhost",
555
+ port: int = 50051,
556
+ collection_name: str = "langgraph_store",
557
+ embedding_fn: Optional[Callable[[str], List[float]]] = None,
558
+ api_key: Optional[str] = None,
559
+ user_id: Optional[str] = None,
560
+ dimension: int = 33,
561
+ metric: str = "lorentz",
562
+ client: Optional[HyperspaceClient] = None,
563
+ ) -> None:
564
+ self.host = host
565
+ self.port = port
566
+ self.collection_name = collection_name
567
+ self._embedding_fn = embedding_fn
568
+ self.dimension = dimension
569
+ self.metric = metric
570
+ target = f"{host}:{port}" if ":" not in host else host
571
+ self._owns_client = client is None
572
+ self._client = client or HyperspaceClient(
573
+ host=target, api_key=api_key, user_id=user_id
574
+ )
575
+ self._hot_items: Dict[int, StoreItem] = {}
576
+ self._ensure_collection()
577
+
578
+ def _ensure_collection(self) -> None:
579
+ try:
580
+ self._client.create_collection(
581
+ self.collection_name,
582
+ dimension=self.dimension,
583
+ metric=self.metric,
584
+ )
585
+ except Exception:
586
+ pass
587
+
588
+ @staticmethod
589
+ def _ns_to_str(namespace: Sequence[str]) -> str:
590
+ return "/".join(str(part) for part in namespace)
591
+
592
+ @staticmethod
593
+ def _str_to_ns(ns_str: str) -> Tuple[str, ...]:
594
+ return tuple(ns_str.split("/")) if ns_str else ()
595
+
596
+ def _item_point_id(self, namespace: Sequence[str], key: str) -> int:
597
+ return _hash_id(f"store::{self._ns_to_str(namespace)}::{key}")
598
+
599
+ def put(
600
+ self,
601
+ namespace: Tuple[str, ...],
602
+ key: str,
603
+ value: Dict[str, Any],
604
+ ) -> None:
605
+ now_ts = time.time()
606
+ pid = self._item_point_id(namespace, key)
607
+ ns_str = self._ns_to_str(namespace)
608
+ text = json.dumps(value, ensure_ascii=False, default=str)
609
+ vec = (
610
+ self._embedding_fn(text)
611
+ if self._embedding_fn is not None
612
+ else _deterministic_lorentz_state_vector(
613
+ text, len(namespace), self.dimension
614
+ )
615
+ )
616
+
617
+ item = StoreItem(
618
+ value=dict(value),
619
+ key=key,
620
+ namespace=tuple(namespace),
621
+ created_at=now_ts,
622
+ updated_at=now_ts,
623
+ )
624
+ self._hot_items[pid] = item
625
+
626
+ meta: Dict[str, str] = {
627
+ "namespace": ns_str,
628
+ "key": key,
629
+ "value_json": text,
630
+ "created_at": str(now_ts),
631
+ "updated_at": str(now_ts),
632
+ }
633
+ try:
634
+ self._client.insert(
635
+ id=pid,
636
+ vector=vec,
637
+ metadata=meta,
638
+ collection=self.collection_name,
639
+ )
640
+ except Exception:
641
+ pass
642
+
643
+ def get(self, namespace: Tuple[str, ...], key: str) -> Optional[StoreItem]:
644
+ pid = self._item_point_id(namespace, key)
645
+ return self._hot_items.get(pid)
646
+
647
+ def delete(self, namespace: Tuple[str, ...], key: str) -> None:
648
+ pid = self._item_point_id(namespace, key)
649
+ self._hot_items.pop(pid, None)
650
+ try:
651
+ self._client.delete(id=pid, collection=self.collection_name)
652
+ except Exception:
653
+ pass
654
+
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: langgraph-checkpoint-hyperspace
3
+ Version: 4.2.0
4
+ Summary: Standalone LangGraph CheckpointSaver & Cross-Thread Store backed by HyperspaceDB CSR KAG Graph and Lorentz Hyperbolic Manifolds
5
+ Author-email: YARlabs <hi@yar.ink>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://yar.ink
8
+ Project-URL: Repository, https://github.com/YARlabs/langgraph-checkpoint-hyperspace
9
+ Project-URL: Documentation, https://yar.ink/docs
10
+ Keywords: hyperspacedb,langgraph,checkpoint,ai-agents,knowledge-graph,lorentz-manifold
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: hyperspacedb>=4.2.0
23
+ Provides-Extra: langgraph
24
+ Requires-Dist: langgraph-checkpoint>=2.0.0; extra == "langgraph"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
27
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # `langgraph-checkpoint-hyperspace` — Standalone LangGraph Checkpointer & Store for HyperspaceDB
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/langgraph-checkpoint-hyperspace.svg)](https://pypi.org/project/langgraph-checkpoint-hyperspace/)
33
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
34
+
35
+ A lightweight, zero-monolith **LangGraph CheckpointSaver** and **Cross-Thread Memory Store** backed by **[HyperspaceDB](https://yar.ink)** CSR KAG Topology and Lorentz Hyperbolic Manifolds.
36
+
37
+ Unlike `langchain-hyperspace`, this standalone package has **zero dependency on `langchain` or `langchain-core`**, making it ideal for lean production LangGraph deployments.
38
+
39
+ ---
40
+
41
+ ## Key Capabilities
42
+
43
+ 1. **CSR KAG Execution Lineage & Fork Tracking**
44
+ - Automatically wires `STEP_TRANSITION` edges between consecutive checkpoints and `FORKED_FROM` edges when branching or time-traveling from an earlier state.
45
+ 2. **Lorentz Hyperboloid State Embeddings**
46
+ - Embeds serialized state snapshots onto the upper sheet of the $d$-dimensional Lorentz hyperboloid ($\mathbb{H}^{d-1}$) where radial distance encodes execution step depth.
47
+ 3. **Semantic State Recall & Time-Travel**
48
+ - `saver.search_checkpoints("query")` recalls relevant past states across execution branches using Lorentzian geodesic similarity.
49
+ - `saver.traverse_lineage(thread_id, start_checkpoint_id)` walks the KAG execution graph in $O(1)$ per hop.
50
+
51
+ ---
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ pip install langgraph-checkpoint-hyperspace
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Quick Start
62
+
63
+ ```python
64
+ from langgraph_checkpoint_hyperspace import HyperspaceCheckpointSaver
65
+
66
+ checkpointer = HyperspaceCheckpointSaver(
67
+ host="localhost",
68
+ port=50051,
69
+ collection_name="agent_checkpoints",
70
+ )
71
+
72
+ # Pass directly to any LangGraph StateGraph.compile(checkpointer=checkpointer)
73
+ ```
74
+
75
+ ---
76
+
77
+ ## License
78
+
79
+ Apache-2.0. Copyright © 2026 **YARlabs**.
80
+
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/langgraph_checkpoint_hyperspace/__init__.py
5
+ src/langgraph_checkpoint_hyperspace/saver.py
6
+ src/langgraph_checkpoint_hyperspace.egg-info/PKG-INFO
7
+ src/langgraph_checkpoint_hyperspace.egg-info/SOURCES.txt
8
+ src/langgraph_checkpoint_hyperspace.egg-info/dependency_links.txt
9
+ src/langgraph_checkpoint_hyperspace.egg-info/requires.txt
10
+ src/langgraph_checkpoint_hyperspace.egg-info/top_level.txt
11
+ tests/test_saver.py
@@ -0,0 +1,8 @@
1
+ hyperspacedb>=4.2.0
2
+
3
+ [dev]
4
+ pytest>=8.0.0
5
+ pytest-asyncio>=0.23.0
6
+
7
+ [langgraph]
8
+ langgraph-checkpoint>=2.0.0
@@ -0,0 +1,111 @@
1
+ """Unit tests for standalone `langgraph-checkpoint-hyperspace`."""
2
+
3
+ from typing import Any, Dict, List
4
+ from langgraph_checkpoint_hyperspace import (
5
+ HyperspaceCheckpointSaver,
6
+ HyperspaceCrossThreadStore,
7
+ )
8
+
9
+
10
+ class _MockHyperspaceClient:
11
+ def __init__(self) -> None:
12
+ self.points: Dict[int, Dict[str, Any]] = {}
13
+ self.edges: List[Dict[str, Any]] = []
14
+
15
+ def create_collection(self, *args: Any, **kwargs: Any) -> None:
16
+ pass
17
+
18
+ def insert(
19
+ self, id: int, vector: List[float], metadata: Dict[str, str], collection: str
20
+ ) -> bool:
21
+ self.points[id] = {"id": id, "vector": vector, "metadata": metadata}
22
+ return True
23
+
24
+ def link(
25
+ self,
26
+ source_id: int,
27
+ target_id: int,
28
+ relation: str,
29
+ weight: float,
30
+ collection: str,
31
+ ) -> None:
32
+ self.edges.append(
33
+ {
34
+ "source_id": source_id,
35
+ "target_id": target_id,
36
+ "relation": relation,
37
+ "weight": weight,
38
+ }
39
+ )
40
+
41
+ def get_points(self, ids: List[int], collection: str) -> List[Dict[str, Any]]:
42
+ return [self.points[i] for i in ids if i in self.points]
43
+
44
+ def scroll(self, **kwargs: Any) -> List[Dict[str, Any]]:
45
+ return list(self.points.values())
46
+
47
+ def delete(self, id: int, collection: str) -> bool:
48
+ self.points.pop(id, None)
49
+ return True
50
+
51
+
52
+ def test_checkpoint_saver_lineage_and_fork_edges() -> None:
53
+ mock_client = _MockHyperspaceClient()
54
+ saver = HyperspaceCheckpointSaver(
55
+ client=mock_client, # type: ignore[arg-type]
56
+ dimension=16,
57
+ )
58
+
59
+ cfg0 = {"configurable": {"thread_id": "t_agent_1", "checkpoint_ns": ""}}
60
+ cfg1 = saver.put(
61
+ cfg0,
62
+ {"id": "ckpt_1", "channel_values": {"plan": "analyze repo"}},
63
+ {"step": 1, "source": "loop"},
64
+ {},
65
+ )
66
+ cfg2 = saver.put(
67
+ cfg1,
68
+ {"id": "ckpt_2", "channel_values": {"plan": "run tests"}},
69
+ {"step": 2, "source": "loop"},
70
+ {},
71
+ )
72
+ # Branching fork from ckpt_1
73
+ cfg_fork = saver.put(
74
+ cfg1,
75
+ {"id": "ckpt_fork", "channel_values": {"plan": "alternative refactor"}},
76
+ {"step": 2, "source": "fork"},
77
+ {},
78
+ )
79
+
80
+ assert len(mock_client.edges) == 2
81
+ assert mock_client.edges[0]["relation"] == "STEP_TRANSITION"
82
+ assert mock_client.edges[1]["relation"] == "FORKED_FROM"
83
+
84
+ latest = saver.get_tuple({"configurable": {"thread_id": "t_agent_1"}})
85
+ assert latest is not None
86
+ assert latest.checkpoint["id"] in ("ckpt_2", "ckpt_fork")
87
+
88
+ lineage = saver.traverse_lineage("t_agent_1", "ckpt_1")
89
+ assert len(lineage) == 3
90
+
91
+ semantic_hits = saver.search_checkpoints("run tests", step_hint=2, thread_id="t_agent_1")
92
+ assert len(semantic_hits) >= 1
93
+
94
+ removed = saver.delete_thread("t_agent_1")
95
+ assert removed == 3
96
+ assert saver.get_tuple(cfg2) is None
97
+ assert saver.get_tuple(cfg_fork) is None
98
+
99
+
100
+ def test_cross_thread_store() -> None:
101
+ mock_client = _MockHyperspaceClient()
102
+ store = HyperspaceCrossThreadStore(client=mock_client) # type: ignore[arg-type]
103
+
104
+ store.put(("users", "u_42", "preferences"), "theme", {"mode": "dark", "lang": "ru"})
105
+ item = store.get(("users", "u_42", "preferences"), "theme")
106
+ assert item is not None
107
+ assert item.value["mode"] == "dark"
108
+
109
+ store.delete(("users", "u_42", "preferences"), "theme")
110
+ assert store.get(("users", "u_42", "preferences"), "theme") is None
111
+