@ekodb/ekodb-client 0.11.0 → 0.12.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 CHANGED
@@ -123,6 +123,18 @@ export interface ChatRequest {
123
123
  system_prompt?: string;
124
124
  bypass_ripple?: boolean;
125
125
  }
126
+ export interface ToolChoice {
127
+ type: "auto" | "none" | "required" | "tool";
128
+ name?: string;
129
+ }
130
+ export interface ToolConfig {
131
+ enabled: boolean;
132
+ allowed_tools?: string[];
133
+ allowed_collections?: string[];
134
+ max_iterations?: number;
135
+ allow_write_operations?: boolean;
136
+ tool_choice?: ToolChoice;
137
+ }
126
138
  export interface CreateChatSessionRequest {
127
139
  collections: CollectionConfig[];
128
140
  llm_provider: string;
@@ -132,11 +144,16 @@ export interface CreateChatSessionRequest {
132
144
  parent_id?: string;
133
145
  branch_point_idx?: number;
134
146
  max_context_messages?: number;
147
+ max_tokens?: number;
148
+ temperature?: number;
149
+ tool_config?: ToolConfig;
135
150
  }
136
151
  export interface ChatMessageRequest {
137
152
  message: string;
138
153
  bypass_ripple?: boolean;
139
154
  force_summarize?: boolean;
155
+ max_iterations?: number;
156
+ tool_config?: ToolConfig;
140
157
  }
141
158
  export interface TokenUsage {
142
159
  prompt_tokens: number;
@@ -195,16 +212,21 @@ export interface UpdateSessionRequest {
195
212
  llm_model?: string;
196
213
  collections?: CollectionConfig[];
197
214
  max_context_messages?: number;
215
+ bypass_ripple?: boolean;
216
+ title?: string;
217
+ memory?: any;
198
218
  }
199
219
  export declare enum MergeStrategy {
200
220
  Chronological = "Chronological",
201
221
  Summarized = "Summarized",
202
- LatestOnly = "LatestOnly"
222
+ LatestOnly = "LatestOnly",
223
+ Interleaved = "Interleaved"
203
224
  }
204
225
  export interface MergeSessionsRequest {
205
226
  source_chat_ids: string[];
206
227
  target_chat_id: string;
207
228
  merge_strategy: MergeStrategy;
229
+ bypass_ripple?: boolean;
208
230
  }
209
231
  /**
210
232
  * Available chat models by provider
@@ -214,6 +236,22 @@ export interface ChatModels {
214
236
  anthropic: string[];
215
237
  perplexity: string[];
216
238
  }
239
+ /**
240
+ * Request to generate embeddings
241
+ */
242
+ export interface EmbedRequest {
243
+ text?: string;
244
+ texts?: string[];
245
+ model?: string;
246
+ }
247
+ /**
248
+ * Response from embedding generation
249
+ */
250
+ export interface EmbedResponse {
251
+ embeddings: number[][];
252
+ model: string;
253
+ dimensions: number;
254
+ }
217
255
  /**
218
256
  * User function definition - reusable sequence of Functions that can be called by Scripts
219
257
  */
@@ -765,13 +803,7 @@ export declare class EkoDBClient {
765
803
  */
766
804
  websocket(wsURL: string): WebSocketClient;
767
805
  /**
768
- * Generate embeddings for text using ekoDB's native Functions
769
- *
770
- * This helper simplifies embedding generation by:
771
- * 1. Creating a temporary collection with the text
772
- * 2. Running a Script with FindAll + Embed Functions
773
- * 3. Extracting and returning the embedding vector
774
- * 4. Cleaning up temporary resources
806
+ * Generate embeddings for a single text
775
807
  *
776
808
  * @param text - The text to generate embeddings for
777
809
  * @param model - The embedding model to use (e.g., "text-embedding-3-small")
@@ -787,6 +819,18 @@ export declare class EkoDBClient {
787
819
  * ```
788
820
  */
789
821
  embed(text: string, model: string): Promise<number[]>;
822
+ /**
823
+ * Generate embeddings for multiple texts in a single batch request
824
+ *
825
+ * @param texts - Array of texts to generate embeddings for
826
+ * @param model - The embedding model to use
827
+ * @returns Array of embedding vectors
828
+ */
829
+ embedBatch(texts: string[], model: string): Promise<number[][]>;
830
+ /**
831
+ * Internal: make embed API request
832
+ */
833
+ private embedRequest;
790
834
  /**
791
835
  * Perform text search without embeddings
792
836
  *
package/dist/client.js CHANGED
@@ -66,6 +66,7 @@ var MergeStrategy;
66
66
  MergeStrategy["Chronological"] = "Chronological";
67
67
  MergeStrategy["Summarized"] = "Summarized";
68
68
  MergeStrategy["LatestOnly"] = "LatestOnly";
69
+ MergeStrategy["Interleaved"] = "Interleaved";
69
70
  })(MergeStrategy || (exports.MergeStrategy = MergeStrategy = {}));
70
71
  class EkoDBClient {
71
72
  constructor(config, apiKey) {
@@ -1026,13 +1027,7 @@ class EkoDBClient {
1026
1027
  }
1027
1028
  // ========== RAG Helper Methods ==========
1028
1029
  /**
1029
- * Generate embeddings for text using ekoDB's native Functions
1030
- *
1031
- * This helper simplifies embedding generation by:
1032
- * 1. Creating a temporary collection with the text
1033
- * 2. Running a Script with FindAll + Embed Functions
1034
- * 3. Extracting and returning the embedding vector
1035
- * 4. Cleaning up temporary resources
1030
+ * Generate embeddings for a single text
1036
1031
  *
1037
1032
  * @param text - The text to generate embeddings for
1038
1033
  * @param model - The embedding model to use (e.g., "text-embedding-3-small")
@@ -1048,52 +1043,28 @@ class EkoDBClient {
1048
1043
  * ```
1049
1044
  */
1050
1045
  async embed(text, model) {
1051
- const tempCollection = `embed_temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
1052
- try {
1053
- // Insert temporary record with the text
1054
- await this.insert(tempCollection, { text }, undefined);
1055
- // Create Script with FindAll + Embed Functions
1056
- const tempLabel = `embed_script_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
1057
- const script = {
1058
- label: tempLabel,
1059
- name: "Generate Embedding",
1060
- description: "Temporary script for embedding generation",
1061
- version: "1.0",
1062
- parameters: {},
1063
- functions: [
1064
- {
1065
- type: "FindAll",
1066
- collection: tempCollection,
1067
- },
1068
- {
1069
- type: "Embed",
1070
- input_field: "text",
1071
- output_field: "embedding",
1072
- model: model,
1073
- },
1074
- ],
1075
- tags: [],
1076
- };
1077
- // Save and execute the script
1078
- const scriptId = await this.saveScript(script);
1079
- const result = await this.callScript(scriptId, undefined);
1080
- // Clean up
1081
- await this.deleteScript(scriptId).catch(() => { });
1082
- await this.deleteCollection(tempCollection).catch(() => { });
1083
- // Extract embedding from result
1084
- if (result.records && result.records.length > 0) {
1085
- const record = result.records[0];
1086
- if (record.embedding && Array.isArray(record.embedding)) {
1087
- return record.embedding;
1088
- }
1089
- }
1090
- throw new Error("Failed to extract embedding from result");
1091
- }
1092
- catch (error) {
1093
- // Ensure cleanup even on error
1094
- await this.deleteCollection(tempCollection).catch(() => { });
1095
- throw error;
1046
+ const response = await this.embedRequest({ text, model });
1047
+ if (response.embeddings.length === 0) {
1048
+ throw new Error("No embedding returned");
1096
1049
  }
1050
+ return response.embeddings[0];
1051
+ }
1052
+ /**
1053
+ * Generate embeddings for multiple texts in a single batch request
1054
+ *
1055
+ * @param texts - Array of texts to generate embeddings for
1056
+ * @param model - The embedding model to use
1057
+ * @returns Array of embedding vectors
1058
+ */
1059
+ async embedBatch(texts, model) {
1060
+ const response = await this.embedRequest({ texts, model });
1061
+ return response.embeddings;
1062
+ }
1063
+ /**
1064
+ * Internal: make embed API request
1065
+ */
1066
+ async embedRequest(request) {
1067
+ return this.makeRequest("POST", "/api/embed", request, 0, true);
1097
1068
  }
1098
1069
  /**
1099
1070
  * Perform text search without embeddings
package/dist/index.d.ts CHANGED
@@ -10,4 +10,4 @@ export type { SearchQuery, SearchResult, SearchResponse } from "./search";
10
10
  export type { Schema, FieldTypeSchema, IndexConfig, CollectionMetadata, } from "./schema";
11
11
  export type { JoinConfig } from "./join";
12
12
  export type { Script, ParameterDefinition, FunctionStageConfig, GroupFunctionConfig, SortFieldConfig, FunctionResult, FunctionStats, StageStats, } from "./functions";
13
- export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, ChatModels, UserFunction, } from "./client";
13
+ export type { Record, Query, BatchOperationResult, ClientConfig, RateLimitInfo, CollectionConfig, ChatRequest, CreateChatSessionRequest, ChatMessageRequest, TokenUsage, ChatResponse, ChatSession, ChatSessionResponse, ListSessionsQuery, ListSessionsResponse, GetMessagesQuery, GetMessagesResponse, UpdateSessionRequest, MergeSessionsRequest, ChatModels, EmbedRequest, EmbedResponse, UserFunction, ToolChoice, ToolConfig, } from "./client";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekodb/ekodb-client",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Official TypeScript/JavaScript client for ekoDB",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,13 +19,13 @@
19
19
  "author": "ekoDB",
20
20
  "license": "MIT",
21
21
  "devDependencies": {
22
- "@types/node": "^25.0.3",
23
- "@types/ws": "^8.5.10",
24
- "typescript": "^5.3.0",
25
- "vitest": "^3.2.0"
22
+ "@types/node": "^25.3.5",
23
+ "@types/ws": "^8.18.1",
24
+ "typescript": "^5.9.3",
25
+ "vitest": "^4.0.18"
26
26
  },
27
27
  "dependencies": {
28
- "@msgpack/msgpack": "^3.0.0",
29
- "ws": "^8.16.0"
28
+ "@msgpack/msgpack": "^3.1.3",
29
+ "ws": "^8.19.0"
30
30
  }
31
31
  }
package/src/client.ts CHANGED
@@ -151,6 +151,20 @@ export interface ChatRequest {
151
151
  bypass_ripple?: boolean;
152
152
  }
153
153
 
154
+ export interface ToolChoice {
155
+ type: "auto" | "none" | "required" | "tool";
156
+ name?: string;
157
+ }
158
+
159
+ export interface ToolConfig {
160
+ enabled: boolean;
161
+ allowed_tools?: string[];
162
+ allowed_collections?: string[];
163
+ max_iterations?: number;
164
+ allow_write_operations?: boolean;
165
+ tool_choice?: ToolChoice;
166
+ }
167
+
154
168
  export interface CreateChatSessionRequest {
155
169
  collections: CollectionConfig[];
156
170
  llm_provider: string;
@@ -160,12 +174,17 @@ export interface CreateChatSessionRequest {
160
174
  parent_id?: string;
161
175
  branch_point_idx?: number;
162
176
  max_context_messages?: number;
177
+ max_tokens?: number;
178
+ temperature?: number;
179
+ tool_config?: ToolConfig;
163
180
  }
164
181
 
165
182
  export interface ChatMessageRequest {
166
183
  message: string;
167
184
  bypass_ripple?: boolean;
168
185
  force_summarize?: boolean;
186
+ max_iterations?: number;
187
+ tool_config?: ToolConfig;
169
188
  }
170
189
 
171
190
  export interface TokenUsage {
@@ -233,18 +252,23 @@ export interface UpdateSessionRequest {
233
252
  llm_model?: string;
234
253
  collections?: CollectionConfig[];
235
254
  max_context_messages?: number;
255
+ bypass_ripple?: boolean;
256
+ title?: string;
257
+ memory?: any;
236
258
  }
237
259
 
238
260
  export enum MergeStrategy {
239
261
  Chronological = "Chronological",
240
262
  Summarized = "Summarized",
241
263
  LatestOnly = "LatestOnly",
264
+ Interleaved = "Interleaved",
242
265
  }
243
266
 
244
267
  export interface MergeSessionsRequest {
245
268
  source_chat_ids: string[];
246
269
  target_chat_id: string;
247
270
  merge_strategy: MergeStrategy;
271
+ bypass_ripple?: boolean;
248
272
  }
249
273
 
250
274
  /**
@@ -256,6 +280,24 @@ export interface ChatModels {
256
280
  perplexity: string[];
257
281
  }
258
282
 
283
+ /**
284
+ * Request to generate embeddings
285
+ */
286
+ export interface EmbedRequest {
287
+ text?: string;
288
+ texts?: string[];
289
+ model?: string;
290
+ }
291
+
292
+ /**
293
+ * Response from embedding generation
294
+ */
295
+ export interface EmbedResponse {
296
+ embeddings: number[][];
297
+ model: string;
298
+ dimensions: number;
299
+ }
300
+
259
301
  /**
260
302
  * User function definition - reusable sequence of Functions that can be called by Scripts
261
303
  */
@@ -1730,13 +1772,7 @@ export class EkoDBClient {
1730
1772
  // ========== RAG Helper Methods ==========
1731
1773
 
1732
1774
  /**
1733
- * Generate embeddings for text using ekoDB's native Functions
1734
- *
1735
- * This helper simplifies embedding generation by:
1736
- * 1. Creating a temporary collection with the text
1737
- * 2. Running a Script with FindAll + Embed Functions
1738
- * 3. Extracting and returning the embedding vector
1739
- * 4. Cleaning up temporary resources
1775
+ * Generate embeddings for a single text
1740
1776
  *
1741
1777
  * @param text - The text to generate embeddings for
1742
1778
  * @param model - The embedding model to use (e.g., "text-embedding-3-small")
@@ -1752,57 +1788,36 @@ export class EkoDBClient {
1752
1788
  * ```
1753
1789
  */
1754
1790
  async embed(text: string, model: string): Promise<number[]> {
1755
- const tempCollection = `embed_temp_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
1756
-
1757
- try {
1758
- // Insert temporary record with the text
1759
- await this.insert(tempCollection, { text }, undefined);
1760
-
1761
- // Create Script with FindAll + Embed Functions
1762
- const tempLabel = `embed_script_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
1763
- const script: Script = {
1764
- label: tempLabel,
1765
- name: "Generate Embedding",
1766
- description: "Temporary script for embedding generation",
1767
- version: "1.0",
1768
- parameters: {},
1769
- functions: [
1770
- {
1771
- type: "FindAll",
1772
- collection: tempCollection,
1773
- },
1774
- {
1775
- type: "Embed",
1776
- input_field: "text",
1777
- output_field: "embedding",
1778
- model: model,
1779
- } as any,
1780
- ],
1781
- tags: [],
1782
- };
1783
-
1784
- // Save and execute the script
1785
- const scriptId = await this.saveScript(script);
1786
- const result = await this.callScript(scriptId, undefined);
1787
-
1788
- // Clean up
1789
- await this.deleteScript(scriptId).catch(() => {});
1790
- await this.deleteCollection(tempCollection).catch(() => {});
1791
+ const response = await this.embedRequest({ text, model });
1792
+ if (response.embeddings.length === 0) {
1793
+ throw new Error("No embedding returned");
1794
+ }
1795
+ return response.embeddings[0];
1796
+ }
1791
1797
 
1792
- // Extract embedding from result
1793
- if (result.records && result.records.length > 0) {
1794
- const record = result.records[0];
1795
- if (record.embedding && Array.isArray(record.embedding)) {
1796
- return record.embedding as number[];
1797
- }
1798
- }
1798
+ /**
1799
+ * Generate embeddings for multiple texts in a single batch request
1800
+ *
1801
+ * @param texts - Array of texts to generate embeddings for
1802
+ * @param model - The embedding model to use
1803
+ * @returns Array of embedding vectors
1804
+ */
1805
+ async embedBatch(texts: string[], model: string): Promise<number[][]> {
1806
+ const response = await this.embedRequest({ texts, model });
1807
+ return response.embeddings;
1808
+ }
1799
1809
 
1800
- throw new Error("Failed to extract embedding from result");
1801
- } catch (error) {
1802
- // Ensure cleanup even on error
1803
- await this.deleteCollection(tempCollection).catch(() => {});
1804
- throw error;
1805
- }
1810
+ /**
1811
+ * Internal: make embed API request
1812
+ */
1813
+ private async embedRequest(request: EmbedRequest): Promise<EmbedResponse> {
1814
+ return this.makeRequest<EmbedResponse>(
1815
+ "POST",
1816
+ "/api/embed",
1817
+ request,
1818
+ 0,
1819
+ true, // Force JSON
1820
+ );
1806
1821
  }
1807
1822
 
1808
1823
  /**
package/src/index.ts CHANGED
@@ -71,5 +71,9 @@ export type {
71
71
  UpdateSessionRequest,
72
72
  MergeSessionsRequest,
73
73
  ChatModels,
74
+ EmbedRequest,
75
+ EmbedResponse,
74
76
  UserFunction,
77
+ ToolChoice,
78
+ ToolConfig,
75
79
  } from "./client";
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ exclude: ["dist/**", "node_modules/**"],
6
+ },
7
+ });