Skip to content

Go: implement Embed (embeddings) in TogetherAI driver - #15017

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
davidv399:feat/go-togetherai-embed
May 20, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
davidv399:feat/go-togetherai-embed

Conversation

@davidv399

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes #15015

The TogetherAI Go driver in internal/entity/models/togetherai.go shipped a stub Embed method that returned "TogetherAI, no such method", so TogetherAI could not be used as an embedding provider in RAGFlow. This PR fills that gap.

TogetherAI exposes a public OpenAI-compatible embeddings endpoint at POST https://api.together.ai/v1/embeddings that accepts the standard {model, input} shape with Authorization: Bearer <api_key> (confirmed in TogetherAI's official docs: https://docs.together.ai/docs/embeddings-overview). Documented embedding models include intfloat/multilingual-e5-large-instruct, BAAI/bge-large-en-v1.5, and BAAI/bge-base-en-v1.5.

Changes

  • internal/entity/models/togetherai.go: implement TogetherAIModel.Embed.
    • Validate inputs (api key, model name) and short-circuit on empty texts.
    • Resolve region with the existing baseURLForRegion helper.
    • Build URL from URLSuffix.Embedding.
    • Send {model, input} POST body, add dimensions when embeddingConfig.Dimension > 0 (matches the pattern in Go CLI: embed and rerank #14735).
    • Bearer auth + JSON content type, mirroring the chat path.
    • Parse {data: [{embedding, index}]} and reorder by index, rejecting out-of-range indices, duplicates, and missing entries so the output always lines up with the input. Same shape as the merged Mistral, Upstage, and Novita Embed implementations.
  • conf/models/togetherai.json:
    • Add "embedding": "embeddings" to url_suffix.
    • Add default embedding model entries for intfloat/multilingual-e5-large-instruct, BAAI/bge-large-en-v1.5, and BAAI/bge-base-en-v1.5.

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 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 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: 840b2eec-84f3-4e40-8c74-24d7eb4fb72b

📥 Commits

Reviewing files that changed from the base of the PR and between 279fdaf and c5045a0.

📒 Files selected for processing (2)
  • conf/models/togetherai.json
  • internal/entity/models/togetherai.go
✅ Files skipped from review due to trivial changes (1)
  • conf/models/togetherai.json

📝 Walkthrough

Walkthrough

Adds TogetherAI embeddings: updates config to add an embeddings route and models, and implements TogetherAIModel.Embed to POST /embeddings, parse and validate per-index embedding items, and return embeddings ordered to match inputs.

Changes

TogetherAI Embeddings Feature

Layer / File(s) Summary
Configuration: Embedding endpoint and models
conf/models/togetherai.json
url_suffix adds an embedding mapping and three embedding-capable models (intfloat/multilingual-e5-large-instruct, BAAI/bge-large-en-v1.5, BAAI/bge-base-en-v1.5) with max_tokens and model_types: ["embedding"].
Embeddings implementation: types and Embed method
internal/entity/models/togetherai.go
Adds internal request/response structs for the TogetherAI embeddings payload and implements TogetherAIModel.Embed: validates inputs, selects region-aware base URL, builds request (including optional dimensions), POSTs with auth headers, parses JSON, enforces one-to-one index→embedding mapping, and returns []EmbeddingData in input order.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #14810 — Another provider Embed implementation with similar POST /embeddings and index validation patterns; related implementation work.

Possibly related PRs

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped through config and code today,
I routed embeddings the TogetherAI way.
Requests now fly, and vectors return,
Indexed and ordered — no more concern.
✨🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: implementing the Embed method for the TogetherAI Go driver.
Description check ✅ Passed The PR description follows the template with a clear problem statement, explicit type of change, and detailed breakdown of changes in both files.
Linked Issues check ✅ Passed The code changes fully implement all eight objectives specified in #15015: validates inputs, resolves region, posts to the correct endpoint with proper auth, sends standard request body with dimensions support, parses OpenAI-shaped responses with strict validation, surfaces errors, and updates the config.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the Embed method for TogetherAI; no unrelated modifications to other drivers or core systems are present.
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.

@davidv399

Copy link
Copy Markdown
Contributor Author

Hi @Magicbook1108, gentle ping for review when you have a moment. This follows the same OpenAI-compatible /embeddings shape that the merged Mistral, Upstage, Novita, Aliyun, Ollama, vLLM, LM Studio, and OpenAI Embed drivers already use, scope is two files (one config, one driver), and it closes #15015. The endpoint and model names were confirmed against TogetherAI's official docs. The driver also honors embeddingConfig.Dimension (the field added in #14735). Thanks!

@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/togetherai.go`:
- Around line 409-410: The validation for modelName currently only checks nil
and empty string but allows whitespace-only names; update the check in the
function that contains variable modelName to use strings.TrimSpace on *modelName
(importing the strings package if needed) and treat a trimmed empty string as
invalid (i.e., change the condition to nil OR strings.TrimSpace(*modelName) ==
""), and optionally assign the trimmed value back to *modelName so callers get
the normalized name; keep the same error return (fmt.Errorf("model name is
required")) when invalid.
🪄 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: f777a201-fcaa-448b-9b42-fc6ebcc39c1f

📥 Commits

Reviewing files that changed from the base of the PR and between eacec86 and 6774117.

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

Comment thread internal/entity/models/togetherai.go Resolved
@davidv399

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai. Addressed in 279fdaf: the model-name check in Embed now uses strings.TrimSpace, so whitespace-only names are rejected with the same model name is required error instead of being sent upstream. strings was already imported. Build passes.

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@jack-stormentswe Thanks for the update! Using strings.TrimSpace on the model name is the right call — whitespace-only strings are now properly caught before hitting the upstream API, consistent with the input validation pattern across the other drivers.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@JinHai-CN
JinHai-CN requested a review from Haruko386 May 20, 2026 02:08

@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 @jack-stormentswe, all tests are passed, thank you for your contribution. ❤

@Haruko386 Haruko386 added the ci Continue Integration label May 20, 2026
@Haruko386 Haruko386 added ci Continue Integration and removed ci Continue Integration labels May 20, 2026
@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (b28e134) to head (c5045a0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15017   +/-   ##
=======================================
  Coverage   93.12%   93.12%           
=======================================
  Files          10       10           
  Lines         713      713           
  Branches      116      116           
=======================================
  Hits          664      664           
  Misses         29       29           
  Partials       20       20           

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

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 Embed (embeddings) in the TogetherAI Go driver

3 participants