superbrain-distributed-sdk 0.2.0 โ 0.2.2
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.
- package/README.md +55 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,22 +90,63 @@ const received = JSON.parse((await clientB.read(ctxPtr, 0, 0)).toString());
|
|
|
90
90
|
## ๐ Architecture
|
|
91
91
|
|
|
92
92
|
```
|
|
93
|
-
Your LLM App
|
|
94
|
-
|
|
95
|
-
โ
|
|
96
|
-
โ
|
|
97
|
-
โ
|
|
98
|
-
โ
|
|
99
|
-
โ
|
|
100
|
-
โ
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
93
|
+
Your LLM App (SDK) SuperBrain Cluster
|
|
94
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
95
|
+
โ allocate(size) โโโโโโโโโผโโ(1)โโโบ Coordinator (Control Plane)
|
|
96
|
+
โ free(ptr_id) โโโโโโโโโผโโ(5)โโโบ Maps pointers โ node locations
|
|
97
|
+
โ โ โ
|
|
98
|
+
โ โ (2) pointer map returned
|
|
99
|
+
โ โ โ
|
|
100
|
+
โ write(ptr_id, data) โโโโผโโ(3)โโโบโโโโโโโโโผโโโโโโโโโโโโโโโ
|
|
101
|
+
โ read(ptr_id) โโโโโโโโโผโโ(4)โโโบโ Memory Nodes โ
|
|
102
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ (Data Plane) โ
|
|
103
|
+
โ 1TB+ pooled RAM โ
|
|
104
|
+
โโโโโโโโโโโโโโโโโโโโโโโโ
|
|
105
|
+
|
|
106
|
+
CRITICAL: write() and read() bypass the Coordinator entirely.
|
|
107
|
+
They stream directly to the Memory Nodes over gRPC for maximum throughput (~100 MB/s).
|
|
108
|
+
The Coordinator is ONLY in the control path (allocate + free).
|
|
104
109
|
```
|
|
105
110
|
|
|
106
|
-
**
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
**Why this matters**: The Coordinator never becomes a bottleneck for your data. 1000 agents can read/write simultaneously to different nodes without fighting for the same control plane.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## ๐งน Memory Management
|
|
116
|
+
|
|
117
|
+
> **The Node.js SDK exposes the raw client layer โ `free()` is always required after `allocate()`.**
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// โ
Always do this after you are done with a pointer
|
|
121
|
+
const ptr = await client.allocate(100 * 1024 * 1024);
|
|
122
|
+
await client.write(ptr, 0, data);
|
|
123
|
+
const result = await client.read(ptr, 0, 0);
|
|
124
|
+
await client.free(ptr); // โ required โ leaks memory if skipped
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### ๐ Want Managed Memory? Use the Python SDK
|
|
128
|
+
|
|
129
|
+
The Python SDK (`pip install superbrain-sdk`) provides higher-level APIs where **free() is never needed**:
|
|
130
|
+
|
|
131
|
+
| Python API | Free needed? | What it does |
|
|
132
|
+
|------------|:------------:|--------------|
|
|
133
|
+
| `SharedContext.write("key", data)` | โ No | Key-based shared state across agents |
|
|
134
|
+
| `fabric.store_kv_cache(prefix)` | โ No | Deduped prompt cache, auto-evicted |
|
|
135
|
+
| `SuperBrainMemory` (LangChain) | โ No | Chat history in distributed RAM |
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Python โ no free() ever needed with high-level APIs
|
|
139
|
+
from superbrain import DistributedContextFabric
|
|
140
|
+
|
|
141
|
+
fabric = DistributedContextFabric(coordinator="localhost:50050")
|
|
142
|
+
ctx = fabric.create_context("session-42")
|
|
143
|
+
|
|
144
|
+
ctx.write("state", {"step": 10}) # written to distributed RAM
|
|
145
|
+
ctx.read("state") # read from any machine
|
|
146
|
+
# No free() โ
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
โ [Full Memory Management Guide](https://github.com/anispy211/superbrainSdk/blob/main/DOCUMENTATION.md#memory-management--when-to-free)
|
|
109
150
|
|
|
110
151
|
---
|
|
111
152
|
|