Skip to content

Go: implement Encode (embeddings) in Gitee AI driver - #14698

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-gitee-encode
May 11, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-gitee-encode

Conversation

@Crystora

@Crystora Crystora commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The Gitee AI Go driver in internal/entity/models/gitee.go shipped with a stub Encode method that returned gitee, no such method, even though conf/models/gitee.json already wires the embedding URL suffix. The conf also listed no embedding models, so the picker had nothing to select.

This blocked any tenant who wanted to use Gitee AI for chat, rerank (already working, see #14656), and embeddings from a single provider.

This PR fills the gap, mirroring the just-merged Aliyun Encode (#14647):

  • internal/entity/models/gitee.go: replace the Encode stub with a real implementation.
    Validates inputs, resolves the region with a default fallback, POSTs the standard OpenAI-compatible {"model", "input": [...]} body to BaseURL[region] + URLSuffix.Embedding, parses data[*].embedding indexed by data[*].index so output order matches input order, handles both float64 and float32 element types, and uses a 30s per-call context deadline matching the merged Rerank.
  • conf/models/gitee.json: add BAAI/bge-m3 so the embedding picker has something to select.

No factory change. No interface change. No URL suffix change.

Verified with go build, go vet, and gofmt -l : all clean.

Closes #14697

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 8, 2026
@coderabbitai

coderabbitai Bot commented May 8, 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: abc56f22-2c53-4a9f-9f36-8250596fd891

📥 Commits

Reviewing files that changed from the base of the PR and between b60e8b7 and 6ea7a8e.

📒 Files selected for processing (2)
  • conf/models/gitee.json
  • internal/entity/models/gitee.go
✅ Files skipped from review due to trivial changes (1)
  • conf/models/gitee.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/gitee.go

📝 Walkthrough

Walkthrough

Adds a BAAI/bge-m3 embedding model to Gitee config and implements GiteeModel.Encode to POST embeddings requests, parse indexed float32/float64 responses, validate and order vectors, and return [][]float64 with a 30s timeout.

Changes

Gitee Embeddings Implementation

Layer / File(s) Summary
Type Definition
internal/entity/models/gitee.go
giteeEmbeddingResponse struct added to unmarshal embeddings API responses with indexed embedding vectors.
Model Configuration
conf/models/gitee.json
Added BAAI/bge-m3 embedding model entry with max_tokens: 8192 and model_types: ["embedding"].
Input Validation
internal/entity/models/gitee.go
Encode returns empty result for empty texts and errors on missing/empty API key or model name.
Request Preparation
internal/entity/models/gitee.go
Resolves base URL by region with default fallback; constructs embeddings endpoint URL and request payload (model, input, optional dimensions).
HTTP Execution
internal/entity/models/gitee.go
Marshals JSON, creates 30s context, sends POST with Bearer auth and JSON headers, reads response, and errors on non-200 with status/body.
Response Parsing
internal/entity/models/gitee.go
Unmarshals response; validates each data[index] against input range; converts float64/float32 elements to float64; ensures every input index has a vector.
Return
internal/entity/models/gitee.go
Returns validated and ordered [][]float64 embeddings to caller.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped through configs, code in paw,
Sent texts to Gitee, awaited the call,
Floats and indices, ordered and true,
Thirty seconds later — vectors anew,
Embeddings bloom for me and you. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The implementation addresses the core requirements from issue #14697, but PR objectives mention the Encode interface was updated in PR #14735 requiring implementation adjustments that cannot be verified from the raw summary alone. Verify that the current Encode implementation matches the updated interface requirements from PR #14735 before merging.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: implementing the Encode method for embeddings in the Gitee AI Go driver.
Description check ✅ Passed The description follows the template with a complete problem statement and properly selected type of change (New Feature), addressing all linked issue requirements.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue #14697: implementing Encode in gitee.go and adding BAAI/bge-m3 model to the configuration.
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.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@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.

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

480-503: ⚡ Quick win

Add focused table-driven tests for response parsing edge cases.

This block has the highest correctness risk surface (index ordering, type conversion, missing vectors). A small set of tests here would materially improve safety for future changes.

🤖 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/gitee.go` around lines 480 - 503, Add focused
table-driven unit tests that exercise the embedding parsing logic which builds
embeddings from parsed.Data (the code that allocates embeddings and handles
item.Index and item.Embedding). Include cases for: valid ordered inputs, valid
unordered indices, out-of-range index (negative and >= len(texts)), non-numeric
embedding values (e.g., string, nil), float32 values to ensure conversion to
float64, duplicate indices, and missing indices producing nil vectors; assert
the returned error messages or resulting embeddings match expectations for each
case. Put tests next to the existing model tests, call the parsing function/path
that constructs the embeddings slice (the code using embeddings, item.Index and
item.Embedding), and use table-driven subtests to keep them concise and
maintainable.
🤖 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.

Nitpick comments:
In `@internal/entity/models/gitee.go`:
- Around line 480-503: Add focused table-driven unit tests that exercise the
embedding parsing logic which builds embeddings from parsed.Data (the code that
allocates embeddings and handles item.Index and item.Embedding). Include cases
for: valid ordered inputs, valid unordered indices, out-of-range index (negative
and >= len(texts)), non-numeric embedding values (e.g., string, nil), float32
values to ensure conversion to float64, duplicate indices, and missing indices
producing nil vectors; assert the returned error messages or resulting
embeddings match expectations for each case. Put tests next to the existing
model tests, call the parsing function/path that constructs the embeddings slice
(the code using embeddings, item.Index and item.Embedding), and use table-driven
subtests to keep them concise and maintainable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 995ca7e0-0570-4332-971d-caa5a6f4afce

📥 Commits

Reviewing files that changed from the base of the PR and between 5e96c5c and b60e8b7.

📒 Files selected for processing (2)
  • conf/models/gitee.json
  • internal/entity/models/gitee.go

@JinHai-CN

Copy link
Copy Markdown
Member

@bittoby Encode interface is updated, would you please update your implementation accordingly? please refer to #14735

@Crystora
Crystora force-pushed the feat/go-gitee-encode branch from b60e8b7 to 6ea7a8e Compare May 9, 2026 11:41
@Crystora

Crystora commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated PR. @JinHai-CN Plz review again. Thanks

@JinHai-CN

Copy link
Copy Markdown
Member

@bittoby Refer to the CLI usage in #14736, would you please provide the CLI embedding test result as below?

RAGFlow(user)> embed text 'what is rag' 'who are you' with 'embedding-3@test@zhipu-ai' dimension 16;
+-----------+-------+
| dimension | index |
+-----------+-------+
| 16        | 0     |
| 16        | 1     |
+-----------+-------+

@Crystora

Crystora commented May 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@JinHai-CN Test is done. Result for BAAI/bge-m3:

RAGFlow(user)> embed text 'what is rag' 'who are you' with 'BAAI/bge-m3@test@gitee' dimension 16;
+-----------+-------+
| dimension | index |
+-----------+-------+
| 16        | 0     |
| 16        | 1     |
+-----------+-------+

Could you merge this PR now?

@JinHai-CN
JinHai-CN marked this pull request as draft May 11, 2026 02:57
@JinHai-CN
JinHai-CN marked this pull request as ready for review May 11, 2026 02:57
@JinHai-CN JinHai-CN added the ci Continue Integration label May 11, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft May 11, 2026 02:58
@JinHai-CN
JinHai-CN marked this pull request as ready for review May 11, 2026 02:58
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (7931b69) to head (6ea7a8e).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14698   +/-   ##
=======================================
  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.

@JinHai-CN
JinHai-CN merged commit bfb4a0e into infiniflow:main May 11, 2026
3 checks passed
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 Gitee AI Go driver in `internal/entity/models/gitee.go` shipped with
a stub `Encode` method that returned `gitee, no such method`, even
though `conf/models/gitee.json` already wires the `embedding` URL
suffix. The conf also listed no embedding models, so the picker had
nothing to select.

This blocked any tenant who wanted to use Gitee AI for chat, rerank
(already working, see infiniflow#14656), and embeddings from a single provider.

This PR fills the gap, mirroring the just-merged Aliyun `Encode`
(infiniflow#14647):

- `internal/entity/models/gitee.go`: replace the `Encode` stub with a
real implementation.
Validates inputs, resolves the region with a default fallback, POSTs the
standard OpenAI-compatible `{"model", "input": [...]}` body to
`BaseURL[region] + URLSuffix.Embedding`, parses `data[*].embedding`
indexed by `data[*].index` so output order matches input order, handles
both `float64` and `float32` element types, and uses a 30s per-call
context deadline matching the merged `Rerank`.
- `conf/models/gitee.json`: add `BAAI/bge-m3` so the embedding picker
has something to select.

No factory change. No interface change. No URL suffix change.

Verified with `go build`, `go vet`, and `gofmt -l` : all clean.

Closes infiniflow#14697

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Feature Request]: Implement Encode (embeddings) in the Gitee AI Go driver

2 participants