Skip to content

Commit 6675aac

Browse files
rish2jainOpenClaw Bot
andauthored
feat(memory-lancedb): Custom OpenAI BaseURL & Dimensions Support (#17874)
* feat(memory-lancedb): add custom baseUrl and dimensions support * fix(memory-lancedb): strict model typing and safe dimension resolution * style: fix formatting in memory-lancedb config * fix(memory-lancedb): sync manifest schema with new embedding options --------- Co-authored-by: OpenClaw Bot <bot@openclaw.ai>
1 parent 62fa65e commit 6675aac

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

extensions/memory-lancedb/config.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { join } from "node:path";
55
export type MemoryConfig = {
66
embedding: {
77
provider: "openai";
8-
model?: string;
8+
model: string;
99
apiKey: string;
10+
baseUrl?: string;
11+
dimensions?: number;
1012
};
1113
dbPath?: string;
1214
autoCapture?: boolean;
@@ -81,7 +83,9 @@ function resolveEnvVars(value: string): string {
8183

8284
function resolveEmbeddingModel(embedding: Record<string, unknown>): string {
8385
const model = typeof embedding.model === "string" ? embedding.model : DEFAULT_MODEL;
84-
vectorDimsForModel(model);
86+
if (typeof embedding.dimensions !== "number") {
87+
vectorDimsForModel(model);
88+
}
8589
return model;
8690
}
8791

@@ -101,7 +105,7 @@ export const memoryConfigSchema = {
101105
if (!embedding || typeof embedding.apiKey !== "string") {
102106
throw new Error("embedding.apiKey is required");
103107
}
104-
assertAllowedKeys(embedding, ["apiKey", "model"], "embedding config");
108+
assertAllowedKeys(embedding, ["apiKey", "model", "baseUrl", "dimensions"], "embedding config");
105109

106110
const model = resolveEmbeddingModel(embedding);
107111

@@ -119,6 +123,9 @@ export const memoryConfigSchema = {
119123
provider: "openai",
120124
model,
121125
apiKey: resolveEnvVars(embedding.apiKey),
126+
baseUrl:
127+
typeof embedding.baseUrl === "string" ? resolveEnvVars(embedding.baseUrl) : undefined,
128+
dimensions: typeof embedding.dimensions === "number" ? embedding.dimensions : undefined,
122129
},
123130
dbPath: typeof cfg.dbPath === "string" ? cfg.dbPath : DEFAULT_DB_PATH,
124131
autoCapture: cfg.autoCapture === true,
@@ -133,6 +140,18 @@ export const memoryConfigSchema = {
133140
placeholder: "sk-proj-...",
134141
help: "API key for OpenAI embeddings (or use ${OPENAI_API_KEY})",
135142
},
143+
"embedding.baseUrl": {
144+
label: "Base URL",
145+
placeholder: "https://api.openai.com/v1",
146+
help: "Base URL for compatible providers (e.g. http://localhost:11434/v1)",
147+
advanced: true,
148+
},
149+
"embedding.dimensions": {
150+
label: "Dimensions",
151+
placeholder: "1536",
152+
help: "Vector dimensions for custom models (required for non-standard models)",
153+
advanced: true,
154+
},
136155
"embedding.model": {
137156
label: "Embedding Model",
138157
placeholder: DEFAULT_MODEL,

extensions/memory-lancedb/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ class Embeddings {
166166
constructor(
167167
apiKey: string,
168168
private model: string,
169+
baseUrl?: string,
169170
) {
170-
this.client = new OpenAI({ apiKey });
171+
this.client = new OpenAI({ apiKey, baseURL: baseUrl });
171172
}
172173

173174
async embed(text: string): Promise<number[]> {
@@ -293,9 +294,11 @@ const memoryPlugin = {
293294
register(api: OpenClawPluginApi) {
294295
const cfg = memoryConfigSchema.parse(api.pluginConfig);
295296
const resolvedDbPath = api.resolvePath(cfg.dbPath!);
296-
const vectorDim = vectorDimsForModel(cfg.embedding.model ?? "text-embedding-3-small");
297+
const { model, dimensions, apiKey, baseUrl } = cfg.embedding;
298+
299+
const vectorDim = dimensions ?? vectorDimsForModel(model);
297300
const db = new MemoryDB(resolvedDbPath, vectorDim);
298-
const embeddings = new Embeddings(cfg.embedding.apiKey, cfg.embedding.model!);
301+
const embeddings = new Embeddings(apiKey, model, baseUrl);
299302

300303
api.logger.info(`memory-lancedb: plugin registered (db: ${resolvedDbPath}, lazy init)`);
301304

extensions/memory-lancedb/openclaw.plugin.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
"placeholder": "text-embedding-3-small",
1414
"help": "OpenAI embedding model to use"
1515
},
16+
"embedding.baseUrl": {
17+
"label": "Base URL",
18+
"placeholder": "https://api.openai.com/v1",
19+
"help": "Base URL for compatible providers (e.g. http://localhost:11434/v1)",
20+
"advanced": true
21+
},
22+
"embedding.dimensions": {
23+
"label": "Dimensions",
24+
"placeholder": "1536",
25+
"help": "Vector dimensions for custom models (required for non-standard models)",
26+
"advanced": true
27+
},
1628
"dbPath": {
1729
"label": "Database Path",
1830
"placeholder": "~/.openclaw/memory/lancedb",
@@ -45,8 +57,13 @@
4557
"type": "string"
4658
},
4759
"model": {
48-
"type": "string",
49-
"enum": ["text-embedding-3-small", "text-embedding-3-large"]
60+
"type": "string"
61+
},
62+
"baseUrl": {
63+
"type": "string"
64+
},
65+
"dimensions": {
66+
"type": "number"
5067
}
5168
},
5269
"required": ["apiKey"]

0 commit comments

Comments
 (0)