@nebula-ai/sdk 0.0.21 → 0.0.27

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/dist/index.js CHANGED
@@ -1,12 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  // src/types.ts
4
- var RetrievalType = /* @__PURE__ */ ((RetrievalType2) => {
5
- RetrievalType2["BASIC"] = "basic";
6
- RetrievalType2["ADVANCED"] = "advanced";
7
- RetrievalType2["CUSTOM"] = "custom";
8
- return RetrievalType2;
9
- })(RetrievalType || {});
10
4
  var GraphSearchResultType = /* @__PURE__ */ ((GraphSearchResultType2) => {
11
5
  GraphSearchResultType2["ENTITY"] = "entity";
12
6
  GraphSearchResultType2["RELATIONSHIP"] = "relationship";
@@ -163,10 +157,10 @@ var NebulaClient = class {
163
157
  }
164
158
  // Cluster Management Methods
165
159
  /** Create a new cluster */
166
- async createCluster(name, description, metadata) {
167
- const data = { name };
168
- if (description) data.description = description;
169
- if (metadata) data.metadata = metadata;
160
+ async createCluster(options) {
161
+ const data = { name: options.name };
162
+ if (options.description) data.description = options.description;
163
+ if (options.metadata) data.metadata = options.metadata;
170
164
  const response = await this._makeRequest("POST", "/v1/collections", data);
171
165
  const result = response.results || response;
172
166
  return this._clusterFromDict(result);
@@ -184,8 +178,11 @@ var NebulaClient = class {
184
178
  return this._clusterFromDict(result);
185
179
  }
186
180
  /** Get all clusters */
187
- async listClusters(limit = 100, offset = 0) {
188
- const params = { limit, offset };
181
+ async listClusters(options) {
182
+ const params = {
183
+ limit: options?.limit ?? 100,
184
+ offset: options?.offset ?? 0
185
+ };
189
186
  const response = await this._makeRequest("GET", "/v1/collections", void 0, params);
190
187
  let clusters;
191
188
  if (response.results) {
@@ -199,10 +196,13 @@ var NebulaClient = class {
199
196
  }
200
197
  // Conversations Methods
201
198
  /** List conversations for the authenticated user */
202
- async listConversations(limit = 100, offset = 0, cluster_ids) {
203
- const params = { limit, offset };
204
- if (cluster_ids && cluster_ids.length > 0) {
205
- params.collection_ids = cluster_ids;
199
+ async listConversations(options) {
200
+ const params = {
201
+ limit: options?.limit ?? 100,
202
+ offset: options?.offset ?? 0
203
+ };
204
+ if (options?.cluster_ids && options.cluster_ids.length > 0) {
205
+ params.collection_ids = options.cluster_ids;
206
206
  }
207
207
  const response = await this._makeRequest("GET", "/v1/conversations", void 0, params);
208
208
  let conversations;
@@ -288,12 +288,12 @@ var NebulaClient = class {
288
288
  });
289
289
  }
290
290
  /** Update a cluster */
291
- async updateCluster(clusterId, name, description, metadata) {
291
+ async updateCluster(options) {
292
292
  const data = {};
293
- if (name !== void 0) data.name = name;
294
- if (description !== void 0) data.description = description;
295
- if (metadata !== void 0) data.metadata = metadata;
296
- const response = await this._makeRequest("POST", `/v1/collections/${clusterId}`, data);
293
+ if (options.name !== void 0) data.name = options.name;
294
+ if (options.description !== void 0) data.description = options.description;
295
+ if (options.metadata !== void 0) data.metadata = options.metadata;
296
+ const response = await this._makeRequest("POST", `/v1/collections/${options.clusterId}`, data);
297
297
  const result = response.results || response;
298
298
  return this._clusterFromDict(result);
299
299
  }
@@ -456,11 +456,29 @@ var NebulaClient = class {
456
456
  }
457
457
  return results;
458
458
  }
459
- /** Delete a specific memory */
460
- async delete(memoryId) {
459
+ /** Delete one or more memories */
460
+ async delete(memoryIds) {
461
461
  try {
462
- await this._makeRequest("DELETE", `/v1/documents/${memoryId}`);
463
- return true;
462
+ if (typeof memoryIds === "string") {
463
+ try {
464
+ await this._makeRequest("DELETE", `/v1/documents/${memoryIds}`);
465
+ return true;
466
+ } catch {
467
+ try {
468
+ const response = await this._makeRequest("POST", "/v1/documents/delete", {
469
+ ids: memoryIds
470
+ });
471
+ return typeof response === "object" && response.success !== void 0 ? response.success : true;
472
+ } catch (error) {
473
+ throw error;
474
+ }
475
+ }
476
+ } else {
477
+ const response = await this._makeRequest("POST", "/v1/documents/delete", {
478
+ ids: memoryIds
479
+ });
480
+ return response;
481
+ }
464
482
  } catch (error) {
465
483
  if (error instanceof Error) {
466
484
  throw error;
@@ -481,12 +499,16 @@ var NebulaClient = class {
481
499
  }
482
500
  }
483
501
  /** Get all memories from specific clusters */
484
- async listMemories(clusterIds, limit = 100, offset = 0) {
485
- const ids = Array.isArray(clusterIds) ? clusterIds : [clusterIds];
502
+ async listMemories(options) {
503
+ const ids = Array.isArray(options.cluster_ids) ? options.cluster_ids : [options.cluster_ids];
486
504
  if (!ids.length) {
487
505
  throw new NebulaClientException("cluster_ids must be provided to list_memories().");
488
506
  }
489
- const params = { limit, offset, collection_ids: ids };
507
+ const params = {
508
+ limit: options.limit ?? 100,
509
+ offset: options.offset ?? 0,
510
+ collection_ids: ids
511
+ };
490
512
  const response = await this._makeRequest("GET", "/v1/documents", void 0, params);
491
513
  let documents;
492
514
  if (response.results) {
@@ -513,49 +535,122 @@ var NebulaClient = class {
513
535
  return this._memoryResponseFromDict(memoryData, []);
514
536
  }
515
537
  // Search Methods
516
- /** Search within specific clusters */
517
- async search(query, clusters, limitOrOptions, retrievalType = "advanced" /* ADVANCED */, filters, searchSettings) {
518
- const clusterIds = Array.isArray(clusters) ? clusters : [clusters];
538
+ /**
539
+ * Search within specific clusters with optional metadata filtering.
540
+ *
541
+ * @param options - Search configuration
542
+ * @param options.query - Search query string
543
+ * @param options.cluster_ids - One or more cluster IDs to search within
544
+ * @param options.limit - Maximum number of results to return (default: 10)
545
+ * @param options.retrieval_type - Retrieval strategy (default: ADVANCED)
546
+ * @param options.filters - Optional filters to apply to the search. Supports comprehensive metadata filtering
547
+ * with MongoDB-like operators for both vector/chunk search and graph search.
548
+ * @param options.searchSettings - Optional search configuration
549
+ *
550
+ * @returns Promise resolving to array of SearchResult objects containing both vector/chunk and graph search results
551
+ *
552
+ * @example
553
+ * // Basic equality filter
554
+ * await client.search({
555
+ * query: "machine learning",
556
+ * cluster_ids: ["research-cluster"],
557
+ * filters: {
558
+ * "metadata.category": { $eq: "research" },
559
+ * "metadata.verified": true // Shorthand for $eq
560
+ * }
561
+ * });
562
+ *
563
+ * @example
564
+ * // Numeric comparisons
565
+ * await client.search({
566
+ * query: "high priority",
567
+ * cluster_ids: ["tasks"],
568
+ * filters: {
569
+ * "metadata.priority": { $gte: 8 },
570
+ * "metadata.score": { $lt: 100 }
571
+ * }
572
+ * });
573
+ *
574
+ * @example
575
+ * // String matching
576
+ * await client.search({
577
+ * query: "employees",
578
+ * cluster_ids: ["team"],
579
+ * filters: {
580
+ * "metadata.email": { $ilike: "%@company.com" } // Case-insensitive
581
+ * }
582
+ * });
583
+ *
584
+ * @example
585
+ * // Array operations
586
+ * await client.search({
587
+ * query: "developers",
588
+ * cluster_ids: ["team"],
589
+ * filters: {
590
+ * "metadata.skills": { $overlap: ["python", "typescript"] } // Has any
591
+ * }
592
+ * });
593
+ *
594
+ * @example
595
+ * // Nested paths
596
+ * await client.search({
597
+ * query: "users",
598
+ * cluster_ids: ["profiles"],
599
+ * filters: {
600
+ * "metadata.user.preferences.theme": { $eq: "dark" }
601
+ * }
602
+ * });
603
+ *
604
+ * @example
605
+ * // Complex logical combinations
606
+ * await client.search({
607
+ * query: "candidates",
608
+ * cluster_ids: ["hiring"],
609
+ * filters: {
610
+ * $and: [
611
+ * { "metadata.verified": true },
612
+ * { "metadata.level": { $gte: 5 } },
613
+ * {
614
+ * $or: [
615
+ * { "metadata.skills": { $overlap: ["python", "go"] } },
616
+ * { "metadata.years_experience": { $gte: 8 } }
617
+ * ]
618
+ * }
619
+ * ]
620
+ * }
621
+ * });
622
+ *
623
+ * @remarks
624
+ * Supported Operators:
625
+ * - Comparison: $eq, $ne, $lt, $lte, $gt, $gte
626
+ * - String: $like (case-sensitive), $ilike (case-insensitive)
627
+ * - Array: $in, $nin, $overlap, $contains
628
+ * - JSONB: $json_contains
629
+ * - Logical: $and, $or
630
+ *
631
+ * For comprehensive filtering documentation, see the Metadata Filtering Guide:
632
+ * https://docs.nebulacloud.app/guides/metadata-filtering
633
+ */
634
+ async search(options) {
635
+ const clusterIds = Array.isArray(options.cluster_ids) ? options.cluster_ids : [options.cluster_ids];
519
636
  if (!clusterIds.length) {
520
637
  throw new NebulaClientException("cluster_ids must be provided to search().");
521
638
  }
522
- let limit = 10;
523
- if (typeof limitOrOptions === "number") {
524
- limit = limitOrOptions;
525
- } else if (typeof limitOrOptions === "object" && limitOrOptions) {
526
- if (typeof limitOrOptions.limit === "number") limit = limitOrOptions.limit;
527
- }
528
- if (typeof retrievalType === "string") {
529
- retrievalType = RetrievalType[retrievalType.toUpperCase()] || "advanced" /* ADVANCED */;
530
- }
531
- const effectiveSettings = { ...searchSettings };
532
- effectiveSettings.limit = limit;
533
- effectiveSettings.use_semantic_search = false;
534
- effectiveSettings.use_fulltext_search = false;
535
- effectiveSettings.use_hybrid_search = false;
536
- effectiveSettings.chunk_settings = {
537
- ...effectiveSettings.chunk_settings || {},
538
- enabled: false
639
+ const limit = options.limit ?? 10;
640
+ const searchMode = options.search_mode ?? "super";
641
+ const effectiveSettings = {
642
+ ...options.searchSettings
539
643
  };
540
- effectiveSettings.search_strategy = "rag_fusion";
541
- effectiveSettings.num_sub_queries = 3;
542
- const gs = { ...effectiveSettings.graph_settings };
543
- gs.enabled = true;
544
- gs.bfs_enabled = true;
545
- gs.bfs_max_depth = 2;
546
- effectiveSettings.graph_settings = gs;
547
- if (retrievalType !== "advanced" /* ADVANCED */) {
548
- effectiveSettings.retrieval_type = retrievalType;
549
- }
644
+ effectiveSettings.limit = limit;
550
645
  const userFilters = { ...effectiveSettings.filters };
551
- if (filters) {
552
- Object.assign(userFilters, filters);
646
+ if (options.filters) {
647
+ Object.assign(userFilters, options.filters);
553
648
  }
554
649
  userFilters.collection_ids = { $overlap: clusterIds };
555
650
  effectiveSettings.filters = userFilters;
556
651
  const data = {
557
- query,
558
- search_mode: "custom",
652
+ query: options.query,
653
+ search_mode: searchMode,
559
654
  search_settings: effectiveSettings
560
655
  };
561
656
  const response = await this._makeRequest("POST", "/v1/retrieval/search", data);
@@ -589,7 +684,12 @@ Assistant: ${String(assistantMessage || "")}`;
589
684
  if (sessionId && !includeAllSessions) {
590
685
  filters["metadata.session_id"] = sessionId;
591
686
  }
592
- return this.search(query, [clusterId], { limit: 10 }, "advanced" /* ADVANCED */, filters);
687
+ return this.search({
688
+ query,
689
+ cluster_ids: [clusterId],
690
+ limit: 10,
691
+ filters
692
+ });
593
693
  }
594
694
  // Health Check
595
695
  async healthCheck() {
@@ -685,6 +785,23 @@ Assistant: ${String(assistantMessage || "")}`;
685
785
  const score = data.score !== void 0 ? Number(data.score) : 0;
686
786
  const metadata = data.metadata || {};
687
787
  const chunkIds = Array.isArray(data.chunk_ids) ? data.chunk_ids : void 0;
788
+ let timestamp;
789
+ if (data.timestamp) {
790
+ if (typeof data.timestamp === "string") {
791
+ timestamp = data.timestamp;
792
+ } else if (data.timestamp instanceof Date) {
793
+ timestamp = data.timestamp.toISOString();
794
+ } else {
795
+ const parsed = new Date(data.timestamp);
796
+ if (!Number.isNaN(parsed.valueOf())) {
797
+ timestamp = parsed.toISOString();
798
+ }
799
+ }
800
+ }
801
+ const displayName = typeof data.display_name === "string" ? data.display_name : void 0;
802
+ const sourceRole = typeof data.source_role === "string" ? data.source_role : void 0;
803
+ const documentId = data.document_id ? String(data.document_id) : void 0;
804
+ const ownerId = data.owner_id ? String(data.owner_id) : void 0;
688
805
  let entity;
689
806
  let rel;
690
807
  let comm;
@@ -724,7 +841,12 @@ Assistant: ${String(assistantMessage || "")}`;
724
841
  graph_entity: entity,
725
842
  graph_relationship: rel,
726
843
  graph_community: comm,
727
- chunk_ids: chunkIds
844
+ chunk_ids: chunkIds,
845
+ timestamp,
846
+ display_name: displayName,
847
+ source_role: sourceRole,
848
+ document_id: documentId,
849
+ owner_id: ownerId
728
850
  };
729
851
  }
730
852
  async _sha256(message) {
@@ -751,6 +873,5 @@ exports.NebulaClusterNotFoundException = NebulaClusterNotFoundException;
751
873
  exports.NebulaException = NebulaException;
752
874
  exports.NebulaRateLimitException = NebulaRateLimitException;
753
875
  exports.NebulaValidationException = NebulaValidationException;
754
- exports.RetrievalType = RetrievalType;
755
876
  //# sourceMappingURL=index.js.map
756
877
  //# sourceMappingURL=index.js.map