Skip to content

Commit b68d13a

Browse files
authored
fix(memory): bound LanceDB prompts and reload embedding config (#125567)
* fix(memory): bound LanceDB recall and reload embeddings * fix(memory): preserve LanceDB index identity
1 parent 7f4bc83 commit b68d13a

11 files changed

Lines changed: 528 additions & 124 deletions

‎docs/plugins/memory-lancedb.md‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ with the current memory provider.
6565
}
6666
```
6767

68-
Restart the Gateway after changing plugin config, then verify it loaded:
68+
Restart the Gateway after installation, then verify it loaded:
6969

7070
```bash
7171
openclaw gateway restart
@@ -81,8 +81,8 @@ defaults to `openai`; `model` defaults to `text-embedding-3-small`.
8181
| ---------------------- | ------------- | ------------------------------------------------------------------------ |
8282
| `embedding.provider` | string | Adapter id, e.g. `openai`, `github-copilot`, `ollama`. Default `openai`. |
8383
| `embedding.model` | string | Default `text-embedding-3-small`. |
84-
| `embedding.apiKey` | string | Optional; supports `${ENV_VAR}` expansion. |
85-
| `embedding.baseUrl` | string | Optional; supports `${ENV_VAR}` expansion. |
84+
| `embedding.apiKey` | string | Optional; supports `${ENV_VAR}` expansion and live credential rotation. |
85+
| `embedding.baseUrl` | string | Optional; supports `${ENV_VAR}` expansion and live endpoint rotation. |
8686
| `embedding.dimensions` | integer (>=1) | Required for models not in the built-in table (see below). |
8787

8888
Two request paths exist:
@@ -98,6 +98,18 @@ Two request paths exist:
9898
for a raw OpenAI-compatible embeddings endpoint that has no bundled provider
9999
adapter.
100100

101+
`embedding.apiKey` and `embedding.baseUrl` are re-read from live plugin config
102+
for the next memory operation, as long as `provider`, `model`, and `dimensions`
103+
remain unchanged.
104+
105+
<Warning>
106+
`embedding.provider`, `embedding.model`, and `embedding.dimensions` define the
107+
persisted LanceDB index identity and do not change live. Before restarting with
108+
a new identity, plan a LanceDB re-embedding or rebuild so every stored row uses
109+
the new vector space and dimensions. The plugin does not re-embed existing rows
110+
automatically.
111+
</Warning>
112+
101113
OpenAI Codex / ChatGPT OAuth is not an OpenAI Platform embeddings credential.
102114
For OpenAI embeddings use an OpenAI API key auth profile, `OPENAI_API_KEY`, or
103115
`models.providers.openai.apiKey`. OAuth-only users should pick another
@@ -191,21 +203,23 @@ local server returns context-length errors.
191203

192204
## Recall and capture limits
193205

194-
| Setting | Default | Range | Applies to |
195-
| ----------------- | ------- | --------------------------- | ---------------------------------------------------------- |
196-
| `recallMaxChars` | `1000` | 100-10000 | Text sent to the embedding API for recall. |
197-
| `captureMaxChars` | `500` | 100-10000 | Message length eligible for auto-capture. |
198-
| `customTriggers` | `[]` | 0-50 items, each ≤100 chars | Literal phrases that make auto-capture consider a message. |
206+
| Setting | Default | Range | Applies to |
207+
| ----------------- | ------- | --------------------------- | ----------------------------------------------------------------- |
208+
| `recallMaxChars` | `1000` | 100-10000 | Recall query length and each escaped model-visible recalled item. |
209+
| `captureMaxChars` | `500` | 100-10000 | `memory_store` input limit and auto-capture eligibility. |
210+
| `customTriggers` | `[]` | 0-50 items, each ≤100 chars | Literal phrases that make auto-capture consider a message. |
199211

200212
`recallMaxChars` bounds the `before_prompt_build` auto-recall query, the
201213
`memory_recall` tool, the `memory_forget` query path, and `openclaw ltm search`.
202214
Auto-recall embeds the latest user message from the turn and falls back to the
203215
full prompt only when no user message is present, keeping channel metadata and
204-
large prompt blocks out of the embedding request.
216+
large prompt blocks out of the embedding request. It also bounds each recalled
217+
item after prompt escaping before that text reaches the model.
205218

206219
`captureMaxChars` gates whether a user message from the turn's `agent_end`
207-
event is short enough to be considered for auto-capture; it does not affect
208-
recall queries.
220+
event is short enough to be considered for auto-capture. `memory_store` rejects
221+
longer text before embedding or storage; the setting does not affect recall
222+
queries.
209223

210224
`customTriggers` adds literal auto-capture phrases without regex. Built-in
211225
triggers cover common English, Czech, Chinese, Japanese, and Korean memory
@@ -341,7 +355,7 @@ The embedding model rejected the recall query:
341355
memory-lancedb: recall failed: Error: 400 the input length exceeds the context length
342356
```
343357

344-
Lower `recallMaxChars`, then restart the Gateway:
358+
Lower `recallMaxChars`; the new limit applies to the next memory operation:
345359

346360
```json5
347361
{

‎extensions/memory-lancedb/config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export type MemoryConfig = {
1515
dbPath?: string;
1616
autoCapture?: boolean;
1717
autoRecall?: boolean;
18-
captureMaxChars?: number;
18+
captureMaxChars: number;
1919
customTriggers?: string[];
20-
recallMaxChars?: number;
20+
recallMaxChars: number;
2121
storageOptions?: Record<string, string>;
2222
};
2323

0 commit comments

Comments
 (0)