Repository navigation
Go: implement Encode (embeddings) in LM Studio driver - #14694
Conversation
The LM Studio Go driver shipped with a stub Encode method that
returned "no such method", even though LM Studio is one of the
most common local LLM runners on macOS and Windows and exposes
an OpenAI-compatible embeddings endpoint at /v1/embeddings.
Users who loaded local embedding models such as
nomic-embed-text-v1.5 or mxbai-embed-large-v1 in LM Studio
could not run an embedding call through the Go layer.
Changes:
- conf/models/lmstudio.json: add "embedding": "embeddings"
under url_suffix so the driver can build the URL from
config.
- internal/entity/models/lmstudio.go: replace the Encode stub
with a real implementation. Adds a small local response type
that matches the OpenAI-compatible shape.
How it works:
- Validate the model name. The API key is optional for local
LM Studio, so the Authorization header is only set when both
apiConfig and ApiKey are non-nil and non-empty, the same
pattern the recently merged CheckConnection PR uses.
- Resolve the region with a default fallback. Return a clear
"missing base URL" error when the user has not configured
the local access address yet.
- Use a per-call context.WithTimeout(30s) and
http.NewRequestWithContext, the same pattern the merged
Aliyun Encode and the in-flight Ollama and vLLM Encode use.
- Send {model, input: [texts]} in one request.
- Parse data[*].embedding and copy each slice into a
[][]float64 indexed by data[*].index, so the output order
matches the input order.
- Handle both float64 and float32 element types.
- Empty input returns [][]float64{} with no HTTP call.
- Length mismatch between input and result, out-of-range
index, and any missing slot all return clear errors instead
of silent zero vectors.
Closes infiniflow#14693
|
Hi @Magicbook1108, gentle ping for review. Same OpenAI-compatible /embeddings shape that the merged Aliyun Encode (#14647), in-flight Ollama Encode (#14664), and in-flight vLLM Encode (#14688) all use, scope is two files (one config, one driver), and it closes #14693. Thanks! |
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an ChangesLM Studio Embeddings Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Possibly related issues
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@pandadev66 Encode interface is updated, would you please update your implementation accordingly? please refer to #14735 |
|
Hi @JinHai-CN, thanks for the heads up. Updated in 2fc7dbd to honor embeddingConfig.Dimension following the pattern in #14735. |
|
@pandadev66 Refer to the CLI usage in #14736, would you please provide the CLI embedding test result as below? |
Hi @JinHai-CN Sharing my result |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14694 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? The LM Studio Go driver shipped with a stub \`Encode\` method that returned \`no such method\`, even though LM Studio is one of the most common local LLM runners on macOS and Windows and exposes an OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`. LM Studio users routinely load local embedding models such as \`nomic-ai/nomic-embed-text-v1.5\`, \`mixedbread-ai/mxbai-embed-large-v1\`, or \`BAAI/bge-m3\`. They run on the same \`/v1\` namespace as chat. The existing \`ListModels\` already discovers them, but because \`Encode\` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call. This finishes the local-LLM trio: Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688) are already in flight, both using the same OpenAI-compatible \`/embeddings\` shape. ### What this PR includes - \`conf/models/lmstudio.json\`: add \`\"embedding\": \"embeddings\"\` under \`url_suffix\` so the driver can build the URL from config. - \`internal/entity/models/lmstudio.go\`: replace the \`Encode\` stub with a real implementation. Adds a small local response type that matches the OpenAI-compatible shape. No factory change. No interface change. ### How the driver works - Validate the model name. The API key is optional for local LM Studio, so the Authorization header is only set when both \`apiConfig\` and \`ApiKey\` are non-nil and non-empty, the same pattern the recently merged CheckConnection PR (infiniflow#14614) uses. - Resolve the region with a default fallback. Return a clear "missing base URL" error when the user has not configured the local access address yet. - Use a per-call \`context.WithTimeout(30s)\` and \`http.NewRequestWithContext\`, the same pattern the merged Aliyun Encode (infiniflow#14647) and the in-flight Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688) use. - Send \`{model, input: [texts]}\` in one request. - Parse \`data[*].embedding\` and copy each slice into a \`[][]float64\` indexed by \`data[*].index\`, so the output order matches the input order. - Handle both \`float64\` and \`float32\` element types. - Empty input returns \`[][]float64{}\` with no HTTP call. - Length mismatch between input and result, out-of-range index, and any missing slot all return clear errors instead of silent zero vectors. ### Type of change - [x] New Feature (non-breaking change which adds functionality) ### How was this tested? - \`go build ./internal/entity/models/...\` in a clean go 1.25 image returns exit 0. - The full method set on \`LmStudioModel\` still matches the \`ModelDriver\` interface. - Pattern parity with the merged Aliyun Encode (infiniflow#14647), the in-flight Ollama Encode (infiniflow#14664) and vLLM Encode (infiniflow#14688), and the existing SiliconFlow Encode. Closes infiniflow#14693
What problem does this PR solve?
The LM Studio Go driver shipped with a stub `Encode` method that returned `no such method`, even though LM Studio is one of the most common local LLM runners on macOS and Windows and exposes an OpenAI-compatible embeddings endpoint at `/v1/embeddings`.
LM Studio users routinely load local embedding models such as `nomic-ai/nomic-embed-text-v1.5`, `mixedbread-ai/mxbai-embed-large-v1`, or `BAAI/bge-m3`. They run on the same `/v1` namespace as chat. The existing `ListModels` already discovers them, but because `Encode` was a stub, a tenant who picked one of these models in the Go layer could not actually run an embedding call.
This finishes the local-LLM trio: Ollama Encode (#14664) and vLLM Encode (#14688) are already in flight, both using the
same OpenAI-compatible `/embeddings` shape.
What this PR includes
No factory change. No interface change.
How the driver works
the local access address yet.
Aliyun Encode (Go: implement Encode (embeddings) in Aliyun driver #14647) and the in-flight Ollama Encode (Go: implement Encode (embeddings) in Ollama driver #14664) and vLLM Encode (Go: implement Encode (embeddings) in vLLM driver #14688) use.
order matches the input order.
of silent zero vectors.
Type of change
How was this tested?
Closes #14693