Skip to content

fix(go): wire CheckConnection to ListModels in ollama, lm-studio, and vllm - #14614

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
pandadev66:fix/go-check-connection
May 8, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
pandadev66:fix/go-check-connection

Conversation

@pandadev66

@pandadev66 pandadev66 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Three Go drivers had CheckConnection returning a hardcoded no such method error, even though each one already has a working ListModels that hits the configured base URL with the configured API key. So the "Check connection" button in the model provider UI always failed for these three providers, even when the underlying setup was fine.

Affected drivers:

  • internal/entity/models/ollama.go
  • internal/entity/models/lmstudio.go
  • internal/entity/models/vllm.go

This is a real user-facing gap because Ollama and LM Studio are two of the most popular local LLM runners, and vLLM is widely used for self-hosted deployments.

What this PR includes

For each of the three drivers, replace the stub with a small implementation that calls ListModels and returns its error:

func (o *OllamaModel) CheckConnection(apiConfig *APIConfig) error {
    _, err := o.ListModels(apiConfig)
    return err
}

This is the exact pattern that xai, moonshot, deepseek, aliyun, and gitee already use for the same method.

No JSON change. No factory change. No interface change.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

How was this tested?

  • go build ./internal/entity/models/... in a clean go 1.25 image (the go.mod minimum) returns exit 0.
  • The full ModelDriver interface still resolves on each driver (NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode, Rerank, ListModels, Balance, CheckConnection).
  • Pattern parity with the existing xai, moonshot, deepseek, aliyun, and gitee CheckConnection methods.

Closes #14609

… vllm

Three Go drivers had CheckConnection returning a hardcoded
"no such method" error, even though each one already has a
working ListModels that hits the configured base URL with
the configured API key. So the "Check connection" button in
the model provider UI always failed for these three providers,
even when the underlying setup was fine.

This commit lines them up with the pattern that xai, moonshot,
deepseek, aliyun, and gitee already use: CheckConnection now
calls ListModels and returns its error. If the host is
reachable and the API key is accepted, the check succeeds.
If not, the user gets the real upstream error instead of the
generic stub message.

Scope is intentionally limited to the three driver files. No
JSON change. No factory change. No interface change.

Closes infiniflow#14609
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 7, 2026
@pandadev66

Copy link
Copy Markdown
Contributor Author

Hi @Magicbook1108, gentle ping for review. Each driver gets the same two-line wiring that xai, moonshot, deepseek, aliyun, and gitee already use, scope is three files only, and it closes #14609. Thanks!

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98836b04-415e-4c55-98d6-a4b2226b9f8a

📥 Commits

Reviewing files that changed from the base of the PR and between 7229312 and d92184b.

📒 Files selected for processing (3)
  • internal/entity/models/lmstudio.go
  • internal/entity/models/ollama.go
  • internal/entity/models/vllm.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/entity/models/ollama.go
  • internal/entity/models/vllm.go

📝 Walkthrough

Walkthrough

Implements real CheckConnection for Ollama, LM Studio, and vLLM by calling their ListModels implementations and hardens ListModels to defensively resolve region and base URL with a fallback to the provider's default base URL; errors are wrapped as "connection check failed" or a clear "missing base URL" message.

Changes

Connection Check Implementation

Layer / File(s) Summary
LmStudio: List & Connection
internal/entity/models/lmstudio.go
ListModels guards apiConfig/Region, resolves baseURL with fallback to BaseURL["default"], and returns missing base URL when unset; CheckConnection resolves baseURL and calls ListModels, wrapping errors as connection check failed.
Ollama: List & Connection
internal/entity/models/ollama.go
ListModels applies apiConfig/Region guards, resolves baseURL with fallback to o.BaseURL["default"], and constructs the models URL from the resolved base; CheckConnection resolves baseURL and calls ListModels, wrapping failures.
vLLM: List & Connection
internal/entity/models/vllm.go
ListModels tolerates nil/empty apiConfig.Region, falls back to BaseURL["default"] when needed, and errors clearly when no base URL is configured; CheckConnection mirrors resolution and calls ListModels, wrapping errors.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through drivers, fixed the gap,
Where "no such method" used to nap.
ListModels calls now pass the test,
Connections checked, the rabbit's best.
Ollama, LM Studio, vLLM clap—hurrah!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: wiring CheckConnection to ListModels in three drivers (ollama, lm-studio, vllm).
Description check ✅ Passed The PR description fully follows the template with a clear problem statement, lists affected files, explains the solution, specifies the change type as bug fix, and documents testing approach.
Linked Issues check ✅ Passed The code changes directly address all objectives from issue #14609: CheckConnection is wired to call ListModels in all three drivers, following the pattern established by other drivers, with no breaking changes.
Out of Scope Changes check ✅ Passed All changes are scoped to the three targeted driver files (ollama.go, lmstudio.go, vllm.go) with modifications limited to CheckConnection and ListModels defensive programming for region/base-URL resolution and Authorization header handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Haruko386 Haruko386 added the ci Continue Integration label May 7, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft May 7, 2026 06:18
@JinHai-CN
JinHai-CN marked this pull request as ready for review May 7, 2026 06:19
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label May 7, 2026
@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (12f80f1) to head (d92184b).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14614   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @pandadev66 , thanks for your PR!

The idea of reusing ListModels inside CheckConnection to avoid code duplication is great and definitely the right direction. However, I have to request some changes before we can merge this, as it introduces a bad UX edge case for local models.

The Issue:
For local providers like lmstudio, there is no default cloud URL in the json config. If a user tries to check instance without properly configuring the instance's BaseURL first, ListModels will attempt to build the URL with an empty string. This results in the HTTP client throwing a very confusing and low-level error:
Get "/models": unsupported protocol scheme ""

This error is misleading for users who simply forgot to input their local IP.

Suggested Fix:
We need to add a defensive check for empty URLs before attempting the HTTP request (or before calling ListModels), so we can throw a human-readable, actionable error instead.

Could you please update the implementation to something like this?

func (l *LmStudioModel) CheckConnection(apiConfig *APIConfig) error {
	var region = "default"
	if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" {
		region = *apiConfig.Region
	}

	baseURL := l.BaseURL[region]
	if baseURL == "" {
		baseURL = l.BaseURL["default"]
	}

	// Defensive check for local models
	if baseURL == "" {
		return fmt.Errorf("missing base URL: please configure the local access address for LM Studio (e.g., http://127.0.0.1:1234/v1)")
	}

	_, err := l.ListModels(apiConfig)
	if err != nil {
		return fmt.Errorf("connection check failed: %w", err)
	}

	return nil
}

(Also, it would be even better if this empty URL check is applied inside ListModels as well.)

Once this safeguard is added, I'll be happy to approve! Let me know if you have any questions.


pandadev66 pushed a commit to pandadev66/ragflow that referenced this pull request May 7, 2026
…ocal providers

Address review note from @Haruko386 on PR infiniflow#14614.

For local providers (ollama, lm-studio, vllm), there is no cloud
default URL in the json config. If a user clicks "Check connection"
or runs ListModels before configuring the local access address,
the previous code passed an empty string into fmt.Sprintf and let
the HTTP client fail with a low-level message such as
'Get "/models": unsupported protocol scheme ""'. That is confusing
for someone who simply forgot to enter their local IP.

This commit adds a small defensive check at the top of both
CheckConnection and ListModels in all three drivers. The check
resolves the region (defaulting to "default" when missing or
empty), looks up the base URL with a "default" fallback, and
returns a clear, actionable error if it is still empty:

  missing base URL: please configure the local access address
  for <Provider> (e.g., http://127.0.0.1:<port>/v1)

The example URLs are provider-specific so the user can copy and
adjust them:

  - Ollama:    http://127.0.0.1:11434/v1
  - LM Studio: http://127.0.0.1:1234/v1
  - vLLM:      http://127.0.0.1:8000/v1

CheckConnection still calls ListModels for the actual probe.
Errors from ListModels are now wrapped with a "connection check
failed: ..." prefix so the user can tell that the failure came
from the connection check path rather than a normal model list
fetch.

No interface change. No json change. Only the three driver files
are touched.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 7, 2026
@pandadev66

pandadev66 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386, thanks for the careful review. Pushed commit with the changes you suggested. Please take another look when you have time.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/ollama.go`:
- Around line 364-366: The code dereferences apiConfig.ApiKey without guarding
for apiConfig==nil (notably in ListModels and CheckConnection); update those
functions (e.g., ListModels, CheckConnection and the other spots referenced near
the blocks at lines 364-366 / 436-438 / 448-450) to nil-check apiConfig before
accessing ApiKey or Region and return a clear error (or use a safe default)
instead of allowing a panic; ensure every path that reads *apiConfig.ApiKey
first validates apiConfig != nil and handle the nil case consistently by
returning an error from the calling function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a9ae672-0dfe-4730-9632-c1d85a1cf47f

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1a40b and 2b1a806.

📒 Files selected for processing (3)
  • internal/entity/models/lmstudio.go
  • internal/entity/models/ollama.go
  • internal/entity/models/vllm.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/entity/models/vllm.go
  • internal/entity/models/lmstudio.go

Comment thread internal/entity/models/ollama.go Resolved
…ocal providers

Address review note from @Haruko386 on PR infiniflow#14614.

For local providers (ollama, lm-studio, vllm), there is no cloud
default URL in the json config. If a user clicks "Check connection"
or runs ListModels before configuring the local access address,
the previous code passed an empty string into fmt.Sprintf and let
the HTTP client fail with a low-level message such as
'Get "/models": unsupported protocol scheme ""'. That is confusing
for someone who simply forgot to enter their local IP.

This commit adds a small defensive check at the top of both
CheckConnection and ListModels in all three drivers. The check
resolves the region (defaulting to "default" when missing or
empty), looks up the base URL with a "default" fallback, and
returns a clear, actionable error if it is still empty:

  missing base URL: please configure the local access address
  for <Provider> (e.g., http://127.0.0.1:<port>/v1)

The example URLs are provider-specific so the user can copy and
adjust them:

  - Ollama:    http://127.0.0.1:11434/v1
  - LM Studio: http://127.0.0.1:1234/v1
  - vLLM:      http://127.0.0.1:8000/v1

CheckConnection still calls ListModels for the actual probe.
Errors from ListModels are now wrapped with a "connection check
failed: ..." prefix so the user can tell that the failure came
from the connection check path rather than a normal model list
fetch.

No interface change. No json change. Only the three driver files
are touched.
@pandadev66
pandadev66 force-pushed the fix/go-check-connection branch from 2b1a806 to 7229312 Compare May 7, 2026 07:58

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/entity/models/lmstudio.go (1)

437-453: 💤 Low value

CheckConnection duplicates the URL-resolution block that ListModels already performs

Lines 437–448 copy the region → baseURL fallback → empty-URL guard verbatim from ListModels (lines 365–376). The only observable difference is that the missing-URL error is returned unwrapped here versus wrapped as "connection check failed: missing base URL: ..." when the check falls through to ListModels. The wrapper is actually more informative in the connection-check context, so the pre-check doesn't add user-visible value and doubles the maintenance surface.

♻️ Proposed simplification
 func (l *LmStudioModel) CheckConnection(apiConfig *APIConfig) error {
-	var region = "default"
-	if apiConfig != nil && apiConfig.Region != nil && *apiConfig.Region != "" {
-		region = *apiConfig.Region
-	}
-
-	baseURL := l.BaseURL[region]
-	if baseURL == "" {
-		baseURL = l.BaseURL["default"]
-	}
-	if baseURL == "" {
-		return fmt.Errorf("missing base URL: please configure the local access address for LM Studio (e.g., http://127.0.0.1:1234/v1)")
-	}
-
 	if _, err := l.ListModels(apiConfig); err != nil {
 		return fmt.Errorf("connection check failed: %w", err)
 	}
 	return nil
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/entity/models/lmstudio.go` around lines 437 - 453, Remove the
duplicated region→baseURL resolution and empty-URL guard from CheckConnection
and instead rely on ListModels for URL validation/lookup; specifically, delete
the block that declares region, reads l.BaseURL[region], falls back to
"default", and returns the missing-URL error, and simply call
l.ListModels(apiConfig) (as already done) so CheckConnection uses ListModels'
error wrapping/behavior; touch functions CheckConnection and ListModels and the
references to baseURL/region/l.BaseURL to ensure no orphaned variables remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/lmstudio.go`:
- Around line 366-376: The code dereferences apiConfig and apiConfig.ApiKey
without safe checks; update the LM Studio client initialization and
CheckConnection logic to first verify apiConfig != nil and apiConfig.ApiKey !=
nil before reading *apiConfig.ApiKey (and treat empty string as no key), e.g.,
only set the local apiKey variable when both pointers are non-nil and non-empty
and otherwise leave it empty or use the existing fallback; apply identical nil
checks in the CheckConnection method (and any other place that reads
apiConfig.ApiKey) to avoid nil-pointer panics.

---

Nitpick comments:
In `@internal/entity/models/lmstudio.go`:
- Around line 437-453: Remove the duplicated region→baseURL resolution and
empty-URL guard from CheckConnection and instead rely on ListModels for URL
validation/lookup; specifically, delete the block that declares region, reads
l.BaseURL[region], falls back to "default", and returns the missing-URL error,
and simply call l.ListModels(apiConfig) (as already done) so CheckConnection
uses ListModels' error wrapping/behavior; touch functions CheckConnection and
ListModels and the references to baseURL/region/l.BaseURL to ensure no orphaned
variables remain.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f451505-8124-491f-989e-1e280b9b3520

📥 Commits

Reviewing files that changed from the base of the PR and between 2b1a806 and 7229312.

📒 Files selected for processing (3)
  • internal/entity/models/lmstudio.go
  • internal/entity/models/ollama.go
  • internal/entity/models/vllm.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/entity/models/vllm.go
  • internal/entity/models/ollama.go

Comment thread internal/entity/models/lmstudio.go Resolved
…key in ListModels

CodeRabbit flagged a remaining nil-pointer risk in ListModels for
all three local-provider drivers (ollama, lm-studio, vllm). The
empty-base-URL guard added in 7229312 nil-checks apiConfig at the
top, but later code unconditionally dereferenced *apiConfig.ApiKey
when building the Authorization header. If apiConfig was nil, or
its ApiKey field was nil, the call would panic instead of returning
a clean error.

This also addresses a UX wart for these three providers: they are
local and their API key is optional. The previous code forced an
"Authorization: Bearer <empty>" header onto every ListModels call
even when the user had no key set.

The fix in each driver wraps the Authorization header set with a
small guard:

  if apiConfig != nil && apiConfig.ApiKey != nil && *apiConfig.ApiKey != "" {
      req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey))
  }

When a key is set the header still goes out as before. When it is
not, the header is simply omitted, which is what these local APIs
expect.

CheckConnection already calls ListModels and does not dereference
ApiKey directly, so the fix in ListModels is enough to make the
connection-check path nil-safe end to end.

Scope is intentionally limited to the ListModels Authorization
site in the three driver files. Chat methods are left for a
separate change.
@pandadev66

Copy link
Copy Markdown
Contributor Author

Quick follow-up on the latest review pass: pushed commit d92184b which gates the Authorization header in ListModels behind a non-nil, non-empty API key in all three drivers. This makes the call nil-safe and also matches the fact that these are local providers where the API key is optional. The defensive URL pre-check in CheckConnection is kept as you requested, even though CodeRabbit flagged the duplication as a nitpick. Please take another look when convenient. Thanks!

@pandadev66
pandadev66 requested a review from Haruko386 May 7, 2026 08:29

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @pandadev66 , LGTM

I have reviewed the code changes, and there are no apparent issues with the code, thank you for you contribution.

However, to ensure everything works flawlessly in practice, please provide a snippet of your local test results in your future PR description or comments

@JinHai-CN
JinHai-CN merged commit 2fd8cdc into infiniflow:main May 8, 2026
1 check passed
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
… vllm (infiniflow#14614)

### What problem does this PR solve?

Three Go drivers had `CheckConnection` returning a hardcoded `no such
method` error, even though each one already has a working `ListModels`
that hits the configured base URL with the configured API key. So the
"Check connection" button in the model provider UI always failed for
these three providers, even when the underlying setup was fine.

Affected drivers:

- `internal/entity/models/ollama.go`
- `internal/entity/models/lmstudio.go`
- `internal/entity/models/vllm.go`

This is a real user-facing gap because Ollama and LM Studio are two of
the most popular local LLM runners, and vLLM is widely used for
self-hosted deployments.

### What this PR includes

For each of the three drivers, replace the stub with a small
implementation that calls `ListModels` and returns its error:

```go
func (o *OllamaModel) CheckConnection(apiConfig *APIConfig) error {
    _, err := o.ListModels(apiConfig)
    return err
}
```

This is the exact pattern that xai, moonshot, deepseek, aliyun, and
gitee already use for the same method.

No JSON change. No factory change. No interface change.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

### How was this tested?

- `go build ./internal/entity/models/...` in a clean go 1.25 image (the
go.mod minimum) returns exit 0.
- The full ModelDriver interface still resolves on each driver
(NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode,
Rerank, ListModels, Balance, CheckConnection).
- Pattern parity with the existing xai, moonshot, deepseek, aliyun, and
gitee CheckConnection methods.

Closes infiniflow#14609
JinHai-CN pushed a commit that referenced this pull request May 11, 2026
### What problem does this PR solve?

The vLLM Go driver shipped with a stub \`Encode\` method that returned
\`not implemented\`, even though vLLM is one of the most common
production-grade self-hosted inference servers and exposes an
OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`.

Users who self-host \`BAAI/bge-m3\`, \`Qwen3-Embedding-*\`,
\`NV-Embed-v2\`, or similar models on vLLM could not run an embedding
call through the Go layer. The existing \`ListModels\` already discovers
the loaded models, but the embedding path failed because \`Encode\` was
a stub.

### What this PR includes

- \`conf/models/vllm.json\`: add \`\"embedding\": \"embeddings\"\` under
\`url_suffix\` so the driver can build the URL from config.
- \`internal/entity/models/vllm.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 self-hosted vLLM,
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 (#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 (#14647) and in-flight Ollama Encode (#14664) 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 \`VllmModel\` still matches the \`ModelDriver\`
interface.
- Pattern parity with the merged Aliyun Encode (#14647), the in-flight
Ollama Encode (#14664), and the existing
  SiliconFlow Encode.

Closes #14687
JinHai-CN pushed a commit that referenced this pull request May 11, 2026
### What problem does this PR solve?

The Ollama Go driver shipped with a stub \`Encode\` method that returned
\`no such method\`, even though Ollama is one of the most common local
LLM runners and exposes an OpenAI-compatible embeddings endpoint at
\`/v1/embeddings\`.

Ollama users routinely run local embedding models such as
\`nomic-embed-text\`, \`mxbai-embed-large\`, or \`bge-m3\`.
Pulled with \`ollama pull <model>\` and served 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.

### What this PR includes

- \`conf/models/ollama.json\`: add \`\"embedding\": \"embeddings\"\`
under \`url_suffix\` so the
  driver can build the URL from config.
- \`internal/entity/models/ollama.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 Ollama, 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 (#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 (#14647) uses.
- 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 \`OllamaModel\` still matches the
\`ModelDriver\` interface.
- Pattern parity with the merged Aliyun Encode (#14647) and the existing
SiliconFlow Encode.

Closes #14662
JinHai-CN pushed a commit that referenced this pull request May 11, 2026
### 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

- \`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 (#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 (#14647) and the in-flight Ollama Encode (#14664) and vLLM
Encode (#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 (#14647), the in-flight
Ollama Encode (#14664) and vLLM Encode (#14688), and the existing
SiliconFlow Encode.

Closes #14693
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
… vllm (infiniflow#14614)

### What problem does this PR solve?

Three Go drivers had `CheckConnection` returning a hardcoded `no such
method` error, even though each one already has a working `ListModels`
that hits the configured base URL with the configured API key. So the
"Check connection" button in the model provider UI always failed for
these three providers, even when the underlying setup was fine.

Affected drivers:

- `internal/entity/models/ollama.go`
- `internal/entity/models/lmstudio.go`
- `internal/entity/models/vllm.go`

This is a real user-facing gap because Ollama and LM Studio are two of
the most popular local LLM runners, and vLLM is widely used for
self-hosted deployments.

### What this PR includes

For each of the three drivers, replace the stub with a small
implementation that calls `ListModels` and returns its error:

```go
func (o *OllamaModel) CheckConnection(apiConfig *APIConfig) error {
    _, err := o.ListModels(apiConfig)
    return err
}
```

This is the exact pattern that xai, moonshot, deepseek, aliyun, and
gitee already use for the same method.

No JSON change. No factory change. No interface change.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

### How was this tested?

- `go build ./internal/entity/models/...` in a clean go 1.25 image (the
go.mod minimum) returns exit 0.
- The full ModelDriver interface still resolves on each driver
(NewInstance, Name, ChatWithMessages, ChatStreamlyWithSender, Encode,
Rerank, ListModels, Balance, CheckConnection).
- Pattern parity with the existing xai, moonshot, deepseek, aliyun, and
gitee CheckConnection methods.

Closes infiniflow#14609
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

The vLLM Go driver shipped with a stub \`Encode\` method that returned
\`not implemented\`, even though vLLM is one of the most common
production-grade self-hosted inference servers and exposes an
OpenAI-compatible embeddings endpoint at \`/v1/embeddings\`.

Users who self-host \`BAAI/bge-m3\`, \`Qwen3-Embedding-*\`,
\`NV-Embed-v2\`, or similar models on vLLM could not run an embedding
call through the Go layer. The existing \`ListModels\` already discovers
the loaded models, but the embedding path failed because \`Encode\` was
a stub.

### What this PR includes

- \`conf/models/vllm.json\`: add \`\"embedding\": \"embeddings\"\` under
\`url_suffix\` so the driver can build the URL from config.
- \`internal/entity/models/vllm.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 self-hosted vLLM,
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 in-flight Ollama Encode (infiniflow#14664) 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 \`VllmModel\` still matches the \`ModelDriver\`
interface.
- Pattern parity with the merged Aliyun Encode (infiniflow#14647), the in-flight
Ollama Encode (infiniflow#14664), and the existing
  SiliconFlow Encode.

Closes infiniflow#14687
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

The Ollama Go driver shipped with a stub \`Encode\` method that returned
\`no such method\`, even though Ollama is one of the most common local
LLM runners and exposes an OpenAI-compatible embeddings endpoint at
\`/v1/embeddings\`.

Ollama users routinely run local embedding models such as
\`nomic-embed-text\`, \`mxbai-embed-large\`, or \`bge-m3\`.
Pulled with \`ollama pull <model>\` and served 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.

### What this PR includes

- \`conf/models/ollama.json\`: add \`\"embedding\": \"embeddings\"\`
under \`url_suffix\` so the
  driver can build the URL from config.
- \`internal/entity/models/ollama.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 Ollama, 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) uses.
- 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 \`OllamaModel\` still matches the
\`ModelDriver\` interface.
- Pattern parity with the merged Aliyun Encode (infiniflow#14647) and the existing
SiliconFlow Encode.

Closes infiniflow#14662
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Go drivers ollama, lm-studio, and vllm have CheckConnection stubbed despite working ListModels

3 participants