hyperspace-sdk-ts 3.1.1 → 3.1.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 +100 -10
- package/dist/client.d.ts +103 -4
- package/dist/client.js +443 -104
- package/dist/proto/hyperspace_grpc_pb.js +222 -0
- package/dist/proto/hyperspace_pb.js +9862 -4739
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,8 +8,14 @@ Use this SDK for:
|
|
|
8
8
|
- high-throughput batched search (`searchBatch`)
|
|
9
9
|
- bulk insertion (`batchInsert`)
|
|
10
10
|
- advanced filtering and hybrid search
|
|
11
|
+
- recursive logical filters (`AND`, `OR`, `NOT`)
|
|
12
|
+
- bulk point retrieval (`getPoints`)
|
|
13
|
+
- metadata updates (`updatePayload`)
|
|
14
|
+
- paginated scanning (`scroll`)
|
|
15
|
+
- filtered point counting (`count`)
|
|
16
|
+
- health monitoring (`healthCheck`)
|
|
11
17
|
- typed metadata (`string | number | boolean`)
|
|
12
|
-
- graph traversal APIs (`getNode`, `getNeighbors`, `getConceptParents`, `traverse`, `findSemanticClusters`)
|
|
18
|
+
- graph traversal APIs (`getNode`, `getNeighbors`, `getSubsumptionTree`, `getConceptParents`, `traverse`, `exploreGraph`, `findSemanticClusters`)
|
|
13
19
|
- rebuild with metadata pruning (`rebuildIndexWithFilter`)
|
|
14
20
|
- multi-tenant authentication headers (`x-api-key`, `x-hyperspace-user-id`)
|
|
15
21
|
|
|
@@ -34,7 +40,12 @@ async function main() {
|
|
|
34
40
|
const collection = "docs_ts";
|
|
35
41
|
|
|
36
42
|
await client.deleteCollection(collection).catch(() => {});
|
|
37
|
-
await client.createCollection(collection,
|
|
43
|
+
await client.createCollection(collection, {
|
|
44
|
+
components: [
|
|
45
|
+
{ name: "primary", metric: "cosine", full_dimension: 3, weight: 1.0 }
|
|
46
|
+
],
|
|
47
|
+
cascade_pipeline: []
|
|
48
|
+
});
|
|
38
49
|
|
|
39
50
|
await client.insert(1, [0.1, 0.2, 0.3], { source: "demo" }, collection);
|
|
40
51
|
await client.insert(2, [0.2, 0.1, 0.4], { source: "demo" }, collection);
|
|
@@ -59,11 +70,22 @@ main().catch(console.error);
|
|
|
59
70
|
- `apiKey`: optional API key
|
|
60
71
|
- `userId`: optional tenant/user ID
|
|
61
72
|
|
|
62
|
-
### `createCollection(name,
|
|
73
|
+
### `createCollection(name, schema)`
|
|
63
74
|
|
|
64
|
-
Create a new collection
|
|
75
|
+
Create a new collection using a `CollectionSchema`.
|
|
65
76
|
|
|
66
|
-
- `metric`: `"l2" | "cosine" | "poincare" | "lorentz"`
|
|
77
|
+
- `metric`: `"l2" | "cosine" | "poincare" | "lorentz" | "hybrid"`
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
await client.createCollection("my_coll", {
|
|
81
|
+
components: [
|
|
82
|
+
{ name: "primary", metric: "lorentz", full_dimension: 129, weight: 1.0 }
|
|
83
|
+
],
|
|
84
|
+
cascade_pipeline: [
|
|
85
|
+
{ component_name: "primary", cutoff_dimension: 17, store_in_ram: true, rerank_top_k: 100 }
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
```
|
|
67
89
|
|
|
68
90
|
### `deleteCollection(name)`
|
|
69
91
|
|
|
@@ -77,7 +99,7 @@ Returns `Promise<CollectionInfo[]>`.
|
|
|
77
99
|
```ts
|
|
78
100
|
const collections = await client.listCollections();
|
|
79
101
|
for (const col of collections) {
|
|
80
|
-
console.log(`${col.name}:
|
|
102
|
+
console.log(`${col.name}: count=${col.count}, schema=${JSON.stringify(col.schema)}`);
|
|
81
103
|
}
|
|
82
104
|
```
|
|
83
105
|
|
|
@@ -145,8 +167,50 @@ const coneFilter = {
|
|
|
145
167
|
const results = await client.search([0.1, 0.2, 0.3], 10, "coll", {
|
|
146
168
|
filters: [ballFilter, boxFilter]
|
|
147
169
|
});
|
|
170
|
+
|
|
171
|
+
// 4. Recursive Logical Filters
|
|
172
|
+
const logicFilter = {
|
|
173
|
+
and: [
|
|
174
|
+
{ match: { key: "status", value: "active" } },
|
|
175
|
+
{ or: [
|
|
176
|
+
{ range: { key: "score", gte: 0.8 } },
|
|
177
|
+
{ match: { key: "priority", value: "high" } }
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `getPoints(ids, collection?)`
|
|
185
|
+
|
|
186
|
+
Retrieve multiple points by their IDs.
|
|
187
|
+
Returns `Promise<Point[]>`.
|
|
188
|
+
|
|
189
|
+
### `updatePayload(id, metadata, collection?)`
|
|
190
|
+
|
|
191
|
+
Patch metadata for an existing point.
|
|
192
|
+
```ts
|
|
193
|
+
await client.updatePayload(1, { status: "processed", tags: "updated" });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### `scroll(limit?, offset?, filters?, collection?)`
|
|
197
|
+
|
|
198
|
+
Paginated retrieval of points with optional filtering.
|
|
199
|
+
```ts
|
|
200
|
+
const points = await client.scroll(50, 0, [{ match: { key: "category", value: "news" } }]);
|
|
148
201
|
```
|
|
149
202
|
|
|
203
|
+
### `count(filters?, collection?)`
|
|
204
|
+
|
|
205
|
+
Count points matching filters.
|
|
206
|
+
```ts
|
|
207
|
+
const total = await client.count([{ range: { key: "price", lte: 100 } }]);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### `healthCheck()`
|
|
211
|
+
|
|
212
|
+
Check server connectivity. Returns `"ONLINE"` or throws.
|
|
213
|
+
|
|
150
214
|
### Hybrid & Lexical Search (BM25)
|
|
151
215
|
|
|
152
216
|
HyperspaceDB supports combined lexical and vector ranking.
|
|
@@ -244,21 +308,47 @@ Provides advanced tools for Agentic AI, running entirely on the client side:
|
|
|
244
308
|
import { CognitiveMath } from "hyperspace-sdk-ts";
|
|
245
309
|
|
|
246
310
|
// 1. Detect Hallucinations (Entropy approaches 1.0)
|
|
247
|
-
const entropy =
|
|
311
|
+
const entropy = client.localEntropy(candidateThought, neighbors, 1.0);
|
|
248
312
|
|
|
249
313
|
// 2. Proof of Convergence (Negative derivative = convergence)
|
|
250
|
-
const stability =
|
|
314
|
+
const stability = await client.getTrustScore([1, 2, 3]);
|
|
251
315
|
|
|
252
316
|
// 3. Extrapolate next thought (Koopman linearization)
|
|
253
|
-
const nextThought =
|
|
317
|
+
const nextThought = await client.predictMomentum([10, 11], 1.0);
|
|
254
318
|
|
|
255
319
|
// 4. Phase-Locked Loop for topic tracking
|
|
256
320
|
const syncedThought = CognitiveMath.contextResonance(thought, globalContext, 0.5, 1.0);
|
|
321
|
+
|
|
322
|
+
// 5. Predict Semantic Relation (A + R ≈ B)
|
|
323
|
+
const relation = await client.predictRelation(1, 2);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Implicit Graph Engine (v3.2)
|
|
327
|
+
|
|
328
|
+
HyperspaceDB treats your vectors as nodes in a dynamic graph. Relationships are inferred from the geometry:
|
|
329
|
+
- **Lorentz / Poincare**: Hierarchy and subsumption (light cones).
|
|
330
|
+
- **L2 / Cosine**: Semantic similarity and adjacency.
|
|
331
|
+
|
|
332
|
+
### Subsumption Trees
|
|
333
|
+
Extract directed hierarchies from Lorentz-encoded data:
|
|
334
|
+
```ts
|
|
335
|
+
const tree = await client.getSubsumptionTree(1, 5);
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Advanced Traversal
|
|
339
|
+
Navigate the graph using physical kernels:
|
|
340
|
+
```ts
|
|
341
|
+
const results = await client.traverse({
|
|
342
|
+
startId: 1,
|
|
343
|
+
traversalMode: 2, // 0: GREEDY, 1: DIFFUSIVE, 2: MOMENTUM
|
|
344
|
+
breadthLimit: 5
|
|
345
|
+
});
|
|
346
|
+
```
|
|
257
347
|
```
|
|
258
348
|
|
|
259
349
|
## Embedding Pipeline (Optional)
|
|
260
350
|
|
|
261
|
-
HyperspaceDB supports **per-geometry embeddings** — each geometry (`l2`, `cosine`, `poincare`, `lorentz`) can have its own backend independently.
|
|
351
|
+
HyperspaceDB supports **per-geometry embeddings** — each geometry (`l2`, `cosine`, `poincare`, `lorentz`, `hybrid`) can have its own backend independently.
|
|
262
352
|
|
|
263
353
|
### Server-Side Config (`.env`)
|
|
264
354
|
|
package/dist/client.d.ts
CHANGED
|
@@ -10,11 +10,31 @@ export interface Filter {
|
|
|
10
10
|
key: string;
|
|
11
11
|
value: string;
|
|
12
12
|
};
|
|
13
|
+
prefix?: {
|
|
14
|
+
key: string;
|
|
15
|
+
prefix: string;
|
|
16
|
+
};
|
|
13
17
|
range?: {
|
|
14
18
|
key: string;
|
|
15
19
|
gte?: number;
|
|
16
20
|
lte?: number;
|
|
17
21
|
};
|
|
22
|
+
inCone?: {
|
|
23
|
+
axes: number[];
|
|
24
|
+
apertures: number[];
|
|
25
|
+
cen: number[];
|
|
26
|
+
};
|
|
27
|
+
inBall?: {
|
|
28
|
+
center: number[];
|
|
29
|
+
radius: number;
|
|
30
|
+
};
|
|
31
|
+
inBox?: {
|
|
32
|
+
minBounds: number[];
|
|
33
|
+
maxBounds: number[];
|
|
34
|
+
};
|
|
35
|
+
and?: Filter[];
|
|
36
|
+
or?: Filter[];
|
|
37
|
+
not?: Filter;
|
|
18
38
|
}
|
|
19
39
|
export interface SearchResult {
|
|
20
40
|
id: number;
|
|
@@ -25,12 +45,51 @@ export interface SearchResult {
|
|
|
25
45
|
typedMetadata: {
|
|
26
46
|
[key: string]: TypedMetadataValue;
|
|
27
47
|
};
|
|
48
|
+
payload?: Uint8Array;
|
|
49
|
+
}
|
|
50
|
+
export interface VectorComponent {
|
|
51
|
+
name: string;
|
|
52
|
+
metric: string;
|
|
53
|
+
fullDimension: number;
|
|
54
|
+
weight: number;
|
|
55
|
+
}
|
|
56
|
+
export interface MrlLayer {
|
|
57
|
+
componentName: string;
|
|
58
|
+
cutoffDimension: number;
|
|
59
|
+
storeInRam: boolean;
|
|
60
|
+
rerankTopK: number;
|
|
61
|
+
}
|
|
62
|
+
export interface CollectionSchema {
|
|
63
|
+
components: VectorComponent[];
|
|
64
|
+
cascadePipeline: MrlLayer[];
|
|
28
65
|
}
|
|
29
66
|
export interface CollectionInfo {
|
|
30
67
|
name: string;
|
|
31
68
|
count: number;
|
|
32
|
-
|
|
33
|
-
|
|
69
|
+
schema?: CollectionSchema;
|
|
70
|
+
}
|
|
71
|
+
export interface CollectionStats {
|
|
72
|
+
count: number;
|
|
73
|
+
schema?: CollectionSchema;
|
|
74
|
+
indexingQueue: number;
|
|
75
|
+
diskUsageBytes: number;
|
|
76
|
+
ramUsageBytes: number;
|
|
77
|
+
activeTasks: number;
|
|
78
|
+
}
|
|
79
|
+
export interface SystemMetrics {
|
|
80
|
+
cpuUsage: number;
|
|
81
|
+
ramUsageMb: number;
|
|
82
|
+
totalVectors: number;
|
|
83
|
+
activeCollections: number;
|
|
84
|
+
uptimeSeconds: number;
|
|
85
|
+
networkRxBytes: number;
|
|
86
|
+
networkTxBytes: number;
|
|
87
|
+
}
|
|
88
|
+
export interface CollectionConfig {
|
|
89
|
+
quantizationMode?: 'NONE' | 'SCALAR_I8';
|
|
90
|
+
efSearch?: number;
|
|
91
|
+
efConstruction?: number;
|
|
92
|
+
m?: number;
|
|
34
93
|
}
|
|
35
94
|
export interface GraphNode {
|
|
36
95
|
id: number;
|
|
@@ -78,19 +137,32 @@ export declare const HyperbolicMath: {
|
|
|
78
137
|
export declare class HyperspaceClient {
|
|
79
138
|
private client;
|
|
80
139
|
private metadata;
|
|
140
|
+
private host;
|
|
141
|
+
private apiKey?;
|
|
142
|
+
private userId?;
|
|
81
143
|
private static toVectorList;
|
|
82
144
|
private static toProtoMetadataValue;
|
|
83
145
|
private static parseTypedMetadata;
|
|
146
|
+
private toProtoFilter;
|
|
84
147
|
constructor(host?: string, apiKey?: string, userId?: string);
|
|
85
|
-
createCollection(name: string,
|
|
148
|
+
createCollection(name: string, schema: CollectionSchema): Promise<boolean>;
|
|
86
149
|
deleteCollection(name: string): Promise<boolean>;
|
|
150
|
+
freezeCollection(name: string): Promise<string>;
|
|
151
|
+
unfreezeCollection(name: string): Promise<string>;
|
|
87
152
|
listCollections(): Promise<CollectionInfo[]>;
|
|
153
|
+
getPoints(ids: number[], collection?: string): Promise<{
|
|
154
|
+
id: number;
|
|
155
|
+
vector: number[];
|
|
156
|
+
metadata: {
|
|
157
|
+
[key: string]: string;
|
|
158
|
+
};
|
|
159
|
+
}[]>;
|
|
88
160
|
delete(id: number, collection?: string): Promise<boolean>;
|
|
89
161
|
insert(id: number, vector: number[] | Float32Array | Float64Array, meta?: {
|
|
90
162
|
[key: string]: string;
|
|
91
163
|
}, collection?: string, durability?: DurabilityLevel, typedMetadata?: {
|
|
92
164
|
[key: string]: TypedMetadataValue;
|
|
93
|
-
}): Promise<boolean>;
|
|
165
|
+
}, payload?: Uint8Array): Promise<boolean>;
|
|
94
166
|
insertText(id: number, text: string, meta?: {
|
|
95
167
|
[key: string]: string;
|
|
96
168
|
}, collection?: string, durability?: DurabilityLevel): Promise<boolean>;
|
|
@@ -106,15 +178,27 @@ export declare class HyperspaceClient {
|
|
|
106
178
|
};
|
|
107
179
|
}[], collection?: string, durability?: DurabilityLevel): Promise<boolean>;
|
|
108
180
|
search(vector: number[] | Float32Array | Float64Array, topK: number, collection?: string, options?: {
|
|
181
|
+
filter?: {
|
|
182
|
+
[key: string]: string;
|
|
183
|
+
};
|
|
109
184
|
filters?: Filter[];
|
|
110
185
|
hybridQuery?: string;
|
|
111
186
|
hybridAlpha?: number;
|
|
112
187
|
bm25?: Bm25Options;
|
|
188
|
+
mrlDimension?: number;
|
|
189
|
+
useWasserstein?: boolean;
|
|
190
|
+
includePayload?: boolean;
|
|
191
|
+
componentWeights?: {
|
|
192
|
+
[key: string]: number;
|
|
193
|
+
};
|
|
194
|
+
useWave?: boolean;
|
|
195
|
+
restartFactor?: number;
|
|
113
196
|
}): Promise<SearchResult[]>;
|
|
114
197
|
searchText(text: string, topK: number, collection?: string, options?: {
|
|
115
198
|
filters?: Filter[];
|
|
116
199
|
bm25?: Bm25Options;
|
|
117
200
|
hybridAlpha?: number;
|
|
201
|
+
includePayload?: boolean;
|
|
118
202
|
}): Promise<SearchResult[]>;
|
|
119
203
|
searchBatch(vectors: Array<number[] | Float32Array | Float64Array>, topK: number, collection?: string): Promise<SearchResult[][]>;
|
|
120
204
|
getDigest(collection?: string): Promise<{
|
|
@@ -137,5 +221,20 @@ export declare class HyperspaceClient {
|
|
|
137
221
|
subscribeToEvents(options: SubscribeOptions, onEvent: (event: EventMessage) => void, onError?: (err: Error) => void): grpc.ClientReadableStream<EventMessage>;
|
|
138
222
|
syncHandshake(collection: string, clientBuckets: number[], clientLogicalClock?: number, clientCount?: number): Promise<hyperspace_pb.SyncHandshakeResponse.AsObject>;
|
|
139
223
|
syncPull(collection: string, bucketIndices: number[], onData: (data: hyperspace_pb.SyncVectorData.AsObject) => void, onError?: (err: Error) => void): grpc.ClientReadableStream<hyperspace_pb.SyncVectorData>;
|
|
224
|
+
getCollectionStats(name: string): Promise<CollectionStats>;
|
|
225
|
+
exists(name: string): Promise<boolean>;
|
|
226
|
+
getCacheStats(name: string): Promise<any>;
|
|
227
|
+
clearCache(name: string): Promise<boolean>;
|
|
228
|
+
updateCacheConfig(name: string, policy: string, annThreshold?: number): Promise<boolean>;
|
|
229
|
+
updateCollection(name: string, config: CollectionConfig): Promise<boolean>;
|
|
230
|
+
createSnapshot(): Promise<boolean>;
|
|
231
|
+
vacuum(): Promise<boolean>;
|
|
232
|
+
getMetrics(onData: (data: any) => void, onError?: (err: Error) => void): grpc.ClientReadableStream<any>;
|
|
233
|
+
searchMultiCollection(collections: string[], query: number[]): Promise<any>;
|
|
234
|
+
triggerReconsolidation(collection: string, targetVector: number[], learningRate?: number): Promise<boolean>;
|
|
235
|
+
getSubsumptionTree(rootId: number, maxDepth?: number, collection?: string): Promise<GraphNode[]>;
|
|
236
|
+
exploreGraph(startId: number, maxDepth?: number, maxNodes?: number, collection?: string): Promise<any>;
|
|
237
|
+
predictMomentum(trajectoryIds: number[], steps?: number, collection?: string, curvature?: number): Promise<number[]>;
|
|
238
|
+
getTrustScore(trajectoryIds: number[], collection?: string, curvature?: number): Promise<number>;
|
|
140
239
|
close(): void;
|
|
141
240
|
}
|