concevent-ai-agent-sdk 3.2.1 → 3.2.2

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 (2) hide show
  1. package/README.md +155 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -22,6 +22,7 @@ A framework-agnostic AI Agent SDK for building intelligent conversational agents
22
22
  - 📋 **Structured Output** - JSON schema validation with Zod for type-safe responses
23
23
  - 🎭 **Multi-Agent Orchestration** - Route tasks to specialized sub-agents based on their capabilities
24
24
  - 📊 **Flow Visualization** - Automatic Mermaid sequence diagrams showing orchestration flow
25
+ - 🔢 **Embeddings** - Generate text embeddings for semantic search and RAG applications
25
26
 
26
27
  ## Installation
27
28
 
@@ -106,6 +107,7 @@ console.log(result.message);
106
107
  - [Middleware](#middleware)
107
108
  - [Multi-Agent Orchestration](#multi-agent-orchestration)
108
109
  - [Orchestration Flow Diagrams](#orchestration-flow-diagrams)
110
+ - [Embeddings](#embeddings)
109
111
 
110
112
  ---
111
113
 
@@ -2206,6 +2208,148 @@ await writeFile("orchestration-flow.md", `\`\`\`mermaid\n${result.diagram}\n\`\`
2206
2208
  - **Special Character Escaping**: Characters that could break Mermaid syntax are safely escaped
2207
2209
  - **Activation Boxes**: Sub-agent calls show activation (`+`/`-`) to indicate processing time
2208
2210
 
2211
+ ### Embeddings
2212
+
2213
+ The SDK provides embedding generation support for semantic search and RAG (Retrieval Augmented Generation) use cases. This uses OpenRouter's OpenAI-compatible embedding endpoint.
2214
+
2215
+ #### Single Embedding
2216
+
2217
+ Generate an embedding vector for a single text input:
2218
+
2219
+ ```typescript
2220
+ import { createEmbedding } from "concevent-ai-agent-sdk";
2221
+
2222
+ const result = await createEmbedding({
2223
+ apiKey: process.env.OPENROUTER_API_KEY!,
2224
+ model: "openai/text-embedding-3-large",
2225
+ input: "Text to embed",
2226
+ dimensions: 3072, // Optional: reduce dimensions
2227
+ });
2228
+
2229
+ console.log(result.embedding); // number[] - the embedding vector
2230
+ console.log(result.model); // Model used
2231
+ console.log(result.usage); // { prompt_tokens, total_tokens }
2232
+ ```
2233
+
2234
+ #### Batch Embeddings
2235
+
2236
+ Generate embeddings for multiple texts in a single request (more efficient):
2237
+
2238
+ ```typescript
2239
+ import { createEmbeddings } from "concevent-ai-agent-sdk";
2240
+
2241
+ const result = await createEmbeddings({
2242
+ apiKey: process.env.OPENROUTER_API_KEY!,
2243
+ model: "openai/text-embedding-3-large",
2244
+ inputs: ["Text 1", "Text 2", "Text 3"],
2245
+ dimensions: 3072, // Optional
2246
+ });
2247
+
2248
+ // Access embeddings by index
2249
+ result.embeddings.forEach(({ index, embedding }) => {
2250
+ console.log(`Embedding ${index}:`, embedding.length, "dimensions");
2251
+ });
2252
+ ```
2253
+
2254
+ #### Configuration
2255
+
2256
+ | Parameter | Type | Required | Default | Description |
2257
+ |-----------|------|----------|---------|-------------|
2258
+ | `apiKey` | `string` | ✅ | - | API key for authentication |
2259
+ | `model` | `string` | ✅ | - | Embedding model to use |
2260
+ | `input` | `string` | ✅ | - | Text to embed (single) |
2261
+ | `inputs` | `string[]` | ✅ | - | Texts to embed (batch) |
2262
+ | `baseURL` | `string` | ❌ | OpenRouter | API base URL |
2263
+ | `dimensions` | `number` | ❌ | Model default | Reduce embedding dimensions |
2264
+
2265
+ #### Recommended Models
2266
+
2267
+ | Model | Dimensions | Best For |
2268
+ |-------|-----------|----------|
2269
+ | `openai/text-embedding-3-large` | 3072 | Highest accuracy, multilingual |
2270
+ | `openai/text-embedding-3-small` | 1536 | Good balance of speed/accuracy |
2271
+ | `openai/text-embedding-ada-002` | 1536 | Legacy, widely compatible |
2272
+
2273
+ #### Semantic Search Example
2274
+
2275
+ ```typescript
2276
+ import { createEmbedding, createEmbeddings } from "concevent-ai-agent-sdk";
2277
+
2278
+ // 1. Build an index from your documents
2279
+ const chunks = ["Document chunk 1...", "Document chunk 2...", "Document chunk 3..."];
2280
+ const { embeddings } = await createEmbeddings({
2281
+ apiKey: process.env.OPENROUTER_API_KEY!,
2282
+ model: "openai/text-embedding-3-large",
2283
+ inputs: chunks,
2284
+ });
2285
+
2286
+ // Store embeddings with your chunks (in a vector database, etc.)
2287
+ const index = chunks.map((text, i) => ({
2288
+ text,
2289
+ embedding: embeddings.find((e) => e.index === i)!.embedding,
2290
+ }));
2291
+
2292
+ // 2. Query with semantic search
2293
+ const { embedding: queryEmbedding } = await createEmbedding({
2294
+ apiKey: process.env.OPENROUTER_API_KEY!,
2295
+ model: "openai/text-embedding-3-large",
2296
+ input: "User's search query",
2297
+ });
2298
+
2299
+ // 3. Find most similar chunks (cosine similarity)
2300
+ function cosineSimilarity(a: number[], b: number[]): number {
2301
+ const dot = a.reduce((sum, val, i) => sum + val * b[i], 0);
2302
+ const magA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
2303
+ const magB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));
2304
+ return dot / (magA * magB);
2305
+ }
2306
+
2307
+ const results = index
2308
+ .map((item) => ({
2309
+ text: item.text,
2310
+ score: cosineSimilarity(queryEmbedding, item.embedding),
2311
+ }))
2312
+ .sort((a, b) => b.score - a.score);
2313
+
2314
+ console.log("Most relevant:", results[0]);
2315
+ ```
2316
+
2317
+ #### Types
2318
+
2319
+ ```typescript
2320
+ interface EmbeddingConfig {
2321
+ apiKey: string;
2322
+ model: string;
2323
+ baseURL?: string;
2324
+ dimensions?: number;
2325
+ }
2326
+
2327
+ interface CreateEmbeddingParams extends EmbeddingConfig {
2328
+ input: string;
2329
+ }
2330
+
2331
+ interface CreateEmbeddingsParams extends EmbeddingConfig {
2332
+ inputs: string[];
2333
+ }
2334
+
2335
+ interface EmbeddingResult {
2336
+ embedding: number[];
2337
+ model: string;
2338
+ usage: EmbeddingUsage;
2339
+ }
2340
+
2341
+ interface EmbeddingsResult {
2342
+ embeddings: Array<{ index: number; embedding: number[] }>;
2343
+ model: string;
2344
+ usage: EmbeddingUsage;
2345
+ }
2346
+
2347
+ interface EmbeddingUsage {
2348
+ prompt_tokens: number;
2349
+ total_tokens: number;
2350
+ }
2351
+ ```
2352
+
2209
2353
  ---
2210
2354
 
2211
2355
  ## Exports Summary
@@ -2359,6 +2503,17 @@ export type {
2359
2503
  TodoWriteParams,
2360
2504
  ReadResultParams,
2361
2505
  } from "./tools";
2506
+
2507
+ // Embeddings
2508
+ export { createEmbedding, createEmbeddings } from "./core/embedding";
2509
+ export type {
2510
+ EmbeddingConfig,
2511
+ CreateEmbeddingParams,
2512
+ CreateEmbeddingsParams,
2513
+ EmbeddingResult,
2514
+ EmbeddingsResult,
2515
+ EmbeddingUsage,
2516
+ } from "./types/embedding";
2362
2517
  ```
2363
2518
 
2364
2519
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "concevent-ai-agent-sdk",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "Framework-agnostic AI Agent SDK with tool calling, conversation management, and automatic summarization",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",