Repository navigation
Go: implement Encode (embeddings) in Gitee AI driver - #14698
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds 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. ChangesGitee Embeddings Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ 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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/entity/models/gitee.go (1)
480-503: ⚡ Quick winAdd 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
📒 Files selected for processing (2)
conf/models/gitee.jsoninternal/entity/models/gitee.go
|
@bittoby Encode interface is updated, would you please update your implementation accordingly? please refer to #14735 |
b60e8b7 to
6ea7a8e
Compare
|
Updated PR. @JinHai-CN Plz review again. Thanks |
|
@bittoby Refer to the CLI usage in #14736, would you please provide the CLI embedding test result as below? |
|
@JinHai-CN Test is done. Result for Could you merge this PR now? |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
### 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)
What problem does this PR solve?
The Gitee AI Go driver in
internal/entity/models/gitee.goshipped with a stubEncodemethod that returnedgitee, no such method, even thoughconf/models/gitee.jsonalready wires theembeddingURL 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 theEncodestub with a real implementation.Validates inputs, resolves the region with a default fallback, POSTs the standard OpenAI-compatible
{"model", "input": [...]}body toBaseURL[region] + URLSuffix.Embedding, parsesdata[*].embeddingindexed bydata[*].indexso output order matches input order, handles bothfloat64andfloat32element types, and uses a 30s per-call context deadline matching the mergedRerank.conf/models/gitee.json: addBAAI/bge-m3so the embedding picker has something to select.No factory change. No interface change. No URL suffix change.
Verified with
go build,go vet, andgofmt -l: all clean.Closes #14697
Type of change