From 5b2a0d8fbb72f76a0f065f9179772a425bd36432 Mon Sep 17 00:00:00 2001 From: sonimwang <17816198144@163.com> Date: Fri, 5 Jun 2026 12:34:45 +0800 Subject: [PATCH 1/3] docs(cn): translate remaining English text in dream.md --- docs/cn/open_source/modules/dream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cn/open_source/modules/dream.md b/docs/cn/open_source/modules/dream.md index a83beab42..55cd9e2cf 100644 --- a/docs/cn/open_source/modules/dream.md +++ b/docs/cn/open_source/modules/dream.md @@ -79,7 +79,7 @@ Dream 模拟这一点:从*未完成的内在动机*出发,而不是从原始 ```json { "motive_id": "motive:dream_memory_strategy_alignment", - "description": "Several conversations failed for the same hidden reason: weekly reporting, future planning, and filter design were treated as separate tasks, while the user needed a shared strategic narrative.", + "description": "几次对话失败,背后是同一个隐藏原因:周报、未来规划和 filter 设计被当成三个独立任务,而用户需要的是一条统一的战略叙事。", "memory_ids": ["weekly_report_thread", "future_planning_thread", "filter_design_thread"] } ``` From cc0fb714ef7fea53955973f7f04f8ffb659c5b76 Mon Sep 17 00:00:00 2001 From: harvey_xiang Date: Tue, 7 Jul 2026 17:17:16 +0800 Subject: [PATCH 2/3] chore: update github workflow stale.yaml --- .github/workflows/stale.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index b398497de..27b330aa9 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -20,8 +20,8 @@ jobs: close-pr-message: 'This PR has been automatically closed due to inactivity.' days-before-stale: 30 # Days of inactivity before marking as stale days-before-close: 7 # Days of inactivity before closing stale issues/PRs - stale-issue-label: 'stale' - stale-pr-label: 'stale' - exempt-issue-labels: 'do not close' - exempt-pr-labels: 'do not close' + stale-issue-label: 'status:stale' + stale-pr-label: 'status:stale' + exempt-issue-labels: 'status:do not close' + exempt-pr-labels: 'status:do not close' remove-stale-when-updated: true From 257b2be801ec76304136b67b41998a7d501a530f Mon Sep 17 00:00:00 2001 From: Ziyang Guo <121015044+RerankerGuo@users.noreply.github.com> Date: Thu, 2 Jul 2026 05:52:42 +0800 Subject: [PATCH 3/3] feat: route embedding input types by usage --- .../src/embedding/index.ts | 23 +++++-- .../src/embedding/providers/openai.ts | 7 +- apps/memos-local-openclaw/src/openclaw-api.ts | 7 +- apps/memos-local-openclaw/src/types.ts | 16 ++++- .../memos-local-openclaw/src/viewer/server.ts | 24 ++++++- .../tests/embedding-input-type.test.ts | 69 +++++++++++++++++++ 6 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 apps/memos-local-openclaw/tests/embedding-input-type.test.ts diff --git a/apps/memos-local-openclaw/src/embedding/index.ts b/apps/memos-local-openclaw/src/embedding/index.ts index 0a5e88067..712fef9d2 100644 --- a/apps/memos-local-openclaw/src/embedding/index.ts +++ b/apps/memos-local-openclaw/src/embedding/index.ts @@ -7,6 +7,8 @@ import { embedMistral } from "./providers/mistral"; import { embedLocal } from "./local"; import { modelHealth } from "../ingest/providers"; +type EmbeddingInputKind = "document" | "query"; + export class Embedder { constructor( private cfg: EmbeddingConfig | undefined, @@ -57,13 +59,17 @@ export class Embedder { if (this.provider === "cohere" && this.cfg) { return embedCohereQuery(text, this.cfg, this.log); } - const vecs = await this.embedBatch([text]); + const vecs = await this.embedBatch([text], "query"); return vecs[0]; } - private async embedBatch(texts: string[]): Promise { + private async embedBatch( + texts: string[], + inputKind: EmbeddingInputKind = "document", + ): Promise { const provider = this.provider; const cfg = this.cfg; + const inputType = this.resolveInputType(inputKind); const modelInfo = `${provider}/${cfg?.model ?? "default"}`; try { @@ -75,7 +81,9 @@ export class Embedder { case "zhipu": case "siliconflow": case "bailian": - result = await embedOpenAI(texts, cfg!, this.log); break; + result = await embedOpenAI(texts, cfg!, this.log, inputType); break; + case "openclaw": + result = await this.embedOpenClaw(texts, inputType); break; case "gemini": result = await embedGemini(texts, cfg!, this.log); break; case "cohere": @@ -100,7 +108,13 @@ export class Embedder { } } - private async embedOpenClaw(texts: string[]): Promise { + private resolveInputType(inputKind: EmbeddingInputKind): string | undefined { + if (!this.cfg) return undefined; + if (inputKind === "query") return this.cfg.queryInputType ?? this.cfg.inputType; + return this.cfg.documentInputType ?? this.cfg.inputType; + } + + private async embedOpenClaw(texts: string[], inputType?: string): Promise { if (!this.openclawAPI) { throw new Error( "OpenClaw API not available. Ensure sharing.capabilities.hostEmbedding is enabled in config." @@ -111,6 +125,7 @@ export class Embedder { const response = await this.openclawAPI.embed({ texts, model: this.cfg?.model, + inputType, }); return response.embeddings; diff --git a/apps/memos-local-openclaw/src/embedding/providers/openai.ts b/apps/memos-local-openclaw/src/embedding/providers/openai.ts index a5a74fbb5..5724abede 100644 --- a/apps/memos-local-openclaw/src/embedding/providers/openai.ts +++ b/apps/memos-local-openclaw/src/embedding/providers/openai.ts @@ -4,6 +4,7 @@ export async function embedOpenAI( texts: string[], cfg: EmbeddingConfig, log: Logger, + inputType?: string, ): Promise { const endpoint = normalizeEmbeddingEndpoint(cfg.endpoint ?? "https://api.openai.com/v1/embeddings"); const model = cfg.model ?? "text-embedding-3-small"; @@ -16,7 +17,11 @@ export async function embedOpenAI( const resp = await fetch(endpoint, { method: "POST", headers, - body: JSON.stringify({ input: texts, model }), + body: JSON.stringify({ + input: texts, + model, + ...(inputType ? { input_type: inputType } : {}), + }), signal: AbortSignal.timeout(cfg.timeoutMs ?? 30_000), }); diff --git a/apps/memos-local-openclaw/src/openclaw-api.ts b/apps/memos-local-openclaw/src/openclaw-api.ts index fb3a101c9..c4c0e11d3 100644 --- a/apps/memos-local-openclaw/src/openclaw-api.ts +++ b/apps/memos-local-openclaw/src/openclaw-api.ts @@ -12,6 +12,7 @@ import type { Logger, OpenClawAPI } from "./types"; export interface OpenClawEmbedRequest { texts: string[]; model?: string; + inputType?: string; } export interface OpenClawEmbedResponse { @@ -98,7 +99,11 @@ export class OpenClawAPIClient implements OpenClawAPI { const resp = await fetch(endpoint, { method: "POST", headers: buildHeaders(provider), - body: JSON.stringify({ input: request.texts, model }), + body: JSON.stringify({ + input: request.texts, + model, + ...(request.inputType ? { input_type: request.inputType } : {}), + }), signal: AbortSignal.timeout(30_000), }); diff --git a/apps/memos-local-openclaw/src/types.ts b/apps/memos-local-openclaw/src/types.ts index a3e79c0ed..c7b847ff1 100644 --- a/apps/memos-local-openclaw/src/types.ts +++ b/apps/memos-local-openclaw/src/types.ts @@ -189,6 +189,9 @@ export interface EmbeddingConfig extends ProviderConfig { batchSize?: number; dimensions?: number; retry?: number; + inputType?: string; + queryInputType?: string; + documentInputType?: string; } // ─── Skill ─── @@ -419,8 +422,17 @@ export interface PluginContext { } export interface OpenClawAPI { - embed(request: { texts: string[]; model?: string }): Promise<{ embeddings: number[][]; dimensions: number }>; - complete(request: { prompt: string; maxTokens?: number; temperature?: number; model?: string }): Promise<{ text: string }>; + embed(request: { + texts: string[]; + model?: string; + inputType?: string; + }): Promise<{ embeddings: number[][]; dimensions: number }>; + complete(request: { + prompt: string; + maxTokens?: number; + temperature?: number; + model?: string; + }): Promise<{ text: string }>; } export interface Logger { diff --git a/apps/memos-local-openclaw/src/viewer/server.ts b/apps/memos-local-openclaw/src/viewer/server.ts index e3474cc70..67a5f372b 100644 --- a/apps/memos-local-openclaw/src/viewer/server.ts +++ b/apps/memos-local-openclaw/src/viewer/server.ts @@ -3892,14 +3892,34 @@ export class ViewerServer { } return vec.length; } - const resp = await fetch(embUrl, { + const requestBody = { input: ["test embedding vector"], model: model || "text-embedding-3-small" }; + let resp = await fetch(embUrl, { method: "POST", headers, - body: JSON.stringify({ input: ["test embedding vector"], model: model || "text-embedding-3-small" }), + body: JSON.stringify(requestBody), signal: AbortSignal.timeout(15_000), }); if (!resp.ok) { const txt = await resp.text(); + if (/input[_ -]?type/i.test(txt) && /required/i.test(txt)) { + resp = await fetch(embUrl, { + method: "POST", + headers, + body: JSON.stringify({ ...requestBody, input_type: "query" }), + signal: AbortSignal.timeout(15_000), + }); + if (resp.ok) { + const json = await resp.json() as any; + const data = json?.data; + const vec = Array.isArray(data) && data.length > 0 ? data[0]?.embedding : undefined; + if (!Array.isArray(vec) || vec.length === 0) { + throw new Error( + `API returned empty embedding vector (got ${JSON.stringify(vec)?.slice(0, 100)})`, + ); + } + return vec.length; + } + } throw new Error(`${resp.status}: ${txt}`); } const json = await resp.json() as any; diff --git a/apps/memos-local-openclaw/tests/embedding-input-type.test.ts b/apps/memos-local-openclaw/tests/embedding-input-type.test.ts new file mode 100644 index 000000000..2993c577c --- /dev/null +++ b/apps/memos-local-openclaw/tests/embedding-input-type.test.ts @@ -0,0 +1,69 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; + +import { Embedder } from "../src/embedding"; +import type { EmbeddingConfig, Logger } from "../src/types"; + +const noopLog: Logger = { + debug: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, +}; + +function mockEmbeddingFetch() { + const bodies: Array> = []; + const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => { + bodies.push(JSON.parse(String(init?.body))); + return { + ok: true, + json: async () => ({ data: [{ embedding: [0.1, 0.2, 0.3] }] }), + } as Response; + }); + vi.stubGlobal("fetch", fetchMock); + return bodies; +} + +function openAiConfig(overrides: Partial = {}): EmbeddingConfig { + return { + provider: "openai_compatible", + endpoint: "https://embeddings.example.test/v1", + apiKey: "test-key", + model: "asymmetric-model", + ...overrides, + }; +} + +afterEach(() => { + vi.unstubAllGlobals(); +}); + +describe("embedding input_type routing", () => { + it("uses documentInputType for document embeddings and queryInputType for query embeddings", async () => { + const bodies = mockEmbeddingFetch(); + const embedder = new Embedder( + openAiConfig({ + inputType: "passage", + documentInputType: "document", + queryInputType: "query", + }), + noopLog, + ); + + await embedder.embed(["stored memory"]); + await embedder.embedQuery("search terms"); + + expect(bodies[0]).toMatchObject({ input_type: "document" }); + expect(bodies[1]).toMatchObject({ input_type: "query" }); + }); + + it("falls back to inputType when a specific query or document input type is absent", async () => { + const bodies = mockEmbeddingFetch(); + const embedder = new Embedder(openAiConfig({ inputType: "passage" }), noopLog); + + await embedder.embed(["stored memory"]); + await embedder.embedQuery("search terms"); + + expect(bodies[0]).toMatchObject({ input_type: "passage" }); + expect(bodies[1]).toMatchObject({ input_type: "passage" }); + }); +});