openclaw-memory-alibaba-mysql 0.1.2 → 0.1.4

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/config.ts CHANGED
@@ -26,24 +26,52 @@ export type MemoryConfig = {
26
26
  export const MEMORY_CATEGORIES = ["preference", "fact", "decision", "entity", "other"] as const;
27
27
  export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number];
28
28
 
29
- const DEFAULT_MODEL = "text-embedding-3-small";
29
+ const DEFAULT_MODEL = "text-embedding-v3";
30
+ const DEFAULT_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
30
31
  const DEFAULT_TABLE_NAME = "openclaw_memories";
31
32
  export const DEFAULT_CAPTURE_MAX_CHARS = 500;
32
33
 
33
34
  const EMBEDDING_DIMENSIONS: Record<string, number> = {
35
+ // DashScope (Alibaba Cloud)
36
+ "text-embedding-v3": 1024,
37
+ "text-embedding-v2": 1536,
38
+ // OpenAI
34
39
  "text-embedding-3-small": 1536,
35
40
  "text-embedding-3-large": 3072,
41
+ "text-embedding-ada-002": 1536,
42
+ // Cohere (via OpenAI-compatible endpoint)
43
+ "embed-english-v3.0": 1024,
44
+ "embed-multilingual-v3.0": 1024,
45
+ "embed-english-light-v3.0": 384,
46
+ "embed-multilingual-light-v3.0": 384,
47
+ // Jina
48
+ "jina-embeddings-v3": 1024,
49
+ "jina-embeddings-v2-base-en": 768,
50
+ "jina-embeddings-v2-base-zh": 768,
51
+ // BGE (via Ollama / local)
52
+ "bge-large-zh-v1.5": 1024,
53
+ "bge-large-en-v1.5": 1024,
54
+ "bge-m3": 1024,
55
+ // Nomic (via Ollama)
56
+ "nomic-embed-text": 768,
57
+ // Google
58
+ "text-embedding-004": 768,
36
59
  };
37
60
 
38
- export function vectorDimsForModel(model: string): number {
39
- const dims = EMBEDDING_DIMENSIONS[model];
40
- if (!dims) {
41
- throw new Error(
42
- `Unknown embedding model "${model}": cannot infer dimensions. ` +
43
- `Please set embedding.dimensions explicitly.`,
44
- );
45
- }
46
- return dims;
61
+ const FLEX_DIMS_MODELS = new Set([
62
+ "text-embedding-v3",
63
+ "text-embedding-3-small",
64
+ "text-embedding-3-large",
65
+ "jina-embeddings-v3",
66
+ ]);
67
+
68
+ export function vectorDimsForModel(model: string, explicit?: number): number {
69
+ if (explicit && explicit > 0) return explicit;
70
+ return EMBEDDING_DIMENSIONS[model] ?? 1024;
71
+ }
72
+
73
+ export function modelSupportsFlexDimensions(model: string): boolean {
74
+ return FLEX_DIMS_MODELS.has(model);
47
75
  }
48
76
 
49
77
  function resolveEnvVars(value: string): string {
@@ -84,7 +112,7 @@ function parseMysqlConfig(raw: unknown): MysqlConnectionConfig {
84
112
  user: requireString(m, "user", "mysql"),
85
113
  password: resolveEnvVars(requireString(m, "password", "mysql")),
86
114
  database: requireString(m, "database", "mysql"),
87
- ssl: m.ssl !== false,
115
+ ssl: m.ssl === true,
88
116
  };
89
117
  }
90
118
 
@@ -96,16 +124,13 @@ function parseEmbeddingConfig(raw: unknown): EmbeddingConfig {
96
124
  assertAllowedKeys(e, ["apiKey", "model", "baseUrl", "dimensions"], "embedding");
97
125
 
98
126
  const model = typeof e.model === "string" ? e.model : DEFAULT_MODEL;
99
-
100
- if (typeof e.dimensions !== "number") {
101
- vectorDimsForModel(model);
102
- }
127
+ const explicitDims = typeof e.dimensions === "number" ? e.dimensions : undefined;
103
128
 
104
129
  return {
105
130
  apiKey: resolveEnvVars(requireString(e, "apiKey", "embedding")),
106
131
  model,
107
- baseUrl: typeof e.baseUrl === "string" ? resolveEnvVars(e.baseUrl) : undefined,
108
- dimensions: typeof e.dimensions === "number" ? e.dimensions : undefined,
132
+ baseUrl: typeof e.baseUrl === "string" ? resolveEnvVars(e.baseUrl) : DEFAULT_BASE_URL,
133
+ dimensions: explicitDims,
109
134
  };
110
135
  }
111
136
 
@@ -138,7 +163,7 @@ export const memoryConfigSchema = {
138
163
  mysql: parseMysqlConfig(cfg.mysql),
139
164
  embedding: parseEmbeddingConfig(cfg.embedding),
140
165
  autoRecall: cfg.autoRecall !== false,
141
- autoCapture: cfg.autoCapture === true,
166
+ autoCapture: cfg.autoCapture !== false,
142
167
  captureMaxChars: captureMaxChars ?? DEFAULT_CAPTURE_MAX_CHARS,
143
168
  tableName,
144
169
  };
package/index.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  type MemoryCategory,
16
16
  memoryConfigSchema,
17
17
  vectorDimsForModel,
18
+ modelSupportsFlexDimensions,
18
19
  } from "./config.js";
19
20
  import { MemoryDB } from "./db.js";
20
21
 
@@ -24,6 +25,7 @@ import { MemoryDB } from "./db.js";
24
25
 
25
26
  class Embeddings {
26
27
  private client: OpenAI;
28
+ private sendDimensions: boolean;
27
29
 
28
30
  constructor(
29
31
  apiKey: string,
@@ -32,6 +34,7 @@ class Embeddings {
32
34
  private dimensions?: number,
33
35
  ) {
34
36
  this.client = new OpenAI({ apiKey, baseURL: baseUrl });
37
+ this.sendDimensions = modelSupportsFlexDimensions(model);
35
38
  }
36
39
 
37
40
  async embed(text: string): Promise<number[]> {
@@ -39,7 +42,7 @@ class Embeddings {
39
42
  model: this.model,
40
43
  input: text,
41
44
  };
42
- if (this.dimensions) {
45
+ if (this.sendDimensions && this.dimensions) {
43
46
  params.dimensions = this.dimensions;
44
47
  }
45
48
  const response = await this.client.embeddings.create(params);
@@ -162,9 +165,9 @@ const memoryPlugin = {
162
165
  const cfg = memoryConfigSchema.parse(api.pluginConfig);
163
166
  const { model, dimensions, apiKey, baseUrl } = cfg.embedding;
164
167
 
165
- const vectorDim = dimensions ?? vectorDimsForModel(model);
168
+ const vectorDim = vectorDimsForModel(model, dimensions);
166
169
  const db = new MemoryDB(cfg.mysql, cfg.tableName, vectorDim);
167
- const embeddings = new Embeddings(apiKey, model, baseUrl, dimensions);
170
+ const embeddings = new Embeddings(apiKey, model, baseUrl, vectorDim);
168
171
 
169
172
  api.logger.info(
170
173
  `openclaw-memory-alibaba-mysql: plugin registered (host: ${cfg.mysql.host}, table: ${cfg.tableName}, lazy init)`,
@@ -277,7 +280,7 @@ const memoryPlugin = {
277
280
  });
278
281
 
279
282
  return {
280
- content: [{ type: "text", text: `Stored: "${text.slice(0, 100)}..."` }],
283
+ content: [{ type: "text", text: `Stored: "${text.length > 100 ? text.slice(0, 100) + "..." : text}"` }],
281
284
  details: { action: "created", id: entry.id },
282
285
  };
283
286
  },
@@ -381,7 +384,7 @@ const memoryPlugin = {
381
384
  return;
382
385
  }
383
386
 
384
- api.logger.info?.(
387
+ api.logger.info(
385
388
  `openclaw-memory-alibaba-mysql: injecting ${results.length} memories into context`,
386
389
  );
387
390
 
@@ -34,22 +34,21 @@
34
34
  "embedding.apiKey": {
35
35
  "label": "Embedding API Key",
36
36
  "sensitive": true,
37
- "placeholder": "sk-proj-... or ${OPENAI_API_KEY}"
37
+ "placeholder": "sk-... or ${DASHSCOPE_API_KEY}"
38
38
  },
39
39
  "embedding.model": {
40
40
  "label": "Embedding Model",
41
- "placeholder": "text-embedding-3-small"
41
+ "placeholder": "text-embedding-v3"
42
42
  },
43
43
  "embedding.baseUrl": {
44
44
  "label": "Embedding Base URL",
45
- "placeholder": "https://api.openai.com/v1",
46
- "help": "DashScope: https://dashscope.aliyuncs.com/compatible-mode/v1",
45
+ "placeholder": "https://dashscope.aliyuncs.com/compatible-mode/v1",
47
46
  "advanced": true
48
47
  },
49
48
  "embedding.dimensions": {
50
49
  "label": "Dimensions",
51
- "placeholder": "1536",
52
- "help": "Vector dimensions (required for non-standard models)",
50
+ "placeholder": "1024",
51
+ "help": "Vector dimensions (auto-detected from model if not set)",
53
52
  "advanced": true
54
53
  },
55
54
  "autoCapture": {
@@ -87,7 +86,7 @@
87
86
  "user": { "type": "string" },
88
87
  "password": { "type": "string" },
89
88
  "database": { "type": "string" },
90
- "ssl": { "type": "boolean", "default": true }
89
+ "ssl": { "type": "boolean", "default": false }
91
90
  }
92
91
  },
93
92
  "embedding": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-memory-alibaba-mysql",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "OpenClaw memory plugin using Alibaba Cloud RDS MySQL vector storage",
5
5
  "type": "module",
6
6
  "license": "MIT",