Repository navigation
Go: implement Embed (embeddings) in Replicate driver - #15073
Conversation
Replicate's Embed method was a `"replicate, no such method"` stub. Tracking issue infiniflow#14736 lists Replicate as a provider whose embedding surface is still unimplemented. Implementation: - New Embed(modelName, texts, apiConfig, embeddingConfig) reuses the existing createPrediction + waitForPrediction plumbing the chat path already validates. Request body uses Replicate's documented embedding input fields: text (string) for len(texts) == 1 text_batch (string) for len(texts) > 1, a JSON-encoded list of strings, NOT a JSON array — matches the openapi_schema's type:"string". - Output parsing handles both observed shapes: []{embedding: [floats]} — canonical Embedding schema (replicate/all-mpnet-base-v2) [][floats] — bare nested array variant some community models emit Rejects mismatched cardinality and non-numeric vector entries rather than silently truncate, matching the defensive posture the n1n / CometAPI drivers already use. - conf/models/replicate.json gains replicate/all-mpnet-base-v2 at version b6b7585c (model_types: ["embedding"]). The version is pinned because that model is not on Replicate's official-models list; bare owner/name 404s on /v1/models/.../predictions and must go through /v1/predictions with the version field — the format the existing predictionEndpoint logic in replicate.go routes when modelName contains ":". Live verification against api.replicate.com — full transcripts in the PR body. The driver's request shape was confirmed via the 402/422 differential: a valid version returns 402 "Insufficient credit" (Replicate accepts the request and only the billing gate stops execution), while an invalid version returns 422 "Invalid version or not permitted". This proves the URL routing, version field, input shape, and wait header are all correct. No unit tests per user direction; chat path tests would cover the shared prediction plumbing if a future PR adds them.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements Replicate embedding support by registering a new all-mpnet-base-v2 embedding model and replacing the stub ChangesReplicate Embedding Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15073 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? `ReplicateModel.Embed` in `internal/entity/models/replicate.go` was a `"replicate, no such method"` stub. Tracking issue #14736 lists Replicate's embedding surface as not implemented. This PR wires it up against Replicate's documented embedding schema. Until this PR, a tenant who selected a Replicate embedding model got the sentinel error on every embed call. Co-authored-by: sxxtony <[email protected]> Co-authored-by: Jin Hai <[email protected]>
### What problem does this PR solve? `ReplicateModel.Rerank` in `internal/entity/models/replicate.go` was a `"replicate, no such method"` stub. The chat path landed in #14958 and the embed path in #15073; rerank is the last major retrieval surface still missing on this provider. Until this PR, a tenant who selected a Replicate reranker model got the sentinel error on every rerank call. Co-authored-by: sxxtony <[email protected]> Co-authored-by: Jin Hai <[email protected]>
What problem does this PR solve?
ReplicateModel.Embedininternal/entity/models/replicate.gowas a"replicate, no such method"stub. Tracking issue #14736 lists Replicate's embedding surface as not implemented. This PR wires it up against Replicate's documented embedding schema.Until this PR, a tenant who selected a Replicate embedding model got the sentinel error on every embed call.
What this PR includes
internal/entity/models/replicate.go— realEmbedmethod backed by Replicate's/v1/predictionsasync API, reusing the existingcreatePrediction+waitForPredictionplumbing the chat path already validates.conf/models/replicate.json— addsreplicate/all-mpnet-base-v2at versionb6b7585c...(model_types: ["embedding"]).Wire shape (verified against Replicate's openapi_schema)
Input (per the canonical
replicate/all-mpnet-base-v2schema):text(string) — single text to encode, used whenlen(texts) == 1text_batch(string) — JSON-encoded list of strings to encode, used whenlen(texts) > 1. Note that the schema declarestext_batchastype: string, so the JSON-encoded list is sent as a string, not as a JSON array.Output: array of
{embedding: [number]}objects, one per input in order. The driver also tolerates the alternative bare-nested-array shape[[number]]some community models emit.Live test transcripts (api.replicate.com)
The Replicate account on the provided key has no billing credit, so I could not run a full embedding inference end-to-end. Everything up to the billing gate works:
T1 — Auth check
T2 — Model metadata for replicate/all-mpnet-base-v2
Confirms the input field names and output shape the driver targets.
T3 — Driver's request reaches the prediction endpoint (route ✓, payload ✓, version ✓)
Replicate accepts the request — URL, headers, version, and
input.textfield shape all pass validation. Only the billing gate stops execution.T4 — Invalid version (control, proves Replicate validates the version field)
This rules out a false-positive on T3: Replicate does validate the version up-front. T3's 402 means the version is real and the request shape is correct.
T5 — Bare owner/name path on a community model (background)
Confirms that
replicate/all-mpnet-base-v2is not on Replicate's official-models list, so the catalog uses theowner/name:versionnotation which the existingpredictionEndpointinreplicate.goroutes through/v1/predictionswith theversionfield — the format that returned 402 in T3.Why owner/name:version in the catalog
replicate.go:111already implements:Names containing
":"go through/v1/predictionswithversion. Community embedding models (which is most of them on Replicate) need this form because they aren't on the official-models list and 404 on the owner/name endpoint (T5). The pinned version in the catalog can be overridden per-tenant if a newer version ships.What I deliberately did NOT do
createPrediction+waitForPredictionin production, and the newEmbedreuses those same code paths; the only new logic is input/output shaping (replicateEmbedInput,replicateEmbedOutputToVectors).nateraw/bge-large-en-v1.5schema — that model usesinput.texts(different field name) and returns either inline arrays or a.npyfile URI. Implementing that alternative input/output shape belongs in a follow-up; the canonicaltext/text_batch+[{embedding:[…]}]schema (replicate/all-mpnet-base-v2) is implemented here.