Skip to content

Commit a0a0ab4

Browse files
committed
fix(memory): resolve custom embedding provider ids
1 parent 632b0fd commit a0a0ab4

9 files changed

Lines changed: 231 additions & 21 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Docs: https://docs.openclaw.ai
3434

3535
### Fixes
3636

37+
- Memory/Ollama: resolve `memorySearch.provider` custom provider ids through their configured `models.providers.<id>.api` owner, so multi-GPU Ollama setups can dedicate embeddings to providers such as `ollama-5080` without losing the Ollama adapter or local auth semantics. Fixes #73150. Thanks @oneandrewwang.
3738
- CLI/memory: skip eager context-window warmup for `openclaw memory` commands so memory search does not race unrelated model metadata discovery. Fixes #73123. Thanks @oalansilva and @neeravmakwana.
3839
- CLI/Telegram: route Telegram `message send` and poll actions through the running Gateway when available, so packaged installs use the staged `grammy` runtime deps and CLI sends return instead of hanging after the Telegram channel is active. Fixes #73140. Thanks @oalansilva.
3940
- Cron/providers: preflight local Ollama and OpenAI-compatible provider endpoints before isolated cron agent turns, record unreachable local providers as skipped runs, and cache dead-endpoint probes so many jobs do not hammer the same stopped local server. Fixes #58584. Thanks @jpeghead.

‎docs/concepts/memory-search.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ explicitly:
2929
}
3030
```
3131

32+
For multi-endpoint setups, `provider` can also be a custom
33+
`models.providers.<id>` entry, such as `ollama-5080`, when that provider sets
34+
`api: "ollama"` or another embedding adapter owner.
35+
3236
For local embeddings with no API key, install the optional `node-llama-cpp`
3337
runtime package next to OpenClaw and use `provider: "local"`.
3438

‎docs/providers/ollama.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Ollama provider config uses `baseUrl` as the canonical key. OpenClaw also accept
2525
Remote public hosts and Ollama Cloud (`https://ollama.com`) require a real credential through `OLLAMA_API_KEY`, an auth profile, or the provider's `apiKey`.
2626
</Accordion>
2727
<Accordion title="Custom provider ids">
28-
Custom provider ids that set `api: "ollama"` follow the same rules. For example, an `ollama-remote` provider that points at a private LAN Ollama host can use `apiKey: "ollama-local"` and sub-agents will resolve that marker through the Ollama provider hook instead of treating it as a missing credential.
28+
Custom provider ids that set `api: "ollama"` follow the same rules. For example, an `ollama-remote` provider that points at a private LAN Ollama host can use `apiKey: "ollama-local"` and sub-agents will resolve that marker through the Ollama provider hook instead of treating it as a missing credential. Memory search can also set `agents.defaults.memorySearch.provider` to that custom provider id so embeddings use the matching Ollama endpoint.
2929
</Accordion>
3030
<Accordion title="Memory embedding scope">
3131
When Ollama is used for memory embeddings, bearer auth is scoped to the host where it was declared:

‎docs/reference/memory-config.md‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ See [Active Memory](/concepts/active-memory) for the activation model, plugin-ow
4646

4747
## Provider selection
4848

49-
| Key | Type | Default | Description |
50-
| ---------- | --------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------- |
51-
| `provider` | `string` | auto-detected | Embedding adapter ID: `bedrock`, `deepinfra`, `gemini`, `github-copilot`, `local`, `mistral`, `ollama`, `openai`, `voyage` |
52-
| `model` | `string` | provider default | Embedding model name |
53-
| `fallback` | `string` | `"none"` | Fallback adapter ID when the primary fails |
54-
| `enabled` | `boolean` | `true` | Enable or disable memory search |
49+
| Key | Type | Default | Description |
50+
| ---------- | --------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
51+
| `provider` | `string` | auto-detected | Embedding adapter ID such as `bedrock`, `deepinfra`, `gemini`, `github-copilot`, `local`, `mistral`, `ollama`, `openai`, or `voyage`; may also be a configured `models.providers.<id>` whose `api` points at one of those adapters |
52+
| `model` | `string` | provider default | Embedding model name |
53+
| `fallback` | `string` | `"none"` | Fallback adapter ID when the primary fails |
54+
| `enabled` | `boolean` | `true` | Enable or disable memory search |
5555

5656
### Auto-detection order
5757

@@ -86,6 +86,33 @@ When `provider` is not set, OpenClaw selects the first available:
8686

8787
`ollama` is supported but not auto-detected (set it explicitly).
8888

89+
### Custom provider ids
90+
91+
`memorySearch.provider` can point at a custom `models.providers.<id>` entry. OpenClaw resolves that provider's `api` owner for the embedding adapter while preserving the custom provider id for endpoint, auth, and model-prefix handling. This lets multi-GPU or multi-host setups dedicate memory embeddings to a specific local endpoint:
92+
93+
```json5
94+
{
95+
models: {
96+
providers: {
97+
"ollama-5080": {
98+
api: "ollama",
99+
baseUrl: "http://gpu-box.local:11435",
100+
apiKey: "ollama-local",
101+
models: [{ id: "qwen3-embedding:0.6b" }],
102+
},
103+
},
104+
},
105+
agents: {
106+
defaults: {
107+
memorySearch: {
108+
provider: "ollama-5080",
109+
model: "qwen3-embedding:0.6b",
110+
},
111+
},
112+
},
113+
}
114+
```
115+
89116
### API key resolution
90117

91118
Remote embeddings require an API key. Bedrock uses the AWS SDK default credential chain instead (instance roles, SSO, access keys).

‎src/agents/memory-search.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,33 @@ describe("memory search config", () => {
199199
expect(resolved?.fallback).toBe("none");
200200
});
201201

202+
it("resolves custom provider ids through their configured api owner", () => {
203+
const cfg = asConfig({
204+
models: {
205+
providers: {
206+
"ollama-5080": {
207+
api: "ollama",
208+
baseUrl: "http://10.0.0.8:11435",
209+
models: [],
210+
},
211+
},
212+
},
213+
agents: {
214+
defaults: {
215+
memorySearch: {
216+
provider: "ollama-5080",
217+
},
218+
},
219+
},
220+
});
221+
222+
const resolved = resolveMemorySearchConfig(cfg, "main");
223+
224+
expect(resolved?.provider).toBe("ollama-5080");
225+
expect(resolved?.model).toBe("nomic-embed-text");
226+
expectDefaultRemoteBatch(resolved);
227+
});
228+
202229
it("resolves sync config without consulting embedding providers", () => {
203230
clearMemoryEmbeddingProviders();
204231
const cfg = asConfig({

‎src/agents/memory-search.ts‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { getMemoryEmbeddingProvider } from "../plugins/memory-embedding-providers.js";
1212
import { clampInt, clampNumber, resolveUserPath } from "../utils.js";
1313
import { resolveAgentConfig } from "./agent-scope.js";
14+
import { findNormalizedProviderValue, normalizeProviderId } from "./provider-id.js";
1415

1516
export type ResolvedMemorySearchConfig = {
1617
enabled: boolean;
@@ -147,7 +148,29 @@ function resolveStorePath(agentId: string, raw?: string): string {
147148
return resolveUserPath(withToken);
148149
}
149150

151+
function getConfiguredMemoryEmbeddingProvider(
152+
providerId: string,
153+
cfg: OpenClawConfig,
154+
): ReturnType<typeof getMemoryEmbeddingProvider> {
155+
const directAdapter = getMemoryEmbeddingProvider(providerId);
156+
if (directAdapter) {
157+
return directAdapter;
158+
}
159+
const providerConfig = findNormalizedProviderValue(cfg.models?.providers, providerId);
160+
const ownerApi = providerConfig?.api?.trim();
161+
if (!ownerApi) {
162+
return undefined;
163+
}
164+
const normalizedProvider = normalizeProviderId(providerId);
165+
const normalizedOwner = normalizeProviderId(ownerApi);
166+
if (!normalizedOwner || normalizedOwner === normalizedProvider) {
167+
return undefined;
168+
}
169+
return getMemoryEmbeddingProvider(normalizedOwner);
170+
}
171+
150172
function mergeConfig(
173+
cfg: OpenClawConfig,
151174
defaults: MemorySearchConfig | undefined,
152175
overrides: MemorySearchConfig | undefined,
153176
agentId: string,
@@ -156,12 +179,15 @@ function mergeConfig(
156179
const sessionMemory =
157180
overrides?.experimental?.sessionMemory ?? defaults?.experimental?.sessionMemory ?? false;
158181
const provider = overrides?.provider ?? defaults?.provider ?? "auto";
159-
const primaryAdapter = provider === "auto" ? undefined : getMemoryEmbeddingProvider(provider);
182+
const primaryAdapter =
183+
provider === "auto" ? undefined : getConfiguredMemoryEmbeddingProvider(provider, cfg);
160184
const defaultRemote = defaults?.remote;
161185
const overrideRemote = overrides?.remote;
162186
const fallback = overrides?.fallback ?? defaults?.fallback ?? "none";
163187
const fallbackAdapter =
164-
fallback && fallback !== "none" ? getMemoryEmbeddingProvider(fallback) : undefined;
188+
fallback && fallback !== "none"
189+
? getConfiguredMemoryEmbeddingProvider(fallback, cfg)
190+
: undefined;
165191
const hasRemoteConfig = Boolean(
166192
overrideRemote?.baseUrl ||
167193
overrideRemote?.apiKey ||
@@ -402,15 +428,17 @@ export function resolveMemorySearchConfig(
402428
): ResolvedMemorySearchConfig | null {
403429
const defaults = cfg.agents?.defaults?.memorySearch;
404430
const overrides = resolveAgentConfig(cfg, agentId)?.memorySearch;
405-
const resolved = mergeConfig(defaults, overrides, agentId);
431+
const resolved = mergeConfig(cfg, defaults, overrides, agentId);
406432
if (!resolved.enabled) {
407433
return null;
408434
}
409435
const multimodalActive = isMemoryMultimodalEnabled(resolved.multimodal);
410436
const multimodalProvider =
411-
resolved.provider === "auto" ? undefined : getMemoryEmbeddingProvider(resolved.provider);
412-
// Config resolution is a startup/doctor hot path; only validate adapters
413-
// already registered by the active runtime instead of cold-loading plugins.
437+
resolved.provider === "auto"
438+
? undefined
439+
: getConfiguredMemoryEmbeddingProvider(resolved.provider, cfg);
440+
// Custom provider ids can map to a memory adapter through models.providers.<id>.api.
441+
// Keep multimodal validation on that config-aware adapter, not the raw id.
414442
if (
415443
multimodalActive &&
416444
multimodalProvider &&

‎src/agents/model-auth.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,40 @@ describe("resolveApiKeyForProvider – synthetic local auth for custom providers
964964
});
965965
});
966966

967+
it("uses Ollama plugin synthetic auth for custom private provider ids without apiKey", async () => {
968+
const auth = await resolveApiKeyForProvider({
969+
provider: "ollama-gpu1",
970+
cfg: {
971+
models: {
972+
providers: {
973+
"ollama-gpu1": {
974+
baseUrl: "http://192.168.178.122:11435",
975+
api: "ollama",
976+
models: [
977+
{
978+
id: "qwen3:14b",
979+
name: "Qwen 3 14B",
980+
reasoning: true,
981+
input: ["text"],
982+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
983+
contextWindow: 16384,
984+
maxTokens: 4096,
985+
},
986+
],
987+
},
988+
},
989+
},
990+
},
991+
store: { version: 1, profiles: {} },
992+
});
993+
994+
expect(auth).toMatchObject({
995+
apiKey: "ollama-local",
996+
source: "models.providers.ollama-gpu1 (synthetic local key)",
997+
mode: "api-key",
998+
});
999+
});
1000+
9671001
it("accepts non-secret local markers for private LAN custom OpenAI-compatible providers", async () => {
9681002
const auth = await resolveApiKeyForProvider({
9691003
provider: "custom-192-168-0-222-11434",

‎src/plugins/memory-embedding-provider-runtime.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,57 @@ describe("memory embedding provider runtime resolution", () => {
7373
});
7474
});
7575

76+
it("uses a configured provider api as the memory adapter owner", () => {
77+
const ollamaAdapter = createCapabilityAdapter("ollama");
78+
mocks.resolvePluginCapabilityProvider.mockImplementation(({ providerId }) =>
79+
providerId === "ollama" ? ollamaAdapter : undefined,
80+
);
81+
82+
expect(
83+
runtimeModule.getMemoryEmbeddingProvider("ollama-5080", {
84+
models: {
85+
providers: {
86+
"ollama-5080": {
87+
api: "ollama",
88+
baseUrl: "http://10.0.0.8:11435",
89+
models: [],
90+
},
91+
},
92+
},
93+
} as never),
94+
).toBe(ollamaAdapter);
95+
expect(mocks.resolvePluginCapabilityProvider).toHaveBeenCalledWith({
96+
key: "memoryEmbeddingProviders",
97+
providerId: "ollama-5080",
98+
cfg: expect.any(Object),
99+
});
100+
expect(mocks.resolvePluginCapabilityProvider).toHaveBeenCalledWith({
101+
key: "memoryEmbeddingProviders",
102+
providerId: "ollama",
103+
cfg: expect.any(Object),
104+
});
105+
});
106+
107+
it("uses registered adapters through a configured provider api", () => {
108+
const ollamaAdapter = createCapabilityAdapter("ollama");
109+
registerMemoryEmbeddingProvider(ollamaAdapter);
110+
111+
expect(
112+
runtimeModule.getMemoryEmbeddingProvider("ollama-gpu1", {
113+
models: {
114+
providers: {
115+
"ollama-gpu1": {
116+
api: "ollama",
117+
baseUrl: "http://ollama-host:11435",
118+
models: [],
119+
},
120+
},
121+
},
122+
} as never),
123+
).toBe(ollamaAdapter);
124+
expect(mocks.resolvePluginCapabilityProvider).not.toHaveBeenCalled();
125+
});
126+
76127
it("prefers registered adapters over declared capability fallback adapters with the same id", () => {
77128
const registered = {
78129
id: "openai",

‎src/plugins/memory-embedding-provider-runtime.ts‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { normalizeProviderId } from "../agents/provider-id.js";
12
import type { OpenClawConfig } from "../config/types.openclaw.js";
23
import {
34
resolvePluginCapabilityProvider,
@@ -30,17 +31,54 @@ export function listMemoryEmbeddingProviders(
3031
return [...merged.values()];
3132
}
3233

34+
function readConfiguredProviderApiId(providerId: string, cfg?: OpenClawConfig): string | undefined {
35+
const providers = cfg?.models?.providers;
36+
if (!providers) {
37+
return undefined;
38+
}
39+
const normalized = normalizeProviderId(providerId);
40+
const providerConfig =
41+
providers[providerId] ??
42+
Object.entries(providers).find(
43+
([candidateId]) => normalizeProviderId(candidateId) === normalized,
44+
)?.[1];
45+
const api = providerConfig?.api?.trim();
46+
if (!api) {
47+
return undefined;
48+
}
49+
const normalizedApi = normalizeProviderId(api);
50+
return normalizedApi && normalizedApi !== normalized ? normalizedApi : undefined;
51+
}
52+
53+
function resolveMemoryEmbeddingProviderLookupIds(id: string, cfg?: OpenClawConfig): string[] {
54+
const ids = [id];
55+
const apiId = readConfiguredProviderApiId(id, cfg);
56+
if (apiId && !ids.some((candidate) => normalizeProviderId(candidate) === apiId)) {
57+
ids.push(apiId);
58+
}
59+
return ids;
60+
}
61+
3362
export function getMemoryEmbeddingProvider(
3463
id: string,
3564
cfg?: OpenClawConfig,
3665
): MemoryEmbeddingProviderAdapter | undefined {
37-
const registered = getRegisteredMemoryEmbeddingProvider(id);
38-
if (registered) {
39-
return registered.adapter;
66+
const ids = resolveMemoryEmbeddingProviderLookupIds(id, cfg);
67+
for (const candidateId of ids) {
68+
const registered = getRegisteredMemoryEmbeddingProvider(candidateId);
69+
if (registered) {
70+
return registered.adapter;
71+
}
4072
}
41-
return resolvePluginCapabilityProvider({
42-
key: "memoryEmbeddingProviders",
43-
providerId: id,
44-
cfg,
45-
});
73+
for (const candidateId of ids) {
74+
const provider = resolvePluginCapabilityProvider({
75+
key: "memoryEmbeddingProviders",
76+
providerId: candidateId,
77+
cfg,
78+
});
79+
if (provider) {
80+
return provider;
81+
}
82+
}
83+
return undefined;
4684
}

0 commit comments

Comments
 (0)