@nebula-ai/sdk 1.2.0 → 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 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 {
@@ -218,6 +218,38 @@ declare class NebulaCollectionNotFoundException extends NebulaException {
218
218
  declare class NebulaNotFoundException extends NebulaException {
219
219
  constructor(resourceId: string, resourceType?: string);
220
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
+ }
221
253
 
222
254
  /**
223
255
  * Official Nebula JavaScript/TypeScript SDK
@@ -283,7 +315,7 @@ declare class Nebula {
283
315
  * - If role is present, creates a conversation
284
316
  * - Otherwise, creates a document
285
317
  */
286
- 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>>;
287
319
  /**
288
320
  * Internal method to append content to an existing memory
289
321
  *
@@ -487,6 +519,7 @@ declare class Nebula {
487
519
  effort?: 'auto' | 'low' | 'medium' | 'high';
488
520
  filters?: Record<string, unknown>;
489
521
  searchSettings?: Record<string, unknown>;
522
+ snapshot?: Record<string, unknown>;
490
523
  }): Promise<MemoryResponse>;
491
524
  /** List available connector providers */
492
525
  listProviders(): Promise<string[]>;
@@ -532,6 +565,15 @@ declare class Nebula {
532
565
  bucket: string;
533
566
  expires_in: number;
534
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>;
535
577
  }
536
578
 
537
579
  /**
@@ -554,4 +596,4 @@ type MemoryFactory = {
554
596
  declare const Memory: MemoryFactory;
555
597
  type Memory = Memory$1;
556
598
 
557
- export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type ActivatedProcedure, type ActivatedSemantic, type Chunk, type Collection, type FileContentPart, type GraphCommunityResult, type GraphEntityResult, type GraphRelationshipResult, GraphSearchResultType, type GroundedSource, Memory, type MemoryResponse, type MultimodalContentPart, Nebula, NebulaAuthenticationException, type NebulaClientConfig, NebulaClientException, NebulaCollectionNotFoundException, NebulaContent, NebulaException, NebulaNotFoundException, NebulaRateLimitException, NebulaValidationException, type S3FileReferencePart, type SearchOptions, type SearchResult, type StructuredChunk, type TextContentPart, Nebula as default };
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 {
@@ -218,6 +218,38 @@ declare class NebulaCollectionNotFoundException extends NebulaException {
218
218
  declare class NebulaNotFoundException extends NebulaException {
219
219
  constructor(resourceId: string, resourceType?: string);
220
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
+ }
221
253
 
222
254
  /**
223
255
  * Official Nebula JavaScript/TypeScript SDK
@@ -283,7 +315,7 @@ declare class Nebula {
283
315
  * - If role is present, creates a conversation
284
316
  * - Otherwise, creates a document
285
317
  */
286
- 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>>;
287
319
  /**
288
320
  * Internal method to append content to an existing memory
289
321
  *
@@ -487,6 +519,7 @@ declare class Nebula {
487
519
  effort?: 'auto' | 'low' | 'medium' | 'high';
488
520
  filters?: Record<string, unknown>;
489
521
  searchSettings?: Record<string, unknown>;
522
+ snapshot?: Record<string, unknown>;
490
523
  }): Promise<MemoryResponse>;
491
524
  /** List available connector providers */
492
525
  listProviders(): Promise<string[]>;
@@ -532,6 +565,15 @@ declare class Nebula {
532
565
  bucket: string;
533
566
  expires_in: number;
534
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>;
535
577
  }
536
578
 
537
579
  /**
@@ -554,4 +596,4 @@ type MemoryFactory = {
554
596
  declare const Memory: MemoryFactory;
555
597
  type Memory = Memory$1;
556
598
 
557
- export { type ActivatedEntity, type ActivatedEpisode, type ActivatedFacet, type ActivatedProcedure, type ActivatedSemantic, type Chunk, type Collection, type FileContentPart, type GraphCommunityResult, type GraphEntityResult, type GraphRelationshipResult, GraphSearchResultType, type GroundedSource, Memory, type MemoryResponse, type MultimodalContentPart, Nebula, NebulaAuthenticationException, type NebulaClientConfig, NebulaClientException, NebulaCollectionNotFoundException, NebulaContent, NebulaException, NebulaNotFoundException, NebulaRateLimitException, NebulaValidationException, type S3FileReferencePart, type SearchOptions, type SearchResult, type StructuredChunk, type TextContentPart, Nebula as default };
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,7 +878,12 @@ var _Nebula = class _Nebula {
843
878
  data.search_settings = options.searchSettings;
844
879
  }
845
880
  const collectionIds = data.collection_ids;
846
- const extraHeaders = collectionIds && collectionIds.length === 1 ? { "X-Nebula-Collection-Id": collectionIds[0] } : void 0;
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 = {
@@ -1178,6 +1218,29 @@ var _Nebula = class _Nebula {
1178
1218
  }
1179
1219
  return response;
1180
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
+ }
1181
1244
  };
1182
1245
  // Files larger than 5MB are automatically uploaded to S3
1183
1246
  _Nebula.MAX_INLINE_SIZE = 5 * 1024 * 1024;