feat(memory): add gemini-embedding-2-preview support

- Add gemini-embedding-2-preview to supported embedding models
- Support outputDimensionality (768/1536/3072, default 3072) for v2 models
- Support taskType parameter for semantic retrieval optimization
- Add multimodal part builders (buildInlineDataPart, buildFileDataPart)
- Set 8192 token limit for gemini-embedding-2-preview
- Maintain backward compatibility for gemini-embedding-001 (no new fields)
- Add comprehensive test coverage (26 tests)

Closes #42487
This commit is contained in:
Pip Build
2026-03-10 16:56:42 -04:00
parent 283570de4d
commit b21f452df8
5 changed files with 542 additions and 14 deletions

View File

@@ -310,6 +310,28 @@ Notes:
- `remote.baseUrl` is optional (defaults to the Gemini API base URL).
- `remote.headers` lets you add extra headers if needed.
- Default model: `gemini-embedding-001`.
- `gemini-embedding-2-preview` is also supported: multimodal inputs, 8192 token limit, configurable dimensions (768 / 1536 / 3072, default 3072).
#### Gemini Embedding 2 (preview)
```json5
agents: {
defaults: {
memorySearch: {
provider: "gemini",
model: "gemini-embedding-2-preview",
outputDimensionality: 3072, // optional: 768, 1536, or 3072 (default)
remote: {
apiKey: "YOUR_GEMINI_API_KEY"
}
}
}
}
```
> **⚠️ Re-index required:** Switching from `gemini-embedding-001` (768 dimensions)
> to `gemini-embedding-2-preview` (3072 dimensions) changes the vector size.
> OpenClaw will automatically reindex when it detects the model change.
If you want to use a **custom OpenAI-compatible endpoint** (OpenRouter, vLLM, or a proxy),
you can use the `remote` configuration with the OpenAI provider: