hyperspace-sdk-ts 3.1.0 → 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 +121 -10
- package/dist/client.d.ts +117 -6
- package/dist/client.js +481 -98
- package/dist/proto/hyperspace_grpc_pb.js +222 -0
- package/dist/proto/hyperspace_pb.js +10261 -4530
- 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,6 +167,69 @@ 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" } }]);
|
|
201
|
+
```
|
|
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
|
+
|
|
214
|
+
### Hybrid & Lexical Search (BM25)
|
|
215
|
+
|
|
216
|
+
HyperspaceDB supports combined lexical and vector ranking.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
// Hybrid Search (Semantic Vector + BM25 Lexical)
|
|
220
|
+
const results = await client.search([0.1, -0.2, 0.5], 10, "coll", {
|
|
221
|
+
hybridQuery: "hybrid search implementation",
|
|
222
|
+
hybridAlpha: 0.7, // 70% vector weight
|
|
223
|
+
bm25: {
|
|
224
|
+
method: "bm25plus",
|
|
225
|
+
language: "english"
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Or Pure Lexical Search via searchText
|
|
230
|
+
const lexicalResults = await client.searchText("full-text query", 10, "coll", {
|
|
231
|
+
bm25: { method: "lucene" }
|
|
232
|
+
});
|
|
148
233
|
```
|
|
149
234
|
|
|
150
235
|
### `searchBatch(vectors, topK, collection?)`
|
|
@@ -223,21 +308,47 @@ Provides advanced tools for Agentic AI, running entirely on the client side:
|
|
|
223
308
|
import { CognitiveMath } from "hyperspace-sdk-ts";
|
|
224
309
|
|
|
225
310
|
// 1. Detect Hallucinations (Entropy approaches 1.0)
|
|
226
|
-
const entropy =
|
|
311
|
+
const entropy = client.localEntropy(candidateThought, neighbors, 1.0);
|
|
227
312
|
|
|
228
313
|
// 2. Proof of Convergence (Negative derivative = convergence)
|
|
229
|
-
const stability =
|
|
314
|
+
const stability = await client.getTrustScore([1, 2, 3]);
|
|
230
315
|
|
|
231
316
|
// 3. Extrapolate next thought (Koopman linearization)
|
|
232
|
-
const nextThought =
|
|
317
|
+
const nextThought = await client.predictMomentum([10, 11], 1.0);
|
|
233
318
|
|
|
234
319
|
// 4. Phase-Locked Loop for topic tracking
|
|
235
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
|
+
```
|
|
236
347
|
```
|
|
237
348
|
|
|
238
349
|
## Embedding Pipeline (Optional)
|
|
239
350
|
|
|
240
|
-
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.
|
|
241
352
|
|
|
242
353
|
### Server-Side Config (`.env`)
|
|
243
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;
|
|
@@ -48,6 +107,15 @@ export interface VacuumFilter {
|
|
|
48
107
|
op: 'lt' | 'lte' | 'gt' | 'gte' | 'eq' | 'ne';
|
|
49
108
|
value: number;
|
|
50
109
|
}
|
|
110
|
+
export interface Bm25Options {
|
|
111
|
+
method?: "bm25plus" | "bm25l" | "robertson" | "lucene" | "atire";
|
|
112
|
+
k1?: number;
|
|
113
|
+
b?: number;
|
|
114
|
+
delta?: number;
|
|
115
|
+
language?: string;
|
|
116
|
+
ngrams?: number;
|
|
117
|
+
fusionMethod?: "rrf" | "weighted";
|
|
118
|
+
}
|
|
51
119
|
export type EventTypeName = 'insert' | 'delete';
|
|
52
120
|
export interface SubscribeOptions {
|
|
53
121
|
types?: EventTypeName[];
|
|
@@ -69,20 +137,33 @@ export declare const HyperbolicMath: {
|
|
|
69
137
|
export declare class HyperspaceClient {
|
|
70
138
|
private client;
|
|
71
139
|
private metadata;
|
|
140
|
+
private host;
|
|
141
|
+
private apiKey?;
|
|
142
|
+
private userId?;
|
|
72
143
|
private static toVectorList;
|
|
73
144
|
private static toProtoMetadataValue;
|
|
74
145
|
private static parseTypedMetadata;
|
|
146
|
+
private toProtoFilter;
|
|
75
147
|
constructor(host?: string, apiKey?: string, userId?: string);
|
|
76
|
-
createCollection(name: string,
|
|
148
|
+
createCollection(name: string, schema: CollectionSchema): Promise<boolean>;
|
|
77
149
|
deleteCollection(name: string): Promise<boolean>;
|
|
150
|
+
freezeCollection(name: string): Promise<string>;
|
|
151
|
+
unfreezeCollection(name: string): Promise<string>;
|
|
78
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
|
+
}[]>;
|
|
79
160
|
delete(id: number, collection?: string): Promise<boolean>;
|
|
80
|
-
insert(vector: number[] | Float32Array | Float64Array,
|
|
161
|
+
insert(id: number, vector: number[] | Float32Array | Float64Array, meta?: {
|
|
81
162
|
[key: string]: string;
|
|
82
163
|
}, collection?: string, durability?: DurabilityLevel, typedMetadata?: {
|
|
83
164
|
[key: string]: TypedMetadataValue;
|
|
84
|
-
}): Promise<boolean>;
|
|
85
|
-
insertText(
|
|
165
|
+
}, payload?: Uint8Array): Promise<boolean>;
|
|
166
|
+
insertText(id: number, text: string, meta?: {
|
|
86
167
|
[key: string]: string;
|
|
87
168
|
}, collection?: string, durability?: DurabilityLevel): Promise<boolean>;
|
|
88
169
|
vectorize(text: string, metric?: string): Promise<number[]>;
|
|
@@ -97,12 +178,27 @@ export declare class HyperspaceClient {
|
|
|
97
178
|
};
|
|
98
179
|
}[], collection?: string, durability?: DurabilityLevel): Promise<boolean>;
|
|
99
180
|
search(vector: number[] | Float32Array | Float64Array, topK: number, collection?: string, options?: {
|
|
181
|
+
filter?: {
|
|
182
|
+
[key: string]: string;
|
|
183
|
+
};
|
|
100
184
|
filters?: Filter[];
|
|
101
185
|
hybridQuery?: string;
|
|
102
186
|
hybridAlpha?: number;
|
|
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;
|
|
103
196
|
}): Promise<SearchResult[]>;
|
|
104
197
|
searchText(text: string, topK: number, collection?: string, options?: {
|
|
105
198
|
filters?: Filter[];
|
|
199
|
+
bm25?: Bm25Options;
|
|
200
|
+
hybridAlpha?: number;
|
|
201
|
+
includePayload?: boolean;
|
|
106
202
|
}): Promise<SearchResult[]>;
|
|
107
203
|
searchBatch(vectors: Array<number[] | Float32Array | Float64Array>, topK: number, collection?: string): Promise<SearchResult[][]>;
|
|
108
204
|
getDigest(collection?: string): Promise<{
|
|
@@ -125,5 +221,20 @@ export declare class HyperspaceClient {
|
|
|
125
221
|
subscribeToEvents(options: SubscribeOptions, onEvent: (event: EventMessage) => void, onError?: (err: Error) => void): grpc.ClientReadableStream<EventMessage>;
|
|
126
222
|
syncHandshake(collection: string, clientBuckets: number[], clientLogicalClock?: number, clientCount?: number): Promise<hyperspace_pb.SyncHandshakeResponse.AsObject>;
|
|
127
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>;
|
|
128
239
|
close(): void;
|
|
129
240
|
}
|