Repository navigation
Go: implement Encode (embeddings) in Google Gemini driver - #14682
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR registers ChangesGoogle Gemini Embedding Feature
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Encode
participant GeminiAPI
Caller->>Encode: Encode(modelName, texts, apiConfig, embeddingConfig)
Encode->>Encode: validate apiKey, modelName, texts
Encode->>Encode: create timeout-bound context
Encode->>Encode: build genai.Content per text
Encode->>GeminiAPI: EmbedContent(ctx, request)
GeminiAPI-->>Encode: response with embeddings array
Encode->>Encode: verify counts and convert Values -> [][]float64
Encode-->>Caller: [][]float64 or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 |
There was a problem hiding this comment.
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/deepseek.go`:
- Around line 462-463: The context timeout in the Deepseek driver uses a
hardcoded 30*time.Second (context.WithTimeout(context.Background(),
30*time.Second)); replace that literal with the shared nonStreamCallTimeout
constant so non-stream calls use the centralized timeout; update the
context.WithTimeout call in deepseek.go (the code that creates ctx, cancel) to
use nonStreamCallTimeout and ensure the symbol is referenced/imported from the
package where it’s defined.
🪄 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: 874f773b-d353-410f-bd69-0131f43508d8
📒 Files selected for processing (2)
conf/models/deepseek.jsoninternal/entity/models/deepseek.go
Haruko386
left a comment
There was a problem hiding this comment.
Hi @Joseff531 Where can I find the DeepSeek embedding documentation?
DeepSeek Api Docs
Hi @Haruko386, you're right to question the original scope. After checking the official DeepSeek API docs ( I repurposed this PR once more - implementing OpenAI
Sorry for the churn on the scope, the implementation is solid now. |
|
Hope your review again, Thanks. |
2189f6e to
7b886c8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14682 +/- ##
==========================================
- Coverage 95.59% 94.16% -1.43%
==========================================
Files 10 10
Lines 703 703
Branches 112 112
==========================================
- Hits 672 662 -10
- Misses 21 25 +4
- Partials 10 16 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@conf/models/google.json`:
- Around line 22-28: Replace the deprecated "text-embedding-004" entry in
conf/models/google.json with the new model name "gemini-embedding-001" and
update its token limit to 8192; specifically update the object where "name":
"text-embedding-004" (and "max_tokens": 2048) to use "name":
"gemini-embedding-001" and "max_tokens": 8192 while keeping "model_types":
["embedding"] intact.
In `@internal/entity/models/google.go`:
- Around line 215-263: The Encode method uses an undefined nonStreamCallTimeout
and lacks the time import; define the constant nonStreamCallTimeout (e.g., const
nonStreamCallTimeout = 120 * time.Second) in this file and add "time" to the
import block so Encode (and its context.WithTimeout call) compiles; update
google.go near the top with the import and the constant definition, leaving the
rest of the Encode function unchanged.
🪄 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: abb6d7d8-ad9a-49cf-8f9b-e140b1d8b3f8
📒 Files selected for processing (2)
conf/models/google.jsoninternal/entity/models/google.go
Wires the existing stub to the DeepSeek OpenAI-compatible /embeddings endpoint and adds the embedding URL suffix and text-embedding-v3 model entry to conf/models/deepseek.json. The implementation mirrors the recently merged Aliyun Encode and the in-flight OpenAI (infiniflow#14682) and Ollama (infiniflow#14664) PRs: - POST to ${BaseURL}/${URLSuffix.Embedding} - Authorization: Bearer <api_key> - OpenAI-compatible request body {"model", "input"} - Per-call context.WithTimeout(nonStreamCallTimeout) so a slow upstream cannot block forever - [][]float64 returned in the original input order, sorted by the response `index` field, with explicit checks for out-of-range, duplicate, and missing indices Adds internal/entity/models/deepseek_test.go covering the happy path, empty-input short-circuit, missing api key / model name, non-OK upstream status, and out-of-range / missing-index responses. Closes infiniflow#14680 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Wires the existing stub to the DeepSeek OpenAI-compatible /embeddings endpoint and adds the embedding URL suffix and text-embedding-v3 model entry to conf/models/deepseek.json. The implementation mirrors the recently merged Aliyun Encode and the in-flight OpenAI (infiniflow#14682) and Ollama (infiniflow#14664) PRs: - POST to ${BaseURL}/${URLSuffix.Embedding} - Authorization: Bearer <api_key> - OpenAI-compatible request body {"model", "input"} - Per-call context.WithTimeout(nonStreamCallTimeout) so a slow upstream cannot block forever - [][]float64 returned in the original input order, sorted by the response `index` field, with explicit checks for out-of-range, duplicate, and missing indices Adds internal/entity/models/deepseek_test.go covering the happy path, empty-input short-circuit, missing api key / model name, non-OK upstream status, and out-of-range / missing-index responses. Closes infiniflow#14680
Wires the existing stub to the DeepSeek OpenAI-compatible /embeddings endpoint and adds the embedding URL suffix and text-embedding-v3 model entry to conf/models/deepseek.json. The implementation mirrors the recently merged Aliyun Encode and the in-flight OpenAI (infiniflow#14682) and Ollama (infiniflow#14664) PRs: - POST to ${BaseURL}/${URLSuffix.Embedding} - Authorization: Bearer <api_key> - OpenAI-compatible request body {"model", "input"} - Per-call context.WithTimeout(nonStreamCallTimeout) so a slow upstream cannot block forever - [][]float64 returned in the original input order, sorted by the response `index` field, with explicit checks for out-of-range, duplicate, and missing indices Adds internal/entity/models/deepseek_test.go covering the happy path, empty-input short-circuit, missing api key / model name, non-OK upstream status, and out-of-range / missing-index responses. Closes infiniflow#14680
|
Sorry for the inconvenience, I'd be happy if you could review the PR again when you have a chance. ❤️ |
|
@Joseff531 Encode interface is updated, would you please update your implementation accordingly? please refer to #14735 |
c32ee22 to
f7b6938
Compare
f7b6938 to
dbbde3e
Compare
Thanks for the heads-up. I've rebased onto current main (which now has the new EmbeddingConfig.Dimension field from #14735) and updated the Gemini driver to honor it — when set, it's passed as OutputDimensionality on mbedContentConfig |
…#14682) ### What problem does this PR solve? - Implements the `Encode` method in the Google Gemini driver, which was previously a stub returning `not implemented` - Uses the `google.golang.org/genai` SDK's `EmbedContent` API, which routes to the `batchEmbedContents` endpoint internally — all texts are sent in a single request - Adds `text-embedding-004` (max 2048 tokens) to `conf/models/google.json` - Response values are `[]float32` from the SDK and are cast to `[]float64` to satisfy the `ModelDriver` interface ## Files changed - `internal/entity/models/google.go` — full `Encode` implementation - `conf/models/google.json` — adds `text-embedding-004` embedding model ### Type of change - [x] New Feature (non-breaking change which adds functionality)
What problem does this PR solve?
Encodemethod in the Google Gemini driver, which was previously a stub returningnot implementedgoogle.golang.org/genaiSDK'sEmbedContentAPI, which routes to thebatchEmbedContentsendpoint internally — all texts are sent in a single requesttext-embedding-004(max 2048 tokens) toconf/models/google.json[]float32from the SDK and are cast to[]float64to satisfy theModelDriverinterfaceFiles changed
internal/entity/models/google.go— fullEncodeimplementationconf/models/google.json— addstext-embedding-004embedding modelType of change