@agentionai/agents 0.3.0-beta

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.
Files changed (91) hide show
  1. package/README.md +517 -0
  2. package/dist/agents/Agent.d.ts +29 -0
  3. package/dist/agents/Agent.js +28 -0
  4. package/dist/agents/AgentConfig.d.ts +118 -0
  5. package/dist/agents/AgentConfig.js +3 -0
  6. package/dist/agents/AgentEvent.d.ts +18 -0
  7. package/dist/agents/AgentEvent.js +26 -0
  8. package/dist/agents/BaseAgent.d.ts +82 -0
  9. package/dist/agents/BaseAgent.js +121 -0
  10. package/dist/agents/anthropic/ClaudeAgent.d.ts +46 -0
  11. package/dist/agents/anthropic/ClaudeAgent.js +262 -0
  12. package/dist/agents/errors/AgentError.d.ts +47 -0
  13. package/dist/agents/errors/AgentError.js +74 -0
  14. package/dist/agents/google/GeminiAgent.d.ts +63 -0
  15. package/dist/agents/google/GeminiAgent.js +395 -0
  16. package/dist/agents/mistral/MistralAgent.d.ts +47 -0
  17. package/dist/agents/mistral/MistralAgent.js +313 -0
  18. package/dist/agents/model-types.d.ts +30 -0
  19. package/dist/agents/model-types.js +8 -0
  20. package/dist/agents/openai/OpenAiAgent.d.ts +48 -0
  21. package/dist/agents/openai/OpenAiAgent.js +338 -0
  22. package/dist/chunkers/Chunker.d.ts +53 -0
  23. package/dist/chunkers/Chunker.js +174 -0
  24. package/dist/chunkers/RecursiveChunker.d.ts +52 -0
  25. package/dist/chunkers/RecursiveChunker.js +166 -0
  26. package/dist/chunkers/TextChunker.d.ts +27 -0
  27. package/dist/chunkers/TextChunker.js +50 -0
  28. package/dist/chunkers/TokenChunker.d.ts +60 -0
  29. package/dist/chunkers/TokenChunker.js +176 -0
  30. package/dist/chunkers/index.d.ts +6 -0
  31. package/dist/chunkers/index.js +14 -0
  32. package/dist/chunkers/types.d.ts +95 -0
  33. package/dist/chunkers/types.js +3 -0
  34. package/dist/graph/AgentGraph.d.ts +99 -0
  35. package/dist/graph/AgentGraph.js +115 -0
  36. package/dist/graph/BaseExecutor.d.ts +86 -0
  37. package/dist/graph/BaseExecutor.js +61 -0
  38. package/dist/graph/GraphMetrics.d.ts +143 -0
  39. package/dist/graph/GraphMetrics.js +264 -0
  40. package/dist/graph/MapExecutor.d.ts +39 -0
  41. package/dist/graph/MapExecutor.js +123 -0
  42. package/dist/graph/ParallelExecutor.d.ts +51 -0
  43. package/dist/graph/ParallelExecutor.js +103 -0
  44. package/dist/graph/Pipeline.d.ts +44 -0
  45. package/dist/graph/Pipeline.js +109 -0
  46. package/dist/graph/RouterExecutor.d.ts +89 -0
  47. package/dist/graph/RouterExecutor.js +209 -0
  48. package/dist/graph/SequentialExecutor.d.ts +44 -0
  49. package/dist/graph/SequentialExecutor.js +115 -0
  50. package/dist/graph/VotingSystem.d.ts +54 -0
  51. package/dist/graph/VotingSystem.js +106 -0
  52. package/dist/history/History.d.ts +107 -0
  53. package/dist/history/History.js +166 -0
  54. package/dist/history/RedisHistory.d.ts +27 -0
  55. package/dist/history/RedisHistory.js +55 -0
  56. package/dist/history/transformers.d.ts +102 -0
  57. package/dist/history/transformers.js +415 -0
  58. package/dist/history/types.d.ts +130 -0
  59. package/dist/history/types.js +55 -0
  60. package/dist/index.d.ts +16 -0
  61. package/dist/index.js +48 -0
  62. package/dist/ingestion/IngestionPipeline.d.ts +86 -0
  63. package/dist/ingestion/IngestionPipeline.js +266 -0
  64. package/dist/ingestion/index.d.ts +3 -0
  65. package/dist/ingestion/index.js +7 -0
  66. package/dist/ingestion/types.d.ts +74 -0
  67. package/dist/ingestion/types.js +3 -0
  68. package/dist/team/Team.d.ts +46 -0
  69. package/dist/team/Team.js +104 -0
  70. package/dist/tools/Tool.d.ts +75 -0
  71. package/dist/tools/Tool.js +137 -0
  72. package/dist/vectorstore/Embeddings.d.ts +67 -0
  73. package/dist/vectorstore/Embeddings.js +54 -0
  74. package/dist/vectorstore/LanceDBVectorStore.d.ts +149 -0
  75. package/dist/vectorstore/LanceDBVectorStore.js +338 -0
  76. package/dist/vectorstore/OpenAIEmbeddings.d.ts +45 -0
  77. package/dist/vectorstore/OpenAIEmbeddings.js +109 -0
  78. package/dist/vectorstore/VectorStore.d.ts +255 -0
  79. package/dist/vectorstore/VectorStore.js +216 -0
  80. package/dist/vectorstore/index.d.ts +28 -0
  81. package/dist/vectorstore/index.js +35 -0
  82. package/dist/viz/VizConfig.d.ts +54 -0
  83. package/dist/viz/VizConfig.js +100 -0
  84. package/dist/viz/VizReporter.d.ts +127 -0
  85. package/dist/viz/VizReporter.js +595 -0
  86. package/dist/viz/index.d.ts +31 -0
  87. package/dist/viz/index.js +51 -0
  88. package/dist/viz/types.d.ts +105 -0
  89. package/dist/viz/types.js +7 -0
  90. package/package.json +109 -0
  91. package/readme.md +1 -0
@@ -0,0 +1,338 @@
1
+ "use strict";
2
+ /**
3
+ * LanceDB implementation of the VectorStore interface.
4
+ *
5
+ * LanceDB is an embedded vector database that runs locally or can connect
6
+ * to cloud storage. It provides fast vector search with automatic indexing.
7
+ *
8
+ * @requires @lancedb/lancedb - Install with: npm install @lancedb/lancedb
9
+ * @requires apache-arrow - Install with: npm install apache-arrow
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || (function () {
28
+ var ownKeys = function(o) {
29
+ ownKeys = Object.getOwnPropertyNames || function (o) {
30
+ var ar = [];
31
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
+ return ar;
33
+ };
34
+ return ownKeys(o);
35
+ };
36
+ return function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ })();
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.LanceDBVectorStore = void 0;
46
+ const VectorStore_1 = require("./VectorStore");
47
+ /**
48
+ * LanceDB implementation of the VectorStore interface.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { LanceDBVectorStore, OpenAIEmbeddings } from "@agentionai/agents";
53
+ *
54
+ * // Create with OpenAI embeddings
55
+ * const embeddings = new OpenAIEmbeddings({
56
+ * model: "text-embedding-3-small",
57
+ * });
58
+ *
59
+ * const store = await LanceDBVectorStore.create({
60
+ * name: "knowledge_base",
61
+ * uri: "./my-database",
62
+ * tableName: "documents",
63
+ * embeddings,
64
+ * });
65
+ *
66
+ * // Add documents (embeddings generated automatically)
67
+ * await store.addDocuments([
68
+ * { id: "1", content: "LanceDB is a vector database" },
69
+ * { id: "2", content: "Vector search enables semantic queries" },
70
+ * ]);
71
+ *
72
+ * // Search
73
+ * const results = await store.search("What is LanceDB?", { limit: 5 });
74
+ *
75
+ * // Create a tool for agents
76
+ * const searchTool = store.toRetrievalTool("Search the knowledge base");
77
+ * ```
78
+ */
79
+ class LanceDBVectorStore extends VectorStore_1.VectorStore {
80
+ constructor(config, connection, table) {
81
+ super();
82
+ this.name = config.name;
83
+ this.connection = connection;
84
+ this.table = table;
85
+ this.embeddings = config.embeddings;
86
+ this.tableName = config.tableName;
87
+ this.dimensions =
88
+ config.dimensions ?? config.embeddings?.dimensions ?? 1536;
89
+ }
90
+ /**
91
+ * Create a new LanceDBVectorStore instance.
92
+ *
93
+ * This is an async factory method since LanceDB connection is asynchronous.
94
+ *
95
+ * @param config - Configuration for the store
96
+ * @returns A configured LanceDBVectorStore instance
97
+ *
98
+ * @throws Error if @lancedb/lancedb is not installed
99
+ */
100
+ static async create(config) {
101
+ // Dynamic import to make lancedb an optional dependency
102
+ let lancedb;
103
+ try {
104
+ lancedb = await Promise.resolve().then(() => __importStar(require("@lancedb/lancedb")));
105
+ }
106
+ catch {
107
+ throw new Error("LanceDB is not installed. Install it with: npm install @lancedb/lancedb apache-arrow");
108
+ }
109
+ const connection = await lancedb.connect(config.uri, config.connectionOptions);
110
+ const tableNames = await connection.tableNames();
111
+ let table;
112
+ const dimensions = config.dimensions ?? config.embeddings?.dimensions ?? 1536;
113
+ if (tableNames.includes(config.tableName)) {
114
+ table = await connection.openTable(config.tableName);
115
+ }
116
+ else {
117
+ // Create table with schema
118
+ let arrow;
119
+ try {
120
+ arrow = await Promise.resolve().then(() => __importStar(require("apache-arrow")));
121
+ }
122
+ catch {
123
+ throw new Error("apache-arrow is not installed. Install it with: npm install apache-arrow");
124
+ }
125
+ const schema = new arrow.Schema([
126
+ new arrow.Field("id", new arrow.Utf8(), false),
127
+ new arrow.Field("text", new arrow.Utf8(), false),
128
+ new arrow.Field("vector", new arrow.FixedSizeList(dimensions, new arrow.Field("item", new arrow.Float32(), true)), false),
129
+ new arrow.Field("metadata", new arrow.Utf8(), true),
130
+ ]);
131
+ table = await connection.createEmptyTable(config.tableName, schema);
132
+ }
133
+ return new LanceDBVectorStore(config, connection, table);
134
+ }
135
+ /**
136
+ * Add documents to the vector store.
137
+ * If an embeddings provider is configured, embeddings are generated automatically.
138
+ */
139
+ async addDocuments(documents, _options) {
140
+ if (!this.embeddings) {
141
+ throw new Error("No embeddings provider configured. Use addEmbeddedDocuments() with pre-computed embeddings, or configure an embeddings provider.");
142
+ }
143
+ // Generate embeddings for all documents
144
+ const texts = documents.map((doc) => doc.content);
145
+ const vectors = await this.embeddings.embed(texts);
146
+ // Convert to embedded documents
147
+ const embeddedDocs = documents.map((doc, i) => ({
148
+ ...doc,
149
+ embedding: vectors[i],
150
+ }));
151
+ return this.addEmbeddedDocuments(embeddedDocs, _options);
152
+ }
153
+ /**
154
+ * Add documents with pre-computed embeddings.
155
+ */
156
+ async addEmbeddedDocuments(documents, _options) {
157
+ const records = documents.map((doc) => ({
158
+ id: doc.id,
159
+ text: doc.content,
160
+ vector: doc.embedding,
161
+ metadata: doc.metadata ? JSON.stringify(doc.metadata) : undefined,
162
+ }));
163
+ await this.table.add(records);
164
+ return documents.map((d) => d.id);
165
+ }
166
+ /**
167
+ * Search for documents similar to the query.
168
+ */
169
+ async search(query, options) {
170
+ if (!this.embeddings) {
171
+ throw new Error("No embeddings provider configured. Use searchByVector() with a pre-computed query embedding, or configure an embeddings provider.");
172
+ }
173
+ const queryVector = await this.embeddings.embedQuery(query);
174
+ return this.searchByVector(queryVector, options);
175
+ }
176
+ /**
177
+ * Search using a pre-computed embedding vector.
178
+ */
179
+ async searchByVector(embedding, options) {
180
+ const limit = options?.limit ?? 10;
181
+ const scoreThreshold = options?.scoreThreshold;
182
+ let queryBuilder = this.table.vectorSearch(embedding).limit(limit);
183
+ if (options?.filter) {
184
+ const filterStr = this.buildFilterString(options.filter);
185
+ if (filterStr) {
186
+ queryBuilder = queryBuilder.where(filterStr);
187
+ }
188
+ }
189
+ const results = await queryBuilder.toArray();
190
+ return this.processResults(results, scoreThreshold);
191
+ }
192
+ /**
193
+ * Delete documents by their IDs.
194
+ */
195
+ async delete(ids, _options) {
196
+ const idList = ids.map((id) => `'${id}'`).join(", ");
197
+ const filter = `id IN (${idList})`;
198
+ const countBefore = await this.table.countRows();
199
+ await this.table.delete(filter);
200
+ const countAfter = await this.table.countRows();
201
+ return countBefore - countAfter;
202
+ }
203
+ /**
204
+ * Delete all documents.
205
+ */
206
+ async clear(_options) {
207
+ await this.table.delete("id IS NOT NULL");
208
+ }
209
+ /**
210
+ * Get a document by its ID.
211
+ */
212
+ async getById(id, _options) {
213
+ const results = await this.table
214
+ .query()
215
+ .where(`id = '${id}'`)
216
+ .limit(1)
217
+ .toArray();
218
+ if (results.length === 0) {
219
+ return null;
220
+ }
221
+ const row = results[0];
222
+ return {
223
+ id: row.id,
224
+ content: row.text,
225
+ metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
226
+ };
227
+ }
228
+ /**
229
+ * Get existing documents by their content hashes.
230
+ * Used for deduplication during ingestion.
231
+ */
232
+ async getByHashes(hashes, _options) {
233
+ const hashMap = new Map();
234
+ if (hashes.length === 0) {
235
+ return hashMap;
236
+ }
237
+ // Query for documents with matching hashes
238
+ // Since hash is stored in the metadata JSON, we need to check each hash
239
+ for (const hash of hashes) {
240
+ // LanceDB doesn't support JSON path queries, so we search for the hash string
241
+ // in the metadata field. This works because the hash is a unique string.
242
+ const results = await this.table
243
+ .query()
244
+ .where(`metadata LIKE '%${hash}%'`)
245
+ .limit(1)
246
+ .toArray();
247
+ if (results.length > 0) {
248
+ const record = results[0];
249
+ hashMap.set(hash, record.id);
250
+ }
251
+ }
252
+ return hashMap;
253
+ }
254
+ /**
255
+ * Get the underlying LanceDB connection.
256
+ */
257
+ getConnection() {
258
+ return this.connection;
259
+ }
260
+ /**
261
+ * Get the underlying LanceDB table.
262
+ */
263
+ getTable() {
264
+ return this.table;
265
+ }
266
+ /**
267
+ * Get the configured embeddings provider.
268
+ */
269
+ getEmbeddings() {
270
+ return this.embeddings;
271
+ }
272
+ /**
273
+ * Get the vector dimensions.
274
+ */
275
+ getDimensions() {
276
+ return this.dimensions;
277
+ }
278
+ /**
279
+ * Create an index on the vector column for faster searches.
280
+ * Recommended for tables with more than 10,000 rows.
281
+ */
282
+ async createIndex() {
283
+ await this.table.createIndex("vector");
284
+ }
285
+ /**
286
+ * Optimize the table for better performance.
287
+ */
288
+ async optimize() {
289
+ await this.table.optimize();
290
+ }
291
+ /**
292
+ * Build a SQL filter string from a filter object.
293
+ */
294
+ buildFilterString(filter) {
295
+ const conditions = [];
296
+ for (const [key, value] of Object.entries(filter)) {
297
+ if (typeof value === "string") {
298
+ conditions.push(`${key} = '${value}'`);
299
+ }
300
+ else if (typeof value === "number") {
301
+ conditions.push(`${key} = ${value}`);
302
+ }
303
+ else if (typeof value === "boolean") {
304
+ conditions.push(`${key} = ${value}`);
305
+ }
306
+ }
307
+ return conditions.join(" AND ");
308
+ }
309
+ /**
310
+ * Process raw LanceDB results into SearchResult format.
311
+ */
312
+ processResults(results, scoreThreshold) {
313
+ const searchResults = [];
314
+ for (const row of results) {
315
+ // LanceDB returns _distance for vector search
316
+ const distance = row._distance ?? 0;
317
+ // Convert distance to similarity score (lower distance = higher similarity)
318
+ const score = 1 / (1 + distance);
319
+ if (scoreThreshold !== undefined && score < scoreThreshold) {
320
+ continue;
321
+ }
322
+ const metadata = row.metadata
323
+ ? JSON.parse(row.metadata)
324
+ : undefined;
325
+ searchResults.push({
326
+ document: {
327
+ id: row.id,
328
+ content: row.text,
329
+ metadata,
330
+ },
331
+ score,
332
+ });
333
+ }
334
+ return searchResults;
335
+ }
336
+ }
337
+ exports.LanceDBVectorStore = LanceDBVectorStore;
338
+ //# sourceMappingURL=LanceDBVectorStore.js.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * OpenAI embeddings implementation.
3
+ *
4
+ * @requires openai - Uses the OpenAI SDK (already a peer dependency)
5
+ */
6
+ import { Embeddings } from "./Embeddings";
7
+ /**
8
+ * Configuration for OpenAI embeddings.
9
+ */
10
+ export interface OpenAIEmbeddingsConfig {
11
+ /** OpenAI API key (defaults to OPENAI_API_KEY env var) */
12
+ apiKey?: string;
13
+ /** Model to use for embeddings */
14
+ model?: "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002" | string;
15
+ /** Number of dimensions (only for text-embedding-3-* models) */
16
+ dimensions?: number;
17
+ /** Base URL for API (for proxies or compatible APIs) */
18
+ baseURL?: string;
19
+ }
20
+ /**
21
+ * OpenAI embeddings provider.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const embeddings = new OpenAIEmbeddings({
26
+ * model: 'text-embedding-3-small',
27
+ * });
28
+ *
29
+ * const vectors = await embeddings.embed(['Hello world', 'Goodbye world']);
30
+ * ```
31
+ */
32
+ export declare class OpenAIEmbeddings extends Embeddings {
33
+ readonly name = "openai";
34
+ readonly model: string;
35
+ readonly dimensions: number;
36
+ private apiKey;
37
+ private baseURL?;
38
+ private requestedDimensions?;
39
+ constructor(config?: OpenAIEmbeddingsConfig);
40
+ /**
41
+ * Generate embeddings for multiple texts using OpenAI API.
42
+ */
43
+ embed(texts: string[]): Promise<number[][]>;
44
+ }
45
+ //# sourceMappingURL=OpenAIEmbeddings.d.ts.map
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * OpenAI embeddings implementation.
4
+ *
5
+ * @requires openai - Uses the OpenAI SDK (already a peer dependency)
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.OpenAIEmbeddings = void 0;
42
+ const Embeddings_1 = require("./Embeddings");
43
+ /** Default dimensions for each model */
44
+ const MODEL_DIMENSIONS = {
45
+ "text-embedding-3-small": 1536,
46
+ "text-embedding-3-large": 3072,
47
+ "text-embedding-ada-002": 1536,
48
+ };
49
+ /**
50
+ * OpenAI embeddings provider.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const embeddings = new OpenAIEmbeddings({
55
+ * model: 'text-embedding-3-small',
56
+ * });
57
+ *
58
+ * const vectors = await embeddings.embed(['Hello world', 'Goodbye world']);
59
+ * ```
60
+ */
61
+ class OpenAIEmbeddings extends Embeddings_1.Embeddings {
62
+ constructor(config = {}) {
63
+ super();
64
+ this.name = "openai";
65
+ this.model = config.model ?? "text-embedding-3-small";
66
+ this.apiKey = config.apiKey ?? process.env.OPENAI_API_KEY ?? "";
67
+ this.baseURL = config.baseURL;
68
+ this.requestedDimensions = config.dimensions;
69
+ // Determine dimensions
70
+ if (config.dimensions) {
71
+ this.dimensions = config.dimensions;
72
+ }
73
+ else {
74
+ this.dimensions = MODEL_DIMENSIONS[this.model] ?? 1536;
75
+ }
76
+ if (!this.apiKey) {
77
+ throw new Error("OpenAI API key is required. Set OPENAI_API_KEY env var or pass apiKey in config.");
78
+ }
79
+ }
80
+ /**
81
+ * Generate embeddings for multiple texts using OpenAI API.
82
+ */
83
+ async embed(texts) {
84
+ if (texts.length === 0) {
85
+ return [];
86
+ }
87
+ // Dynamic import to keep openai optional at module load time
88
+ const { default: OpenAI } = await Promise.resolve().then(() => __importStar(require("openai")));
89
+ const client = new OpenAI({
90
+ apiKey: this.apiKey,
91
+ baseURL: this.baseURL,
92
+ });
93
+ const params = {
94
+ model: this.model,
95
+ input: texts,
96
+ };
97
+ // Only text-embedding-3-* models support custom dimensions
98
+ if (this.requestedDimensions &&
99
+ this.model.startsWith("text-embedding-3-")) {
100
+ params.dimensions = this.requestedDimensions;
101
+ }
102
+ const response = await client.embeddings.create(params);
103
+ // Sort by index to ensure order matches input
104
+ const sorted = response.data.sort((a, b) => a.index - b.index);
105
+ return sorted.map((item) => item.embedding);
106
+ }
107
+ }
108
+ exports.OpenAIEmbeddings = OpenAIEmbeddings;
109
+ //# sourceMappingURL=OpenAIEmbeddings.js.map