@ekodb/ekodb-client 0.3.0 → 0.5.0
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/client.d.ts +110 -0
- package/dist/client.js +198 -0
- package/dist/functions.d.ts +195 -0
- package/dist/functions.js +154 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/package.json +1 -1
- package/src/client.ts +239 -0
- package/src/functions.ts +420 -0
- package/src/index.ts +11 -0
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { QueryBuilder } from "./query-builder";
|
|
5
5
|
import { SearchQuery, SearchQueryBuilder, SearchResponse } from "./search";
|
|
6
6
|
import { Schema, SchemaBuilder, CollectionMetadata } from "./schema";
|
|
7
|
+
import { Script, FunctionResult } from "./functions";
|
|
7
8
|
export interface Record {
|
|
8
9
|
[key: string]: any;
|
|
9
10
|
}
|
|
@@ -395,10 +396,119 @@ export declare class EkoDBClient {
|
|
|
395
396
|
* Merge multiple chat sessions into one
|
|
396
397
|
*/
|
|
397
398
|
mergeChatSessions(request: MergeSessionsRequest): Promise<ChatSessionResponse>;
|
|
399
|
+
/**
|
|
400
|
+
* Save a new script definition
|
|
401
|
+
*/
|
|
402
|
+
saveScript(script: Script): Promise<string>;
|
|
403
|
+
/**
|
|
404
|
+
* Get a script by ID
|
|
405
|
+
*/
|
|
406
|
+
getScript(id: string): Promise<Script>;
|
|
407
|
+
/**
|
|
408
|
+
* List all scripts, optionally filtered by tags
|
|
409
|
+
*/
|
|
410
|
+
listScripts(tags?: string[]): Promise<Script[]>;
|
|
411
|
+
/**
|
|
412
|
+
* Update an existing script by ID
|
|
413
|
+
*/
|
|
414
|
+
updateScript(id: string, script: Script): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* Delete a script by ID
|
|
417
|
+
*/
|
|
418
|
+
deleteScript(id: string): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Call a saved script by ID or label
|
|
421
|
+
*/
|
|
422
|
+
callScript(idOrLabel: string, params?: {
|
|
423
|
+
[key: string]: any;
|
|
424
|
+
}): Promise<FunctionResult>;
|
|
398
425
|
/**
|
|
399
426
|
* Create a WebSocket client
|
|
400
427
|
*/
|
|
401
428
|
websocket(wsURL: string): WebSocketClient;
|
|
429
|
+
/**
|
|
430
|
+
* Generate embeddings for text using ekoDB's native Functions
|
|
431
|
+
*
|
|
432
|
+
* This helper simplifies embedding generation by:
|
|
433
|
+
* 1. Creating a temporary collection with the text
|
|
434
|
+
* 2. Running a Script with FindAll + Embed Functions
|
|
435
|
+
* 3. Extracting and returning the embedding vector
|
|
436
|
+
* 4. Cleaning up temporary resources
|
|
437
|
+
*
|
|
438
|
+
* @param text - The text to generate embeddings for
|
|
439
|
+
* @param model - The embedding model to use (e.g., "text-embedding-3-small")
|
|
440
|
+
* @returns Array of floats representing the embedding vector
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* const embedding = await client.embed(
|
|
445
|
+
* "Hello world",
|
|
446
|
+
* "text-embedding-3-small"
|
|
447
|
+
* );
|
|
448
|
+
* console.log(`Generated ${embedding.length} dimensions`);
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
embed(text: string, model: string): Promise<number[]>;
|
|
452
|
+
/**
|
|
453
|
+
* Perform text search without embeddings
|
|
454
|
+
*
|
|
455
|
+
* Simplified text search with full-text matching, fuzzy search, and stemming.
|
|
456
|
+
*
|
|
457
|
+
* @param collection - Collection name to search
|
|
458
|
+
* @param queryText - Search query text
|
|
459
|
+
* @param limit - Maximum number of results to return
|
|
460
|
+
* @returns Array of matching records
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* const results = await client.textSearch(
|
|
465
|
+
* "documents",
|
|
466
|
+
* "ownership system",
|
|
467
|
+
* 10
|
|
468
|
+
* );
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
textSearch(collection: string, queryText: string, limit: number): Promise<Record[]>;
|
|
472
|
+
/**
|
|
473
|
+
* Perform hybrid search combining text and vector search
|
|
474
|
+
*
|
|
475
|
+
* Combines semantic similarity (vector search) with keyword matching (text search)
|
|
476
|
+
* for more accurate and relevant results.
|
|
477
|
+
*
|
|
478
|
+
* @param collection - Collection name to search
|
|
479
|
+
* @param queryText - Search query text
|
|
480
|
+
* @param queryVector - Embedding vector for semantic search
|
|
481
|
+
* @param limit - Maximum number of results to return
|
|
482
|
+
* @returns Array of matching records
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* const embedding = await client.embed(query, "text-embedding-3-small");
|
|
487
|
+
* const results = await client.hybridSearch(
|
|
488
|
+
* "documents",
|
|
489
|
+
* query,
|
|
490
|
+
* embedding,
|
|
491
|
+
* 5
|
|
492
|
+
* );
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
hybridSearch(collection: string, queryText: string, queryVector: number[], limit: number): Promise<Record[]>;
|
|
496
|
+
/**
|
|
497
|
+
* Find all records in a collection with a limit
|
|
498
|
+
*
|
|
499
|
+
* Simplified method to query all documents in a collection.
|
|
500
|
+
*
|
|
501
|
+
* @param collection - Collection name
|
|
502
|
+
* @param limit - Maximum number of records to return
|
|
503
|
+
* @returns Array of records
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```typescript
|
|
507
|
+
* const allMessages = await client.findAll("messages", 1000);
|
|
508
|
+
* console.log(`Found ${allMessages.length} messages`);
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
findAllWithLimit(collection: string, limit: number): Promise<Record[]>;
|
|
402
512
|
}
|
|
403
513
|
/**
|
|
404
514
|
* WebSocket client for real-time queries
|
package/dist/client.js
CHANGED
|
@@ -228,6 +228,13 @@ class EkoDBClient {
|
|
|
228
228
|
}
|
|
229
229
|
throw new RateLimitError(retryAfter);
|
|
230
230
|
}
|
|
231
|
+
// Handle unauthorized (401) - try refreshing token
|
|
232
|
+
if (response.status === 401 && attempt === 0) {
|
|
233
|
+
console.log("Authentication failed, refreshing token...");
|
|
234
|
+
await this.refreshToken();
|
|
235
|
+
// Retry with new token
|
|
236
|
+
return this.makeRequest(method, path, data, attempt + 1, forceJson);
|
|
237
|
+
}
|
|
231
238
|
// Handle service unavailable (503)
|
|
232
239
|
if (response.status === 503 &&
|
|
233
240
|
this.shouldRetry &&
|
|
@@ -548,12 +555,203 @@ class EkoDBClient {
|
|
|
548
555
|
async mergeChatSessions(request) {
|
|
549
556
|
return this.makeRequest("POST", "/api/chat/merge", request, 0, true);
|
|
550
557
|
}
|
|
558
|
+
// ========================================================================
|
|
559
|
+
// SCRIPTS API
|
|
560
|
+
// ========================================================================
|
|
561
|
+
/**
|
|
562
|
+
* Save a new script definition
|
|
563
|
+
*/
|
|
564
|
+
async saveScript(script) {
|
|
565
|
+
const result = await this.makeRequest("POST", "/api/functions", script);
|
|
566
|
+
return result.id;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Get a script by ID
|
|
570
|
+
*/
|
|
571
|
+
async getScript(id) {
|
|
572
|
+
return this.makeRequest("GET", `/api/functions/${id}`);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* List all scripts, optionally filtered by tags
|
|
576
|
+
*/
|
|
577
|
+
async listScripts(tags) {
|
|
578
|
+
const params = tags ? `?tags=${tags.join(",")}` : "";
|
|
579
|
+
return this.makeRequest("GET", `/api/functions${params}`);
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Update an existing script by ID
|
|
583
|
+
*/
|
|
584
|
+
async updateScript(id, script) {
|
|
585
|
+
await this.makeRequest("PUT", `/api/functions/${id}`, script);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Delete a script by ID
|
|
589
|
+
*/
|
|
590
|
+
async deleteScript(id) {
|
|
591
|
+
await this.makeRequest("DELETE", `/api/functions/${id}`);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Call a saved script by ID or label
|
|
595
|
+
*/
|
|
596
|
+
async callScript(idOrLabel, params) {
|
|
597
|
+
return this.makeRequest("POST", `/api/functions/${idOrLabel}`, params || {});
|
|
598
|
+
}
|
|
551
599
|
/**
|
|
552
600
|
* Create a WebSocket client
|
|
553
601
|
*/
|
|
554
602
|
websocket(wsURL) {
|
|
555
603
|
return new WebSocketClient(wsURL, this.token);
|
|
556
604
|
}
|
|
605
|
+
// ========== RAG Helper Methods ==========
|
|
606
|
+
/**
|
|
607
|
+
* Generate embeddings for text using ekoDB's native Functions
|
|
608
|
+
*
|
|
609
|
+
* This helper simplifies embedding generation by:
|
|
610
|
+
* 1. Creating a temporary collection with the text
|
|
611
|
+
* 2. Running a Script with FindAll + Embed Functions
|
|
612
|
+
* 3. Extracting and returning the embedding vector
|
|
613
|
+
* 4. Cleaning up temporary resources
|
|
614
|
+
*
|
|
615
|
+
* @param text - The text to generate embeddings for
|
|
616
|
+
* @param model - The embedding model to use (e.g., "text-embedding-3-small")
|
|
617
|
+
* @returns Array of floats representing the embedding vector
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```typescript
|
|
621
|
+
* const embedding = await client.embed(
|
|
622
|
+
* "Hello world",
|
|
623
|
+
* "text-embedding-3-small"
|
|
624
|
+
* );
|
|
625
|
+
* console.log(`Generated ${embedding.length} dimensions`);
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
async embed(text, model) {
|
|
629
|
+
const tempCollection = `embed_temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
630
|
+
try {
|
|
631
|
+
// Insert temporary record with the text
|
|
632
|
+
await this.insert(tempCollection, { text }, undefined);
|
|
633
|
+
// Create Script with FindAll + Embed Functions
|
|
634
|
+
const tempLabel = `embed_script_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
635
|
+
const script = {
|
|
636
|
+
label: tempLabel,
|
|
637
|
+
name: "Generate Embedding",
|
|
638
|
+
description: "Temporary script for embedding generation",
|
|
639
|
+
version: "1.0",
|
|
640
|
+
parameters: {},
|
|
641
|
+
functions: [
|
|
642
|
+
{
|
|
643
|
+
type: "FindAll",
|
|
644
|
+
collection: tempCollection,
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
type: "Embed",
|
|
648
|
+
input_field: "text",
|
|
649
|
+
output_field: "embedding",
|
|
650
|
+
model: model,
|
|
651
|
+
},
|
|
652
|
+
],
|
|
653
|
+
tags: [],
|
|
654
|
+
};
|
|
655
|
+
// Save and execute the script
|
|
656
|
+
const scriptId = await this.saveScript(script);
|
|
657
|
+
const result = await this.callScript(scriptId, undefined);
|
|
658
|
+
// Clean up
|
|
659
|
+
await this.deleteScript(scriptId).catch(() => { });
|
|
660
|
+
await this.deleteCollection(tempCollection).catch(() => { });
|
|
661
|
+
// Extract embedding from result
|
|
662
|
+
if (result.records && result.records.length > 0) {
|
|
663
|
+
const record = result.records[0];
|
|
664
|
+
if (record.embedding && Array.isArray(record.embedding)) {
|
|
665
|
+
return record.embedding;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
throw new Error("Failed to extract embedding from result");
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
// Ensure cleanup even on error
|
|
672
|
+
await this.deleteCollection(tempCollection).catch(() => { });
|
|
673
|
+
throw error;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Perform text search without embeddings
|
|
678
|
+
*
|
|
679
|
+
* Simplified text search with full-text matching, fuzzy search, and stemming.
|
|
680
|
+
*
|
|
681
|
+
* @param collection - Collection name to search
|
|
682
|
+
* @param queryText - Search query text
|
|
683
|
+
* @param limit - Maximum number of results to return
|
|
684
|
+
* @returns Array of matching records
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```typescript
|
|
688
|
+
* const results = await client.textSearch(
|
|
689
|
+
* "documents",
|
|
690
|
+
* "ownership system",
|
|
691
|
+
* 10
|
|
692
|
+
* );
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
async textSearch(collection, queryText, limit) {
|
|
696
|
+
const searchQuery = {
|
|
697
|
+
query: queryText,
|
|
698
|
+
limit,
|
|
699
|
+
};
|
|
700
|
+
const response = await this.search(collection, searchQuery);
|
|
701
|
+
return response.results.map((r) => r.record);
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Perform hybrid search combining text and vector search
|
|
705
|
+
*
|
|
706
|
+
* Combines semantic similarity (vector search) with keyword matching (text search)
|
|
707
|
+
* for more accurate and relevant results.
|
|
708
|
+
*
|
|
709
|
+
* @param collection - Collection name to search
|
|
710
|
+
* @param queryText - Search query text
|
|
711
|
+
* @param queryVector - Embedding vector for semantic search
|
|
712
|
+
* @param limit - Maximum number of results to return
|
|
713
|
+
* @returns Array of matching records
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```typescript
|
|
717
|
+
* const embedding = await client.embed(query, "text-embedding-3-small");
|
|
718
|
+
* const results = await client.hybridSearch(
|
|
719
|
+
* "documents",
|
|
720
|
+
* query,
|
|
721
|
+
* embedding,
|
|
722
|
+
* 5
|
|
723
|
+
* );
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
async hybridSearch(collection, queryText, queryVector, limit) {
|
|
727
|
+
const searchQuery = {
|
|
728
|
+
query: queryText,
|
|
729
|
+
vector: queryVector,
|
|
730
|
+
limit,
|
|
731
|
+
};
|
|
732
|
+
const response = await this.search(collection, searchQuery);
|
|
733
|
+
return response.results.map((r) => r.record);
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Find all records in a collection with a limit
|
|
737
|
+
*
|
|
738
|
+
* Simplified method to query all documents in a collection.
|
|
739
|
+
*
|
|
740
|
+
* @param collection - Collection name
|
|
741
|
+
* @param limit - Maximum number of records to return
|
|
742
|
+
* @returns Array of records
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```typescript
|
|
746
|
+
* const allMessages = await client.findAll("messages", 1000);
|
|
747
|
+
* console.log(`Found ${allMessages.length} messages`);
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
async findAllWithLimit(collection, limit) {
|
|
751
|
+
const query = new query_builder_1.QueryBuilder().limit(limit).build();
|
|
752
|
+
const results = await this.find(collection, query);
|
|
753
|
+
return results;
|
|
754
|
+
}
|
|
557
755
|
}
|
|
558
756
|
exports.EkoDBClient = EkoDBClient;
|
|
559
757
|
/**
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scripts API for ekoDB TypeScript client
|
|
3
|
+
*/
|
|
4
|
+
export interface Script {
|
|
5
|
+
label: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
version: string;
|
|
9
|
+
parameters: {
|
|
10
|
+
[key: string]: ParameterDefinition;
|
|
11
|
+
};
|
|
12
|
+
functions: FunctionStageConfig[];
|
|
13
|
+
tags: string[];
|
|
14
|
+
created_at?: string;
|
|
15
|
+
updated_at?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParameterDefinition {
|
|
18
|
+
required: boolean;
|
|
19
|
+
default?: any;
|
|
20
|
+
description?: string;
|
|
21
|
+
param_type?: string;
|
|
22
|
+
}
|
|
23
|
+
export type FunctionStageConfig = {
|
|
24
|
+
type: "FindAll";
|
|
25
|
+
collection: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "Query";
|
|
28
|
+
collection: string;
|
|
29
|
+
filter?: Record<string, any>;
|
|
30
|
+
sort?: SortFieldConfig[];
|
|
31
|
+
limit?: number;
|
|
32
|
+
skip?: number;
|
|
33
|
+
} | {
|
|
34
|
+
type: "Project";
|
|
35
|
+
fields: string[];
|
|
36
|
+
exclude: boolean;
|
|
37
|
+
} | {
|
|
38
|
+
type: "Group";
|
|
39
|
+
by_fields: string[];
|
|
40
|
+
functions: GroupFunctionConfig[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "Count";
|
|
43
|
+
output_field: string;
|
|
44
|
+
} | {
|
|
45
|
+
type: "Filter";
|
|
46
|
+
filter: Record<string, any>;
|
|
47
|
+
} | {
|
|
48
|
+
type: "Sort";
|
|
49
|
+
sort: SortFieldConfig[];
|
|
50
|
+
} | {
|
|
51
|
+
type: "Limit";
|
|
52
|
+
limit: number;
|
|
53
|
+
} | {
|
|
54
|
+
type: "Skip";
|
|
55
|
+
skip: number;
|
|
56
|
+
} | {
|
|
57
|
+
type: "Insert";
|
|
58
|
+
collection: string;
|
|
59
|
+
record: Record<string, any>;
|
|
60
|
+
bypass_ripple?: boolean;
|
|
61
|
+
ttl?: number;
|
|
62
|
+
} | {
|
|
63
|
+
type: "Update";
|
|
64
|
+
collection: string;
|
|
65
|
+
filter: Record<string, any>;
|
|
66
|
+
updates: Record<string, any>;
|
|
67
|
+
bypass_ripple?: boolean;
|
|
68
|
+
ttl?: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: "UpdateById";
|
|
71
|
+
collection: string;
|
|
72
|
+
record_id: string;
|
|
73
|
+
updates: Record<string, any>;
|
|
74
|
+
bypass_ripple?: boolean;
|
|
75
|
+
ttl?: number;
|
|
76
|
+
} | {
|
|
77
|
+
type: "Delete";
|
|
78
|
+
collection: string;
|
|
79
|
+
filter: Record<string, any>;
|
|
80
|
+
bypass_ripple?: boolean;
|
|
81
|
+
} | {
|
|
82
|
+
type: "DeleteById";
|
|
83
|
+
collection: string;
|
|
84
|
+
record_id: string;
|
|
85
|
+
bypass_ripple?: boolean;
|
|
86
|
+
} | {
|
|
87
|
+
type: "BatchInsert";
|
|
88
|
+
collection: string;
|
|
89
|
+
records: Record<string, any>[];
|
|
90
|
+
bypass_ripple?: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: "BatchDelete";
|
|
93
|
+
collection: string;
|
|
94
|
+
record_ids: string[];
|
|
95
|
+
bypass_ripple?: boolean;
|
|
96
|
+
} | {
|
|
97
|
+
type: "HttpRequest";
|
|
98
|
+
url: string;
|
|
99
|
+
method?: string;
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
body?: any;
|
|
102
|
+
} | {
|
|
103
|
+
type: "VectorSearch";
|
|
104
|
+
collection: string;
|
|
105
|
+
query_vector: number[];
|
|
106
|
+
limit?: number;
|
|
107
|
+
threshold?: number;
|
|
108
|
+
} | {
|
|
109
|
+
type: "TextSearch";
|
|
110
|
+
collection: string;
|
|
111
|
+
query_text: string;
|
|
112
|
+
fields?: string[];
|
|
113
|
+
limit?: number;
|
|
114
|
+
fuzzy?: boolean;
|
|
115
|
+
} | {
|
|
116
|
+
type: "HybridSearch";
|
|
117
|
+
collection: string;
|
|
118
|
+
query_text: string;
|
|
119
|
+
query_vector?: number[];
|
|
120
|
+
limit?: number;
|
|
121
|
+
} | {
|
|
122
|
+
type: "Chat";
|
|
123
|
+
messages: ChatMessage[];
|
|
124
|
+
model?: string;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
max_tokens?: number;
|
|
127
|
+
} | {
|
|
128
|
+
type: "Embed";
|
|
129
|
+
input_field: string;
|
|
130
|
+
output_field: string;
|
|
131
|
+
model?: string;
|
|
132
|
+
};
|
|
133
|
+
export interface ChatMessage {
|
|
134
|
+
role: string;
|
|
135
|
+
content: string;
|
|
136
|
+
}
|
|
137
|
+
export declare const ChatMessage: {
|
|
138
|
+
system: (content: string) => ChatMessage;
|
|
139
|
+
user: (content: string) => ChatMessage;
|
|
140
|
+
assistant: (content: string) => ChatMessage;
|
|
141
|
+
};
|
|
142
|
+
export interface GroupFunctionConfig {
|
|
143
|
+
output_field: string;
|
|
144
|
+
operation: "Sum" | "Average" | "Count" | "Min" | "Max" | "First" | "Last" | "Push";
|
|
145
|
+
input_field?: string;
|
|
146
|
+
}
|
|
147
|
+
export interface SortFieldConfig {
|
|
148
|
+
field: string;
|
|
149
|
+
ascending: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface FunctionResult {
|
|
152
|
+
records: Record<string, any>[];
|
|
153
|
+
stats: FunctionStats;
|
|
154
|
+
}
|
|
155
|
+
export interface FunctionStats {
|
|
156
|
+
input_count: number;
|
|
157
|
+
output_count: number;
|
|
158
|
+
execution_time_ms: number;
|
|
159
|
+
stages_executed: number;
|
|
160
|
+
stage_stats: StageStats[];
|
|
161
|
+
}
|
|
162
|
+
export interface StageStats {
|
|
163
|
+
stage: string;
|
|
164
|
+
input_count: number;
|
|
165
|
+
output_count: number;
|
|
166
|
+
execution_time_ms: number;
|
|
167
|
+
}
|
|
168
|
+
export declare const Stage: {
|
|
169
|
+
findAll: (collection: string) => FunctionStageConfig;
|
|
170
|
+
query: (collection: string, filter?: Record<string, any>, sort?: SortFieldConfig[], limit?: number, skip?: number) => FunctionStageConfig;
|
|
171
|
+
project: (fields: string[], exclude?: boolean) => FunctionStageConfig;
|
|
172
|
+
group: (by_fields: string[], functions: GroupFunctionConfig[]) => FunctionStageConfig;
|
|
173
|
+
count: (output_field?: string) => FunctionStageConfig;
|
|
174
|
+
insert: (collection: string, record: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
175
|
+
update: (collection: string, filter: Record<string, any>, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
176
|
+
updateById: (collection: string, record_id: string, updates: Record<string, any>, bypassRipple?: boolean, ttl?: number) => FunctionStageConfig;
|
|
177
|
+
delete: (collection: string, filter: Record<string, any>, bypassRipple?: boolean) => FunctionStageConfig;
|
|
178
|
+
deleteById: (collection: string, record_id: string, bypassRipple?: boolean) => FunctionStageConfig;
|
|
179
|
+
batchInsert: (collection: string, records: Record<string, any>[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
180
|
+
batchDelete: (collection: string, record_ids: string[], bypassRipple?: boolean) => FunctionStageConfig;
|
|
181
|
+
filter: (filter: Record<string, any>) => FunctionStageConfig;
|
|
182
|
+
sort: (sort: SortFieldConfig[]) => FunctionStageConfig;
|
|
183
|
+
limit: (limit: number) => FunctionStageConfig;
|
|
184
|
+
skip: (skip: number) => FunctionStageConfig;
|
|
185
|
+
httpRequest: (url: string, method?: string, headers?: Record<string, string>, body?: any) => FunctionStageConfig;
|
|
186
|
+
vectorSearch: (collection: string, query_vector: number[], limit?: number, threshold?: number) => FunctionStageConfig;
|
|
187
|
+
textSearch: (collection: string, query_text: string, options?: {
|
|
188
|
+
fields?: string[];
|
|
189
|
+
limit?: number;
|
|
190
|
+
fuzzy?: boolean;
|
|
191
|
+
}) => FunctionStageConfig;
|
|
192
|
+
hybridSearch: (collection: string, query_text: string, query_vector?: number[], limit?: number) => FunctionStageConfig;
|
|
193
|
+
chat: (messages: ChatMessage[], model?: string, temperature?: number, max_tokens?: number) => FunctionStageConfig;
|
|
194
|
+
embed: (input_field: string, output_field: string, model?: string) => FunctionStageConfig;
|
|
195
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scripts API for ekoDB TypeScript client
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Stage = exports.ChatMessage = void 0;
|
|
7
|
+
exports.ChatMessage = {
|
|
8
|
+
system: (content) => ({
|
|
9
|
+
role: "system",
|
|
10
|
+
content: content,
|
|
11
|
+
}),
|
|
12
|
+
user: (content) => ({
|
|
13
|
+
role: "user",
|
|
14
|
+
content: content,
|
|
15
|
+
}),
|
|
16
|
+
assistant: (content) => ({
|
|
17
|
+
role: "assistant",
|
|
18
|
+
content: content,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
// Stage builder functions
|
|
22
|
+
exports.Stage = {
|
|
23
|
+
findAll: (collection) => ({
|
|
24
|
+
type: "FindAll",
|
|
25
|
+
collection,
|
|
26
|
+
}),
|
|
27
|
+
query: (collection, filter, sort, limit, skip) => ({
|
|
28
|
+
type: "Query",
|
|
29
|
+
collection,
|
|
30
|
+
filter,
|
|
31
|
+
sort,
|
|
32
|
+
limit,
|
|
33
|
+
skip,
|
|
34
|
+
}),
|
|
35
|
+
project: (fields, exclude = false) => ({
|
|
36
|
+
type: "Project",
|
|
37
|
+
fields,
|
|
38
|
+
exclude,
|
|
39
|
+
}),
|
|
40
|
+
group: (by_fields, functions) => ({
|
|
41
|
+
type: "Group",
|
|
42
|
+
by_fields,
|
|
43
|
+
functions,
|
|
44
|
+
}),
|
|
45
|
+
count: (output_field = "count") => ({
|
|
46
|
+
type: "Count",
|
|
47
|
+
output_field,
|
|
48
|
+
}),
|
|
49
|
+
insert: (collection, record, bypassRipple = false, ttl) => ({
|
|
50
|
+
type: "Insert",
|
|
51
|
+
collection,
|
|
52
|
+
record,
|
|
53
|
+
bypass_ripple: bypassRipple,
|
|
54
|
+
ttl,
|
|
55
|
+
}),
|
|
56
|
+
update: (collection, filter, updates, bypassRipple = false, ttl) => ({
|
|
57
|
+
type: "Update",
|
|
58
|
+
collection,
|
|
59
|
+
filter,
|
|
60
|
+
updates,
|
|
61
|
+
bypass_ripple: bypassRipple,
|
|
62
|
+
ttl,
|
|
63
|
+
}),
|
|
64
|
+
updateById: (collection, record_id, updates, bypassRipple = false, ttl) => ({
|
|
65
|
+
type: "UpdateById",
|
|
66
|
+
collection,
|
|
67
|
+
record_id,
|
|
68
|
+
updates,
|
|
69
|
+
bypass_ripple: bypassRipple,
|
|
70
|
+
ttl,
|
|
71
|
+
}),
|
|
72
|
+
delete: (collection, filter, bypassRipple = false) => ({
|
|
73
|
+
type: "Delete",
|
|
74
|
+
collection,
|
|
75
|
+
filter,
|
|
76
|
+
bypass_ripple: bypassRipple,
|
|
77
|
+
}),
|
|
78
|
+
deleteById: (collection, record_id, bypassRipple = false) => ({
|
|
79
|
+
type: "DeleteById",
|
|
80
|
+
collection,
|
|
81
|
+
record_id,
|
|
82
|
+
bypass_ripple: bypassRipple,
|
|
83
|
+
}),
|
|
84
|
+
batchInsert: (collection, records, bypassRipple = false) => ({
|
|
85
|
+
type: "BatchInsert",
|
|
86
|
+
collection,
|
|
87
|
+
records,
|
|
88
|
+
bypass_ripple: bypassRipple,
|
|
89
|
+
}),
|
|
90
|
+
batchDelete: (collection, record_ids, bypassRipple = false) => ({
|
|
91
|
+
type: "BatchDelete",
|
|
92
|
+
collection,
|
|
93
|
+
record_ids,
|
|
94
|
+
bypass_ripple: bypassRipple,
|
|
95
|
+
}),
|
|
96
|
+
filter: (filter) => ({
|
|
97
|
+
type: "Filter",
|
|
98
|
+
filter,
|
|
99
|
+
}),
|
|
100
|
+
sort: (sort) => ({
|
|
101
|
+
type: "Sort",
|
|
102
|
+
sort,
|
|
103
|
+
}),
|
|
104
|
+
limit: (limit) => ({
|
|
105
|
+
type: "Limit",
|
|
106
|
+
limit,
|
|
107
|
+
}),
|
|
108
|
+
skip: (skip) => ({
|
|
109
|
+
type: "Skip",
|
|
110
|
+
skip,
|
|
111
|
+
}),
|
|
112
|
+
httpRequest: (url, method = "GET", headers, body) => ({
|
|
113
|
+
type: "HttpRequest",
|
|
114
|
+
url,
|
|
115
|
+
method,
|
|
116
|
+
headers,
|
|
117
|
+
body,
|
|
118
|
+
}),
|
|
119
|
+
vectorSearch: (collection, query_vector, limit, threshold) => ({
|
|
120
|
+
type: "VectorSearch",
|
|
121
|
+
collection,
|
|
122
|
+
query_vector,
|
|
123
|
+
limit,
|
|
124
|
+
threshold,
|
|
125
|
+
}),
|
|
126
|
+
textSearch: (collection, query_text, options) => ({
|
|
127
|
+
type: "TextSearch",
|
|
128
|
+
collection,
|
|
129
|
+
query_text,
|
|
130
|
+
fields: options?.fields,
|
|
131
|
+
limit: options?.limit,
|
|
132
|
+
fuzzy: options?.fuzzy,
|
|
133
|
+
}),
|
|
134
|
+
hybridSearch: (collection, query_text, query_vector, limit) => ({
|
|
135
|
+
type: "HybridSearch",
|
|
136
|
+
collection,
|
|
137
|
+
query_text,
|
|
138
|
+
query_vector,
|
|
139
|
+
limit,
|
|
140
|
+
}),
|
|
141
|
+
chat: (messages, model, temperature, max_tokens) => ({
|
|
142
|
+
type: "Chat",
|
|
143
|
+
messages,
|
|
144
|
+
model,
|
|
145
|
+
temperature,
|
|
146
|
+
max_tokens,
|
|
147
|
+
}),
|
|
148
|
+
embed: (input_field, output_field, model) => ({
|
|
149
|
+
type: "Embed",
|
|
150
|
+
input_field,
|
|
151
|
+
output_field,
|
|
152
|
+
model,
|
|
153
|
+
}),
|
|
154
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export { QueryBuilder, SortOrder } from "./query-builder";
|
|
|
3
3
|
export { SearchQueryBuilder } from "./search";
|
|
4
4
|
export { SchemaBuilder, FieldTypeSchemaBuilder, VectorIndexAlgorithm, DistanceMetric, } from "./schema";
|
|
5
5
|
export { JoinBuilder } from "./join";
|
|
6
|
+
export { Stage, ChatMessage } from "./functions";
|
|
6
7
|
export type { SearchQuery, SearchResult, SearchResponse } from "./search";
|
|
7
8
|
export type { Schema, FieldTypeSchema, IndexConfig, CollectionMetadata, } from "./schema";
|
|
8
9
|
export type { JoinConfig } from "./join";
|
|
10
|
+
export type { Script, ParameterDefinition, FunctionStageConfig, GroupFunctionConfig, SortFieldConfig, FunctionResult, FunctionStats, StageStats, } from "./functions";
|
|
9
11
|
export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, } from "./client";
|