@nebula-ai/sdk 0.0.24 → 0.0.29

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
@@ -29,26 +29,26 @@ const client = new NebulaClient({
29
29
  });
30
30
 
31
31
  // Create a cluster
32
- const cluster = await client.createCluster(
33
- 'My Project',
34
- 'A collection of project memories'
35
- );
32
+ const cluster = await client.createCluster({
33
+ name: 'My Project',
34
+ description: 'A collection of project memories'
35
+ });
36
36
 
37
37
  // Store a memory using the unified Memory model
38
38
  const memoryId = await client.storeMemory({
39
- cluster_id: cluster.id,
39
+ collection_id: cluster.id,
40
40
  content: 'This is an important piece of information about my project.',
41
41
  metadata: { category: 'project', priority: 'high' }
42
42
  });
43
43
 
44
44
  // Search for memories with advanced options
45
- const results = await client.search(
46
- 'project information',
47
- [cluster.id],
48
- 5,
49
- RetrievalType.ADVANCED,
50
- { 'metadata.category': 'project' }
51
- );
45
+ const results = await client.search({
46
+ query: 'project information',
47
+ collection_ids: [cluster.id],
48
+ limit: 5,
49
+ retrieval_type: RetrievalType.ADVANCED,
50
+ filters: { 'metadata.category': 'project' }
51
+ });
52
52
 
53
53
  console.log('Found memories:', results);
54
54
  ```
@@ -72,29 +72,42 @@ new NebulaClient(config: NebulaClientConfig)
72
72
 
73
73
  ```typescript
74
74
  // Create a new cluster
75
- await client.createCluster(name: string, description?: string, metadata?: Record<string, any>)
75
+ await client.createCluster(options: { name: string, description?: string, metadata?: Record<string, any> })
76
76
 
77
77
  // Get a cluster by ID
78
- await client.getCluster(clusterId: string)
78
+ await client.getCluster(collectionId: string)
79
79
 
80
80
  // Get a cluster by name
81
81
  await client.getClusterByName(name: string)
82
82
 
83
83
  // List all clusters
84
- await client.listClusters(limit?: number, offset?: number)
84
+ await client.listClusters(options?: { limit?: number, offset?: number })
85
85
 
86
86
  // Update a cluster
87
- await client.updateCluster(clusterId: string, name?: string, description?: string, metadata?: Record<string, any>)
87
+ await client.updateCluster(options: { collectionId: string, name?: string, description?: string, metadata?: Record<string, any> })
88
88
 
89
89
  // Delete a cluster
90
- await client.deleteCluster(clusterId: string)
90
+ await client.deleteCluster(collectionId: string)
91
91
  ```
92
92
 
93
93
  #### Conversations
94
94
 
95
95
  ```typescript
96
96
  // List conversations for the authenticated user
97
- await client.listConversations(limit?: number, offset?: number, cluster_ids?: string[])
97
+ await client.listConversations(options?: {
98
+ limit?: number,
99
+ offset?: number,
100
+ collection_ids?: string[],
101
+ metadata_filters?: Record<string, any> // MongoDB-like operators: $eq, $ne, $in, $nin, $exists, $and, $or
102
+ })
103
+
104
+ // Example: Filter playground conversations
105
+ const playgroundConversations = await client.listConversations({
106
+ collection_ids: ['cluster-id'],
107
+ metadata_filters: {
108
+ 'metadata.playground': { $eq: true }
109
+ }
110
+ });
98
111
 
99
112
  // Get conversation messages
100
113
  await client.getConversationMessages(conversationId: string): Promise<MemoryResponse[]>
@@ -117,24 +130,52 @@ await client.storeMemories(memories: Memory[])
117
130
  await client.getMemory(memoryId: string)
118
131
 
119
132
  // List memories from clusters
120
- await client.listMemories(clusterIds: string | string[], limit?: number, offset?: number)
133
+ await client.listMemories(options: {
134
+ collection_ids: string | string[],
135
+ limit?: number,
136
+ offset?: number,
137
+ metadata_filters?: Record<string, any> // MongoDB-like operators: $eq, $ne, $in, $nin, $exists, $and, $or
138
+ })
139
+
140
+ // Example: List memories excluding conversations
141
+ const memories = await client.listMemories({
142
+ collection_ids: ['cluster-id'],
143
+ metadata_filters: {
144
+ 'metadata.content_type': { $ne: 'conversation' }
145
+ }
146
+ });
147
+
148
+ // Example: Complex filter with multiple conditions
149
+ const playgroundMemories = await client.listMemories({
150
+ collection_ids: ['cluster-id'],
151
+ metadata_filters: {
152
+ $and: [
153
+ { 'metadata.playground': { $eq: true } },
154
+ { 'metadata.session_id': { $exists: true } }
155
+ ]
156
+ }
157
+ });
121
158
 
122
- // Delete a memory
123
- await client.delete(memoryId: string)
159
+ // Delete one or more memories
160
+ // Single deletion:
161
+ await client.delete('memory-id') // Returns: boolean
162
+
163
+ // Batch deletion:
164
+ await client.delete(['id1', 'id2', 'id3']) // Returns: detailed results object
124
165
  ```
125
166
 
126
167
  #### Search
127
168
 
128
169
  ```typescript
129
170
  // Search within clusters
130
- await client.search(
171
+ await client.search(options: {
131
172
  query: string,
132
- clusters: string | string[],
133
- limitOrOptions?: number | { limit?: number },
134
- retrievalType?: RetrievalType | string,
173
+ collection_ids: string | string[],
174
+ limit?: number,
175
+ retrieval_type?: RetrievalType | string,
135
176
  filters?: Record<string, any>,
136
177
  searchSettings?: Record<string, any>
137
- )
178
+ })
138
179
  ```
139
180
 
140
181
  #### Health Check
@@ -150,7 +191,7 @@ await client.healthCheck()
150
191
 
151
192
  ```typescript
152
193
  interface Memory {
153
- cluster_id: string; // Required: cluster to store in
194
+ collection_id: string; // Required: cluster to store in
154
195
  content: string; // Required: text content
155
196
  role?: string; // Optional: 'user', 'assistant', or custom (for conversations)
156
197
  parent_id?: string; // Optional: conversation ID (for conversations)
@@ -166,7 +207,7 @@ interface MemoryResponse {
166
207
  content?: string;
167
208
  chunks?: string[];
168
209
  metadata: Record<string, any>;
169
- cluster_ids: string[];
210
+ collection_ids: string[];
170
211
  created_at?: string;
171
212
  updated_at?: string;
172
213
  }
@@ -220,13 +261,13 @@ enum RetrievalType {
220
261
  The search method supports advanced configuration:
221
262
 
222
263
  ```typescript
223
- const results = await client.search(
224
- 'query',
225
- [clusterId],
226
- 10,
227
- RetrievalType.ADVANCED,
228
- { 'metadata.category': 'science' },
229
- {
264
+ const results = await client.search({
265
+ query: 'query',
266
+ collection_ids: [collectionId],
267
+ limit: 10,
268
+ retrieval_type: RetrievalType.ADVANCED,
269
+ filters: { 'metadata.category': 'science' },
270
+ searchSettings: {
230
271
  graph_settings: {
231
272
  enabled: true,
232
273
  bfs_enabled: true,
@@ -234,7 +275,7 @@ const results = await client.search(
234
275
  },
235
276
  num_sub_queries: 3
236
277
  }
237
- );
278
+ });
238
279
  ```
239
280
 
240
281
  ### Error Handling
@@ -252,7 +293,7 @@ import {
252
293
  } from '@nebula-ai/sdk';
253
294
 
254
295
  try {
255
- await client.search('query', [clusterId]);
296
+ await client.search({ query: 'query', collection_ids: [collectionId] });
256
297
  } catch (error) {
257
298
  if (error instanceof NebulaAuthenticationException) {
258
299
  console.log('Invalid API key');
@@ -277,20 +318,20 @@ const client = new NebulaClient({ apiKey: 'your-key' });
277
318
 
278
319
  async function manageMemories() {
279
320
  // Create a cluster
280
- const cluster = await client.createCluster(
281
- 'Knowledge Base',
282
- 'My personal knowledge repository'
283
- );
321
+ const cluster = await client.createCluster({
322
+ name: 'Knowledge Base',
323
+ description: 'My personal knowledge repository'
324
+ });
284
325
 
285
326
  // Store memories using the unified model
286
327
  const memories = [
287
328
  {
288
- cluster_id: cluster.id,
329
+ collection_id: cluster.id,
289
330
  content: 'JavaScript is a programming language',
290
331
  metadata: { category: 'programming', difficulty: 'beginner' }
291
332
  },
292
333
  {
293
- cluster_id: cluster.id,
334
+ collection_id: cluster.id,
294
335
  content: 'TypeScript adds static typing to JavaScript',
295
336
  metadata: { category: 'programming', difficulty: 'beginner' }
296
337
  }
@@ -301,8 +342,24 @@ async function manageMemories() {
301
342
  console.log('Stored memories:', memoryIds);
302
343
 
303
344
  // Search for memories
304
- const results = await client.search('JavaScript', [cluster.id]);
345
+ const results = await client.search({ query: 'JavaScript', collection_ids: [cluster.id] });
305
346
  console.log('Search results:', results);
347
+
348
+ // Delete a single memory
349
+ const deleted = await client.delete(memoryIds[0]);
350
+ console.log('Deleted single memory:', deleted); // true
351
+
352
+ // Delete multiple memories at once
353
+ const batchResult = await client.delete([memoryIds[1], memoryIds[2]]);
354
+ console.log('Batch deletion results:', batchResult);
355
+ // {
356
+ // message: "Deleted 2 of 2 documents",
357
+ // results: {
358
+ // successful: ["id1", "id2"],
359
+ // failed: [],
360
+ // summary: { total: 2, succeeded: 2, failed: 0 }
361
+ // }
362
+ // }
306
363
  }
307
364
  ```
308
365
 
@@ -314,18 +371,21 @@ import { NebulaClient } from '@nebula-ai/sdk';
314
371
  const client = new NebulaClient({ apiKey: 'your-key' });
315
372
 
316
373
  async function trackConversation() {
317
- const cluster = await client.createCluster('Conversations', 'AI chat history');
374
+ const cluster = await client.createCluster({
375
+ name: 'Conversations',
376
+ description: 'AI chat history'
377
+ });
318
378
 
319
379
  // Store conversation turns
320
380
  const conversationMemories = [
321
381
  {
322
- cluster_id: cluster.id,
382
+ collection_id: cluster.id,
323
383
  content: 'What is machine learning?',
324
384
  role: 'user',
325
385
  metadata: { topic: 'AI' }
326
386
  },
327
387
  {
328
- cluster_id: cluster.id,
388
+ collection_id: cluster.id,
329
389
  content: 'Machine learning is a subset of AI...',
330
390
  role: 'assistant',
331
391
  metadata: { topic: 'AI' }
@@ -350,7 +410,7 @@ const client = new NebulaClient({ apiKey: 'your-key' });
350
410
 
351
411
  async function manageConversations() {
352
412
  // List all conversations
353
- const conversations = await client.listConversations(10, 0);
413
+ const conversations = await client.listConversations({ limit: 10, offset: 0 });
354
414
  console.log('All conversations:', conversations);
355
415
 
356
416
  // Get messages from a specific conversation
@@ -375,30 +435,32 @@ import { NebulaClient, RetrievalType } from '@nebula-ai/sdk';
375
435
  const client = new NebulaClient({ apiKey: 'your-key' });
376
436
 
377
437
  async function advancedSearch() {
378
- const cluster = await client.createCluster('Knowledge Graph', 'Entity relationships');
438
+ const cluster = await client.createCluster({
439
+ name: 'Knowledge Graph',
440
+ description: 'Entity relationships'
441
+ });
379
442
 
380
443
  // Store knowledge graph data
381
444
  await client.storeMemory({
382
- cluster_id: cluster.id,
445
+ collection_id: cluster.id,
383
446
  content: 'Einstein developed the theory of relativity',
384
447
  metadata: { entity: 'Einstein', concept: 'relativity', field: 'physics' }
385
448
  });
386
449
 
387
450
  // Search with graph settings
388
- const results = await client.search(
389
- 'Einstein relativity',
390
- [cluster.id],
391
- 10,
392
- RetrievalType.ADVANCED,
393
- undefined,
394
- {
451
+ const results = await client.search({
452
+ query: 'Einstein relativity',
453
+ collection_ids: [cluster.id],
454
+ limit: 10,
455
+ retrieval_type: RetrievalType.ADVANCED,
456
+ searchSettings: {
395
457
  graph_settings: {
396
458
  enabled: true,
397
459
  bfs_enabled: true,
398
460
  bfs_max_depth: 2
399
461
  }
400
462
  }
401
- );
463
+ });
402
464
 
403
465
  // Handle both chunk and graph results
404
466
  results.forEach(result => {