@nebula-ai/sdk 1.1.31 → 1.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 +0 -2
- package/dist/index.d.mts +57 -8
- package/dist/index.d.ts +57 -8
- package/dist/index.js +70 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,6 @@ const memoryId = await client.storeMemory({
|
|
|
38
38
|
const results = await client.search({
|
|
39
39
|
query: 'machine learning healthcare',
|
|
40
40
|
collection_ids: [collection.id],
|
|
41
|
-
limit: 5
|
|
42
41
|
});
|
|
43
42
|
|
|
44
43
|
results.forEach(result => {
|
|
@@ -120,7 +119,6 @@ const memory = await client.getMemory('memory-id');
|
|
|
120
119
|
const results = await client.search({
|
|
121
120
|
query: 'your search query',
|
|
122
121
|
collection_ids: [collection.id],
|
|
123
|
-
limit: 10
|
|
124
122
|
});
|
|
125
123
|
```
|
|
126
124
|
|
package/dist/index.d.mts
CHANGED
|
@@ -50,6 +50,7 @@ interface Memory$1 {
|
|
|
50
50
|
memory_id?: string;
|
|
51
51
|
metadata: Record<string, unknown>;
|
|
52
52
|
authority?: number;
|
|
53
|
+
snapshot?: Record<string, unknown>;
|
|
53
54
|
chunks?: Chunk[];
|
|
54
55
|
collection_ids?: string[];
|
|
55
56
|
created_at?: string;
|
|
@@ -106,7 +107,6 @@ interface GraphCommunityResult {
|
|
|
106
107
|
metadata: Record<string, unknown>;
|
|
107
108
|
}
|
|
108
109
|
interface SearchOptions {
|
|
109
|
-
limit: number;
|
|
110
110
|
filters?: Record<string, unknown>;
|
|
111
111
|
}
|
|
112
112
|
interface ActivatedEntity {
|
|
@@ -123,11 +123,11 @@ interface ActivatedFacet {
|
|
|
123
123
|
facet_id: string;
|
|
124
124
|
facet_name: string;
|
|
125
125
|
relevance_score: number;
|
|
126
|
-
facts:
|
|
126
|
+
facts: ActivatedSemantic[];
|
|
127
127
|
coherence_score?: number;
|
|
128
128
|
is_noise: boolean;
|
|
129
129
|
}
|
|
130
|
-
interface
|
|
130
|
+
interface ActivatedSemantic {
|
|
131
131
|
id?: string;
|
|
132
132
|
category?: string;
|
|
133
133
|
description?: string;
|
|
@@ -168,16 +168,23 @@ interface ActivatedEpisode {
|
|
|
168
168
|
t_start?: number;
|
|
169
169
|
t_last?: number;
|
|
170
170
|
n_facts?: number;
|
|
171
|
-
|
|
171
|
+
member_semantic_ids?: string[];
|
|
172
172
|
source_chunk_ids?: string[];
|
|
173
173
|
entity_names?: string[];
|
|
174
174
|
}
|
|
175
|
+
interface ActivatedProcedure {
|
|
176
|
+
statement: string;
|
|
177
|
+
activation_score: number;
|
|
178
|
+
confidence: number;
|
|
179
|
+
is_negated?: boolean;
|
|
180
|
+
}
|
|
175
181
|
interface MemoryResponse {
|
|
176
182
|
query: string;
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
semantics: ActivatedSemantic[];
|
|
184
|
+
procedures?: ActivatedProcedure[];
|
|
179
185
|
episodes?: ActivatedEpisode[];
|
|
180
186
|
sources: GroundedSource[];
|
|
187
|
+
entities: ActivatedEntity[];
|
|
181
188
|
total_traversal_time_ms?: number;
|
|
182
189
|
token_count?: number;
|
|
183
190
|
}
|
|
@@ -211,6 +218,38 @@ declare class NebulaCollectionNotFoundException extends NebulaException {
|
|
|
211
218
|
declare class NebulaNotFoundException extends NebulaException {
|
|
212
219
|
constructor(resourceId: string, resourceType?: string);
|
|
213
220
|
}
|
|
221
|
+
/** Portable graph state envelope returned by export and consumed by compute/query. */
|
|
222
|
+
interface SnapshotEnvelope {
|
|
223
|
+
collection_id: string;
|
|
224
|
+
graph: GraphPayload;
|
|
225
|
+
root_hash: string;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
interface GraphPayload {
|
|
229
|
+
entities: Record<string, unknown>[];
|
|
230
|
+
relationships: Record<string, unknown>[];
|
|
231
|
+
entity_embeddings?: EmbeddingBlock;
|
|
232
|
+
relationship_desc_embeddings?: EmbeddingBlock;
|
|
233
|
+
relationship_rel_embeddings?: EmbeddingBlock;
|
|
234
|
+
[key: string]: unknown;
|
|
235
|
+
}
|
|
236
|
+
interface EmbeddingBlock {
|
|
237
|
+
dimension: number;
|
|
238
|
+
matrix_b64: string;
|
|
239
|
+
present_mask: boolean[];
|
|
240
|
+
}
|
|
241
|
+
/** Full-value diff produced by compute. */
|
|
242
|
+
interface PatchEnvelope {
|
|
243
|
+
collection_id: string;
|
|
244
|
+
previous_root_hash: string;
|
|
245
|
+
next_root_hash: string;
|
|
246
|
+
put_entities: Record<string, unknown>[];
|
|
247
|
+
delete_entities: string[];
|
|
248
|
+
put_relationships: Record<string, unknown>[];
|
|
249
|
+
delete_relationships: string[];
|
|
250
|
+
events: Record<string, unknown>[];
|
|
251
|
+
[key: string]: unknown;
|
|
252
|
+
}
|
|
214
253
|
|
|
215
254
|
/**
|
|
216
255
|
* Official Nebula JavaScript/TypeScript SDK
|
|
@@ -276,7 +315,7 @@ declare class Nebula {
|
|
|
276
315
|
* - If role is present, creates a conversation
|
|
277
316
|
* - Otherwise, creates a document
|
|
278
317
|
*/
|
|
279
|
-
storeMemory(memory: Memory$1 | Record<string, unknown>, name?: string): Promise<string
|
|
318
|
+
storeMemory(memory: Memory$1 | Record<string, unknown>, name?: string): Promise<string | Record<string, unknown>>;
|
|
280
319
|
/**
|
|
281
320
|
* Internal method to append content to an existing memory
|
|
282
321
|
*
|
|
@@ -480,6 +519,7 @@ declare class Nebula {
|
|
|
480
519
|
effort?: 'auto' | 'low' | 'medium' | 'high';
|
|
481
520
|
filters?: Record<string, unknown>;
|
|
482
521
|
searchSettings?: Record<string, unknown>;
|
|
522
|
+
snapshot?: Record<string, unknown>;
|
|
483
523
|
}): Promise<MemoryResponse>;
|
|
484
524
|
/** List available connector providers */
|
|
485
525
|
listProviders(): Promise<string[]>;
|
|
@@ -525,6 +565,15 @@ declare class Nebula {
|
|
|
525
565
|
bucket: string;
|
|
526
566
|
expires_in: number;
|
|
527
567
|
}>;
|
|
568
|
+
/**
|
|
569
|
+
* Export a collection's full graph state as a portable snapshot.
|
|
570
|
+
*/
|
|
571
|
+
exportSnapshot(collectionId: string): Promise<SnapshotEnvelope>;
|
|
572
|
+
/**
|
|
573
|
+
* Import a snapshot into an ephemeral server-side collection.
|
|
574
|
+
* @returns The ephemeral collection ID.
|
|
575
|
+
*/
|
|
576
|
+
importSnapshot(snapshot: SnapshotEnvelope | Record<string, unknown>): Promise<string>;
|
|
528
577
|
}
|
|
529
578
|
|
|
530
579
|
/**
|
|
@@ -547,4 +596,4 @@ type MemoryFactory = {
|
|
|
547
596
|
declare const Memory: MemoryFactory;
|
|
548
597
|
type Memory = Memory$1;
|
|
549
598
|
|
|
550
|
-
export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type
|
|
599
|
+
export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type ActivatedProcedure, type ActivatedSemantic, type Chunk, type Collection, type EmbeddingBlock, type FileContentPart, type GraphCommunityResult, type GraphEntityResult, type GraphPayload, type GraphRelationshipResult, GraphSearchResultType, type GroundedSource, Memory, type MemoryResponse, type MultimodalContentPart, Nebula, NebulaAuthenticationException, type NebulaClientConfig, NebulaClientException, NebulaCollectionNotFoundException, NebulaContent, NebulaException, NebulaNotFoundException, NebulaRateLimitException, NebulaValidationException, type PatchEnvelope, type S3FileReferencePart, type SearchOptions, type SearchResult, type SnapshotEnvelope, type StructuredChunk, type TextContentPart, Nebula as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ interface Memory$1 {
|
|
|
50
50
|
memory_id?: string;
|
|
51
51
|
metadata: Record<string, unknown>;
|
|
52
52
|
authority?: number;
|
|
53
|
+
snapshot?: Record<string, unknown>;
|
|
53
54
|
chunks?: Chunk[];
|
|
54
55
|
collection_ids?: string[];
|
|
55
56
|
created_at?: string;
|
|
@@ -106,7 +107,6 @@ interface GraphCommunityResult {
|
|
|
106
107
|
metadata: Record<string, unknown>;
|
|
107
108
|
}
|
|
108
109
|
interface SearchOptions {
|
|
109
|
-
limit: number;
|
|
110
110
|
filters?: Record<string, unknown>;
|
|
111
111
|
}
|
|
112
112
|
interface ActivatedEntity {
|
|
@@ -123,11 +123,11 @@ interface ActivatedFacet {
|
|
|
123
123
|
facet_id: string;
|
|
124
124
|
facet_name: string;
|
|
125
125
|
relevance_score: number;
|
|
126
|
-
facts:
|
|
126
|
+
facts: ActivatedSemantic[];
|
|
127
127
|
coherence_score?: number;
|
|
128
128
|
is_noise: boolean;
|
|
129
129
|
}
|
|
130
|
-
interface
|
|
130
|
+
interface ActivatedSemantic {
|
|
131
131
|
id?: string;
|
|
132
132
|
category?: string;
|
|
133
133
|
description?: string;
|
|
@@ -168,16 +168,23 @@ interface ActivatedEpisode {
|
|
|
168
168
|
t_start?: number;
|
|
169
169
|
t_last?: number;
|
|
170
170
|
n_facts?: number;
|
|
171
|
-
|
|
171
|
+
member_semantic_ids?: string[];
|
|
172
172
|
source_chunk_ids?: string[];
|
|
173
173
|
entity_names?: string[];
|
|
174
174
|
}
|
|
175
|
+
interface ActivatedProcedure {
|
|
176
|
+
statement: string;
|
|
177
|
+
activation_score: number;
|
|
178
|
+
confidence: number;
|
|
179
|
+
is_negated?: boolean;
|
|
180
|
+
}
|
|
175
181
|
interface MemoryResponse {
|
|
176
182
|
query: string;
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
semantics: ActivatedSemantic[];
|
|
184
|
+
procedures?: ActivatedProcedure[];
|
|
179
185
|
episodes?: ActivatedEpisode[];
|
|
180
186
|
sources: GroundedSource[];
|
|
187
|
+
entities: ActivatedEntity[];
|
|
181
188
|
total_traversal_time_ms?: number;
|
|
182
189
|
token_count?: number;
|
|
183
190
|
}
|
|
@@ -211,6 +218,38 @@ declare class NebulaCollectionNotFoundException extends NebulaException {
|
|
|
211
218
|
declare class NebulaNotFoundException extends NebulaException {
|
|
212
219
|
constructor(resourceId: string, resourceType?: string);
|
|
213
220
|
}
|
|
221
|
+
/** Portable graph state envelope returned by export and consumed by compute/query. */
|
|
222
|
+
interface SnapshotEnvelope {
|
|
223
|
+
collection_id: string;
|
|
224
|
+
graph: GraphPayload;
|
|
225
|
+
root_hash: string;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
interface GraphPayload {
|
|
229
|
+
entities: Record<string, unknown>[];
|
|
230
|
+
relationships: Record<string, unknown>[];
|
|
231
|
+
entity_embeddings?: EmbeddingBlock;
|
|
232
|
+
relationship_desc_embeddings?: EmbeddingBlock;
|
|
233
|
+
relationship_rel_embeddings?: EmbeddingBlock;
|
|
234
|
+
[key: string]: unknown;
|
|
235
|
+
}
|
|
236
|
+
interface EmbeddingBlock {
|
|
237
|
+
dimension: number;
|
|
238
|
+
matrix_b64: string;
|
|
239
|
+
present_mask: boolean[];
|
|
240
|
+
}
|
|
241
|
+
/** Full-value diff produced by compute. */
|
|
242
|
+
interface PatchEnvelope {
|
|
243
|
+
collection_id: string;
|
|
244
|
+
previous_root_hash: string;
|
|
245
|
+
next_root_hash: string;
|
|
246
|
+
put_entities: Record<string, unknown>[];
|
|
247
|
+
delete_entities: string[];
|
|
248
|
+
put_relationships: Record<string, unknown>[];
|
|
249
|
+
delete_relationships: string[];
|
|
250
|
+
events: Record<string, unknown>[];
|
|
251
|
+
[key: string]: unknown;
|
|
252
|
+
}
|
|
214
253
|
|
|
215
254
|
/**
|
|
216
255
|
* Official Nebula JavaScript/TypeScript SDK
|
|
@@ -276,7 +315,7 @@ declare class Nebula {
|
|
|
276
315
|
* - If role is present, creates a conversation
|
|
277
316
|
* - Otherwise, creates a document
|
|
278
317
|
*/
|
|
279
|
-
storeMemory(memory: Memory$1 | Record<string, unknown>, name?: string): Promise<string
|
|
318
|
+
storeMemory(memory: Memory$1 | Record<string, unknown>, name?: string): Promise<string | Record<string, unknown>>;
|
|
280
319
|
/**
|
|
281
320
|
* Internal method to append content to an existing memory
|
|
282
321
|
*
|
|
@@ -480,6 +519,7 @@ declare class Nebula {
|
|
|
480
519
|
effort?: 'auto' | 'low' | 'medium' | 'high';
|
|
481
520
|
filters?: Record<string, unknown>;
|
|
482
521
|
searchSettings?: Record<string, unknown>;
|
|
522
|
+
snapshot?: Record<string, unknown>;
|
|
483
523
|
}): Promise<MemoryResponse>;
|
|
484
524
|
/** List available connector providers */
|
|
485
525
|
listProviders(): Promise<string[]>;
|
|
@@ -525,6 +565,15 @@ declare class Nebula {
|
|
|
525
565
|
bucket: string;
|
|
526
566
|
expires_in: number;
|
|
527
567
|
}>;
|
|
568
|
+
/**
|
|
569
|
+
* Export a collection's full graph state as a portable snapshot.
|
|
570
|
+
*/
|
|
571
|
+
exportSnapshot(collectionId: string): Promise<SnapshotEnvelope>;
|
|
572
|
+
/**
|
|
573
|
+
* Import a snapshot into an ephemeral server-side collection.
|
|
574
|
+
* @returns The ephemeral collection ID.
|
|
575
|
+
*/
|
|
576
|
+
importSnapshot(snapshot: SnapshotEnvelope | Record<string, unknown>): Promise<string>;
|
|
528
577
|
}
|
|
529
578
|
|
|
530
579
|
/**
|
|
@@ -547,4 +596,4 @@ type MemoryFactory = {
|
|
|
547
596
|
declare const Memory: MemoryFactory;
|
|
548
597
|
type Memory = Memory$1;
|
|
549
598
|
|
|
550
|
-
export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type
|
|
599
|
+
export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type ActivatedProcedure, type ActivatedSemantic, type Chunk, type Collection, type EmbeddingBlock, type FileContentPart, type GraphCommunityResult, type GraphEntityResult, type GraphPayload, type GraphRelationshipResult, GraphSearchResultType, type GroundedSource, Memory, type MemoryResponse, type MultimodalContentPart, Nebula, NebulaAuthenticationException, type NebulaClientConfig, NebulaClientException, NebulaCollectionNotFoundException, NebulaContent, NebulaException, NebulaNotFoundException, NebulaRateLimitException, NebulaValidationException, type PatchEnvelope, type S3FileReferencePart, type SearchOptions, type SearchResult, type SnapshotEnvelope, type StructuredChunk, type TextContentPart, Nebula as default };
|
package/dist/index.js
CHANGED
|
@@ -343,7 +343,7 @@ var _Nebula = class _Nebula {
|
|
|
343
343
|
*/
|
|
344
344
|
async storeMemory(memory, name) {
|
|
345
345
|
let mem;
|
|
346
|
-
if ("collection_id" in memory) {
|
|
346
|
+
if ("collection_id" in memory || "snapshot" in memory) {
|
|
347
347
|
mem = memory;
|
|
348
348
|
} else {
|
|
349
349
|
const memRecord2 = memory;
|
|
@@ -352,9 +352,23 @@ var _Nebula = class _Nebula {
|
|
|
352
352
|
content: memRecord2.content || "",
|
|
353
353
|
role: memRecord2.role,
|
|
354
354
|
memory_id: memRecord2.memory_id || memRecord2.memoryId || void 0,
|
|
355
|
-
metadata: memRecord2.metadata || {}
|
|
355
|
+
metadata: memRecord2.metadata || {},
|
|
356
|
+
snapshot: memRecord2.snapshot
|
|
356
357
|
};
|
|
357
358
|
}
|
|
359
|
+
if (mem.snapshot) {
|
|
360
|
+
const contentText = await this._serializeContentAsText(mem.content);
|
|
361
|
+
const payload2 = {
|
|
362
|
+
snapshot: mem.snapshot,
|
|
363
|
+
raw_text: contentText
|
|
364
|
+
};
|
|
365
|
+
const response2 = await this._makeRequest("POST", "/v1/memories", payload2);
|
|
366
|
+
const snapshot = response2?.results?.snapshot;
|
|
367
|
+
if (snapshot) {
|
|
368
|
+
return snapshot;
|
|
369
|
+
}
|
|
370
|
+
return response2?.results ?? {};
|
|
371
|
+
}
|
|
358
372
|
if (mem.memory_id) {
|
|
359
373
|
return await this._appendToMemory(mem.memory_id, mem);
|
|
360
374
|
}
|
|
@@ -823,6 +837,27 @@ var _Nebula = class _Nebula {
|
|
|
823
837
|
* https://docs.trynebula.ai/guides/metadata-filtering
|
|
824
838
|
*/
|
|
825
839
|
async search(options) {
|
|
840
|
+
if (options.snapshot) {
|
|
841
|
+
const snapshotData = {
|
|
842
|
+
snapshot: options.snapshot,
|
|
843
|
+
query: options.query
|
|
844
|
+
};
|
|
845
|
+
if (options.effort) {
|
|
846
|
+
snapshotData.effort = options.effort;
|
|
847
|
+
}
|
|
848
|
+
const response2 = await this._makeRequest("POST", "/v1/memories/search", snapshotData);
|
|
849
|
+
const memoryResponseData2 = response2.results;
|
|
850
|
+
return {
|
|
851
|
+
query: memoryResponseData2.query || options.query,
|
|
852
|
+
semantics: memoryResponseData2.semantics || memoryResponseData2.knowledge || [],
|
|
853
|
+
procedures: memoryResponseData2.procedures || [],
|
|
854
|
+
episodes: memoryResponseData2.episodes || [],
|
|
855
|
+
sources: memoryResponseData2.sources || [],
|
|
856
|
+
total_traversal_time_ms: memoryResponseData2.total_traversal_time_ms,
|
|
857
|
+
token_count: memoryResponseData2.token_count,
|
|
858
|
+
entities: memoryResponseData2.entities || []
|
|
859
|
+
};
|
|
860
|
+
}
|
|
826
861
|
const data = {
|
|
827
862
|
query: options.query
|
|
828
863
|
};
|
|
@@ -843,17 +878,23 @@ var _Nebula = class _Nebula {
|
|
|
843
878
|
data.search_settings = options.searchSettings;
|
|
844
879
|
}
|
|
845
880
|
const collectionIds = data.collection_ids;
|
|
846
|
-
|
|
881
|
+
let extraHeaders;
|
|
882
|
+
if (collectionIds && collectionIds.length === 1) {
|
|
883
|
+
extraHeaders = { "X-Nebula-Collection-Id": collectionIds[0] };
|
|
884
|
+
} else if (collectionIds && collectionIds.length > 1) {
|
|
885
|
+
extraHeaders = { "X-Nebula-Collection-Id": [...collectionIds].sort().join(",") };
|
|
886
|
+
}
|
|
847
887
|
const response = await this._makeRequest("POST", "/v1/memories/search", data, void 0, extraHeaders);
|
|
848
888
|
const memoryResponseData = response.results;
|
|
849
889
|
const memoryResponse = {
|
|
850
890
|
query: memoryResponseData.query || options.query,
|
|
851
|
-
|
|
852
|
-
|
|
891
|
+
semantics: memoryResponseData.semantics || memoryResponseData.knowledge || [],
|
|
892
|
+
procedures: memoryResponseData.procedures || [],
|
|
853
893
|
episodes: memoryResponseData.episodes || [],
|
|
854
894
|
sources: memoryResponseData.sources || [],
|
|
855
895
|
total_traversal_time_ms: memoryResponseData.total_traversal_time_ms,
|
|
856
|
-
token_count: memoryResponseData.token_count
|
|
896
|
+
token_count: memoryResponseData.token_count,
|
|
897
|
+
entities: memoryResponseData.entities || []
|
|
857
898
|
};
|
|
858
899
|
return memoryResponse;
|
|
859
900
|
}
|
|
@@ -1177,6 +1218,29 @@ var _Nebula = class _Nebula {
|
|
|
1177
1218
|
}
|
|
1178
1219
|
return response;
|
|
1179
1220
|
}
|
|
1221
|
+
// ------------------------------------------------------------------
|
|
1222
|
+
// Device Memory
|
|
1223
|
+
// ------------------------------------------------------------------
|
|
1224
|
+
/**
|
|
1225
|
+
* Export a collection's full graph state as a portable snapshot.
|
|
1226
|
+
*/
|
|
1227
|
+
async exportSnapshot(collectionId) {
|
|
1228
|
+
const response = await this._makeRequest("POST", "/v1/device-memory/snapshot/export", {
|
|
1229
|
+
collection_id: collectionId
|
|
1230
|
+
});
|
|
1231
|
+
return response.results ?? response;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Import a snapshot into an ephemeral server-side collection.
|
|
1235
|
+
* @returns The ephemeral collection ID.
|
|
1236
|
+
*/
|
|
1237
|
+
async importSnapshot(snapshot) {
|
|
1238
|
+
const response = await this._makeRequest("POST", "/v1/device-memory/snapshot/import", {
|
|
1239
|
+
snapshot
|
|
1240
|
+
});
|
|
1241
|
+
const result = response.results ?? response;
|
|
1242
|
+
return result.ephemeral_collection_id ?? "";
|
|
1243
|
+
}
|
|
1180
1244
|
};
|
|
1181
1245
|
// Files larger than 5MB are automatically uploaded to S3
|
|
1182
1246
|
_Nebula.MAX_INLINE_SIZE = 5 * 1024 * 1024;
|