惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Last Week in AI
Last Week in AI
月光博客
月光博客
D
DataBreaches.Net
WordPress大学
WordPress大学
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
Recent Announcements
Recent Announcements
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
C
Check Point Blog
F
Fortinet All Blogs
B
Blog
小众软件
小众软件
Vercel News
Vercel News
罗磊的独立博客
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
feat(memory): support asymmetric embedding input types · ...
steipete · 2026-04-27 · via Recent Commits to openclaw:main

@@ -1,5 +1,5 @@

11

import {

2-

createRemoteEmbeddingProvider,

2+

fetchRemoteEmbeddingVectors,

33

resolveRemoteEmbeddingClient,

44

type MemoryEmbeddingProvider,

55

type MemoryEmbeddingProviderCreateOptions,

@@ -13,6 +13,9 @@ export type OpenAiEmbeddingClient = {

1313

ssrfPolicy?: SsrFPolicy;

1414

fetchImpl?: typeof fetch;

1515

model: string;

16+

inputType?: string;

17+

queryInputType?: string;

18+

documentInputType?: string;

1619

};

17201821

const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";

@@ -35,25 +38,63 @@ export async function createOpenAiEmbeddingProvider(

3538

options: MemoryEmbeddingProviderCreateOptions,

3639

): Promise<{ provider: MemoryEmbeddingProvider; client: OpenAiEmbeddingClient }> {

3740

const client = await resolveOpenAiEmbeddingClient(options);

41+

const url = `${client.baseUrl.replace(/\/$/, "")}/embeddings`;

42+43+

const resolveInputType = (kind: "query" | "document"): string | undefined => {

44+

const explicit = kind === "query" ? client.queryInputType : client.documentInputType;

45+

const value = explicit ?? client.inputType;

46+

return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;

47+

};

48+49+

const embed = async (input: string[], kind: "query" | "document"): Promise<number[][]> => {

50+

if (input.length === 0) {

51+

return [];

52+

}

53+

const inputType = resolveInputType(kind);

54+

return await fetchRemoteEmbeddingVectors({

55+

url,

56+

headers: client.headers,

57+

ssrfPolicy: client.ssrfPolicy,

58+

fetchImpl: client.fetchImpl,

59+

body: {

60+

model: client.model,

61+

input,

62+

...(inputType ? { input_type: inputType } : {}),

63+

},

64+

errorPrefix: "openai embeddings failed",

65+

});

66+

};

38673968

return {

40-

provider: createRemoteEmbeddingProvider({

69+

provider: {

4170

id: "openai",

42-

client,

43-

errorPrefix: "openai embeddings failed",

44-

maxInputTokens: OPENAI_MAX_INPUT_TOKENS[client.model],

45-

}),

71+

model: client.model,

72+

...(typeof OPENAI_MAX_INPUT_TOKENS[client.model] === "number"

73+

? { maxInputTokens: OPENAI_MAX_INPUT_TOKENS[client.model] }

74+

: {}),

75+

embedQuery: async (text) => {

76+

const [vec] = await embed([text], "query");

77+

return vec ?? [];

78+

},

79+

embedBatch: async (texts) => await embed(texts, "document"),

80+

},

4681

client,

4782

};

4883

}

49845085

export async function resolveOpenAiEmbeddingClient(

5186

options: MemoryEmbeddingProviderCreateOptions,

5287

): Promise<OpenAiEmbeddingClient> {

53-

return await resolveRemoteEmbeddingClient({

88+

const client = await resolveRemoteEmbeddingClient({

5489

provider: "openai",

5590

options,

5691

defaultBaseUrl: DEFAULT_OPENAI_BASE_URL,

5792

normalizeModel: normalizeOpenAiModel,

5893

});

94+

return {

95+

...client,

96+

inputType: options.inputType,

97+

queryInputType: options.queryInputType,

98+

documentInputType: options.documentInputType,

99+

};

59100

}