Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/memos-local-openclaw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Add the plugin config to `~/.openclaw/openclaw.json`:
| Provider | `provider` value | Example `model` | Notes |
|---|---|---|---|
| OpenAI / compatible | `openai_compatible` | `bge-m3`, `text-embedding-3-small` | Any OpenAI-compatible API |
| Gemini | `gemini` | `text-embedding-004` | Requires `apiKey` |
| Gemini | `gemini` | `gemini-embedding-001` | Requires `apiKey` |
| Cohere | `cohere` | `embed-english-v3.0` | Separates document/query embedding |
| Voyage | `voyage` | `voyage-2` | |
| Mistral | `mistral` | `mistral-embed` | |
Expand Down
7 changes: 5 additions & 2 deletions apps/memos-local-openclaw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { Type } from "@sinclair/typebox";
import * as fs from "fs";
import * as path from "path";
import { fileURLToPath } from "url";
import { buildContext } from "./src/config";
import { SqliteStore } from "./src/storage/sqlite";
import { Embedder } from "./src/embedding";
Expand Down Expand Up @@ -76,13 +77,15 @@ const memosLocalPlugin = {

register(api: OpenClawPluginApi) {
// ─── Ensure better-sqlite3 native module is available ───
const pluginDir = path.dirname(new URL(import.meta.url).pathname);
const pluginDir = path.dirname(fileURLToPath(import.meta.url));
let sqliteReady = false;

function trySqliteLoad(): boolean {
try {
const resolved = require.resolve("better-sqlite3", { paths: [pluginDir] });
if (!resolved.startsWith(pluginDir)) {
const normalizedResolved = path.normalize(resolved).toLowerCase();
const normalizedPluginDir = path.normalize(pluginDir).toLowerCase();
if (!normalizedResolved.startsWith(normalizedPluginDir)) {
api.logger.warn(`memos-local: better-sqlite3 resolved outside plugin dir: ${resolved}`);
return false;
}
Expand Down
19 changes: 15 additions & 4 deletions apps/memos-local-openclaw/src/embedding/providers/gemini.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import type { EmbeddingConfig, Logger } from "../../types";

function normalizeGeminiEmbeddingEndpoint(endpoint: string, model: string): string {
let out = endpoint.trim();
if (!out) {
return `https://generativelanguage.googleapis.com/v1beta/models/${model}:batchEmbedContents`;
}
out = out.replace('/v1/models/', '/v1beta/models/');
out = out.replace(/:embedContent\b/, ':batchEmbedContents');
return out;
}

export async function embedGemini(
texts: string[],
cfg: EmbeddingConfig,
log: Logger,
): Promise<number[][]> {
const model = cfg.model ?? "text-embedding-004";
const endpoint =
cfg.endpoint ??
`https://generativelanguage.googleapis.com/v1beta/models/${model}:batchEmbedContents`;
const model = cfg.model ?? "gemini-embedding-001";
const endpoint = normalizeGeminiEmbeddingEndpoint(
cfg.endpoint ?? `https://generativelanguage.googleapis.com/v1beta/models/${model}:batchEmbedContents`,
model,
);

const headers: Record<string, string> = {
"Content-Type": "application/json",
Expand Down