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