Skip to content

fix(embedding): correct MiniMax (MiniMax CodePlan) adapter - #66

Merged
adoresever merged 1 commit into
adoresever:mainfrom
ulnacranium17:fix/minimax-embedding-adapter
Aug 1, 2026
Merged

fix(embedding): correct MiniMax (MiniMax CodePlan) adapter#66
adoresever merged 1 commit into
adoresever:mainfrom
ulnacranium17:fix/minimax-embedding-adapter

Conversation

@ulnacranium17

Copy link
Copy Markdown
Contributor

Summary

Fix the embedding adapter so that users running the MiniMax CodePlan OAuth service (the platform referred to as "MiniMax" in the README — the alias predates this PR and is left intact for backward compatibility) can actually use it.

What's wrong today

  • README documents baseURL=https://api.minimax.chat/v1 and dimensions=1024 for MiniMax. The reachable endpoint is https://api.minimaxi.com/v1 and embo-01 returns 1536-d vectors.
  • Even with the right URL, the adapter sends {"input": "..."} and reads data[0].embedding. MiniMax's /embeddings expects {"texts": [...], "type": "db"|"query"} and returns data[0].vector. So every call fails with missing required parameter expr_path=texts or returns an empty embedding.

What this PR changes

  • src/engine/embed.ts
    • Adds isMinimax(baseURL) detection (matches minimaxi.com, minimax.chat, minimax.io).
    • When detected, sends {model, texts:[input], type} instead of {model, input}, and omits dimensions (MiniMax rejects it).
    • Reads data[0].vector for MiniMax, data[0].embedding for everything else.
    • Extends EmbedFn to (text: string, mode?: "db" | "query") => Promise<number[]>. MiniMax routes the two modes through different retrieval models, so callers need to be explicit.
  • src/recaller/recall.tsrecallPrecise / recallGeneralized pass "query", syncEmbed passes "db".
  • src/graph/community.ts — community summarization passes "db".
  • README.md / README_CN.md
    • Provider table row corrected: baseURL=api.minimaxi.com, dimensions=1536, label clarified as MiniMax (MiniMax CodePlan).
    • Universal-embedding bullets now note the MiniMax format exception.

Backward compatibility

  • Other providers (OpenAI, DashScope, Jina, Ollama, llama.cpp, etc.) are unchanged: same request body shape, same data[0].embedding parsing, same dimensions handling. Their existing embeddings keep working.
  • The mode argument on EmbedFn is optional and defaults to "db", so any external code that constructs a custom EmbedFn keeps compiling.

Verification

  • Local: TS compiles, the four EmbedFn call sites all pass the new mode (verified by grepping for this.embed( / embedFn().
  • Runtime: I run graph-memory against the actual MiniMax CodePlan service (oauth-cn endpoint, api.minimaxi.com). Before the patch the embed probe fails with missing required parameter expr_path=texts; after the patch recall reports vector search ready and 1536-d vectors are stored and used for vector search + community summaries.

Notes for the maintainer

  • The "MiniMax" string in the existing README/code was a pre-existing alias. I kept it everywhere for diff minimality, but expanded the README label to MiniMax (MiniMax CodePlan) so the official product name is now discoverable from the docs. Happy to rename wholesale in a follow-up if you'd prefer.
  • Test suite wasn't run inside this PR — WSL/3 GB memory kills vitest run. The change is small (one new function plus a branch in buildBody) and the four call-site updates are mechanical, but I can add a unit test for createEmbedFn if you want.

The MiniMax row in README claimed baseURL=api.minimax.chat and 1024
dimensions, but the platform (called MiniMax here for legacy reasons;
real product is MiniMax CodePlan) actually serves embeddings from
api.minimaxi.com and returns 1536d vectors.

This change:
- Adds isMinimax(baseURL) detection and a MiniMax-specific request body
  branch in createEmbedFn. MiniMax uses {texts:[...], type:"db"|"query"}
  instead of OpenAI's {input:...}, returns data[0].vector instead of
  data[0].embedding, and does not accept a dimensions field.
- Extends EmbedFn with an optional second 'mode' arg
  ("db" | "query") so recall callers can pass "query" while syncEmbed
  and community summarization pass "db", matching MiniMax's separate
  retrieval models.
- Updates all 4 call sites in src/recaller/recall.ts and
  src/graph/community.ts to pass the appropriate mode.
- Corrects README.md / README_CN.md provider table
  (baseURL, dimensions) and Universal embedding bullets to reflect the
  real MiniMax embedding format.

Other OpenAI-compatible providers (OpenAI, DashScope, Jina, Ollama,
llama.cpp) are unaffected; their request body and response parsing
paths are unchanged.
Copilot AI review requested due to automatic review settings July 25, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the embedding adapter so MiniMax (MiniMax CodePlan) works correctly by using the provider-specific /embeddings request/response shape and by distinguishing between “db” vs “query” embedding modes, while keeping other OpenAI-compatible providers’ behavior unchanged.

Changes:

  • Updated createEmbedFn to detect MiniMax endpoints and switch to { texts: [...], type } request bodies plus data[0].vector parsing, and extended EmbedFn to accept an optional "db" | "query" mode.
  • Updated recall and community summarization call sites to pass "query" for search-time embeddings and "db" for stored vectors.
  • Updated README/README_CN provider docs (MiniMax baseURL + dimensions + format exception note).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/engine/embed.ts Adds MiniMax detection + request/response branching and introduces EmbedMode in the embedding function signature.
src/recaller/recall.ts Passes "query" for recall searches and "db" for background embedding sync.
src/graph/community.ts Uses "db" mode when generating/storing community summary embeddings.
README.md Corrects MiniMax provider docs (baseURL/dimensions) and documents the non-OpenAI request shape.
README_CN.md Same as README.md, for Chinese documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/engine/embed.ts
Comment on lines +58 to +60
function isMinimax(baseURL: string): boolean {
return /minimaxi\.com|minimax\.chat|minimax\.io/i.test(baseURL);
}
Comment thread src/engine/embed.ts
Comment on lines +14 to +17
* 兼容 OpenAI、阿里云 DashScope、MiniMax(MiniMax CodePlan)、Jina、Ollama、llama.cpp 等。
*
* MiniMax(MiniMax) 是特例:
* - 端点走 anthropic 协议但 embeddings 用 OpenAI 风格变体
@TriDefender

Copy link
Copy Markdown
Contributor

你好,这个repo似乎不再被维护,可以向https://github.com/TriDefender/graph-memory

@adoresever
adoresever merged commit 39b515f into adoresever:main Aug 1, 2026

@adoresever adoresever left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复已采纳并合并:MiniMax CodePlan 的适配方向正确。合并时把域名判断收紧为精确主机名匹配,并补充请求/响应适配测试,避免相似域名误判。感谢贡献。

TriDefender added a commit to TriDefender/graph-memory that referenced this pull request Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants