Go: implement Bedrock embeddings (#15543)

### What problem does this PR solve?

Fixes #15542.

AWS Bedrock support for the Go model provider layer was added in #15166,
but embedding support was intentionally left out of scope and
`BedrockModel.Embed(...)` still returned the `no such method` sentinel.
This PR implements Bedrock text embeddings under the umbrella provider
tracker #14736.

### What this PR includes

- `internal/entity/models/bedrock.go`: implement
`BedrockModel.Embed(...)` through Bedrock Runtime `InvokeModel` with
existing SigV4 auth, region resolution, and runtime URL helpers.
- Titan embeddings: supports `amazon.titan-embed-text-v1` and
`amazon.titan-embed-text-v2:0`; v2 forwards `EmbeddingConfig.Dimension`
as `dimensions` when provided, while v1 keeps the payload minimal.
- Cohere embeddings: supports `cohere.embed-english-v3`,
`cohere.embed-multilingual-v3`, and `cohere.embed-v4:0`; batches input
texts and maps returned vectors to RAGFlow `EmbeddingData` in input
order.
- `conf/models/bedrock.json`: adds the `embedding` URL suffix (`invoke`)
and Bedrock embedding model entries.
- `internal/entity/models/bedrock_test.go`: adds unit tests for Titan,
Cohere, typed Cohere responses, validation, empty input, unsupported
models, and HTTP error propagation.

Reference docs:

- Bedrock InvokeModel API:
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html
- Titan Text Embeddings:
https://docs.aws.amazon.com/bedrock/latest/userguide/titan-embedding-models.html
- Cohere Embed models on Bedrock:
https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-embed.html

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

### How was this tested?

- [x] `jq empty conf/models/bedrock.json`
- [x] `git diff --check`
- [x] `go test ./internal/entity/models/... -run Bedrock -count=1`
- [x] `go test ./internal/entity/models/... -run '^$' -count=1`
- [x] `go test ./internal/entity/models/... -run Bedrock -race -count=1`

Note: `go test ./internal/entity/models/... -count=1` currently fails in
unrelated existing Astraflow coverage
(`TestAstraflowEmbedReturnsNoSuchMethod` panics in
`internal/entity/models/astraflow.go`). The Bedrock-specific tests and
compile-only package check pass.
This commit is contained in:
tmimmanuel
2026-06-04 19:26:32 -10:00
committed by GitHub
parent b8db200757
commit f78ef328bb
3 changed files with 395 additions and 8 deletions

View File

@@ -2,7 +2,8 @@
"name": "Bedrock",
"url_suffix": {
"chat": "converse",
"models": "foundation-models"
"models": "foundation-models",
"embedding": "invoke"
},
"class": "bedrock",
"models": [
@@ -110,6 +111,41 @@
"model_types": [
"chat"
]
},
{
"name": "amazon.titan-embed-text-v2:0",
"max_tokens": 8192,
"model_types": [
"embedding"
]
},
{
"name": "amazon.titan-embed-text-v1",
"max_tokens": 8192,
"model_types": [
"embedding"
]
},
{
"name": "cohere.embed-english-v3",
"max_tokens": 512,
"model_types": [
"embedding"
]
},
{
"name": "cohere.embed-multilingual-v3",
"max_tokens": 512,
"model_types": [
"embedding"
]
},
{
"name": "cohere.embed-v4:0",
"max_tokens": 128000,
"model_types": [
"embedding"
]
}
]
}