Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/services/code-index/embedders/bedrock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BedrockRuntimeClient, InvokeModelCommand, InvokeModelCommandInput } from "@aws-sdk/client-bedrock-runtime"
import { fromEnv, fromIni } from "@aws-sdk/credential-providers"
import { fromIni, fromNodeProviderChain } from "@aws-sdk/credential-providers"
import { IEmbedder, EmbeddingResponse, EmbedderInfo } from "../interfaces"
import {
MAX_BATCH_TOKENS,
Expand Down Expand Up @@ -38,7 +38,7 @@ export class BedrockEmbedder implements IEmbedder {

// Initialize the Bedrock client with credentials
// If profile is specified, use it; otherwise use default credential chain
const credentials = this.profile ? fromIni({ profile: this.profile }) : fromEnv()
const credentials = this.profile ? fromIni({ profile: this.profile }) : fromNodeProviderChain()

this.bedrockClient = new BedrockRuntimeClient({
userAgentAppId: `RooCode#${Package.version}`,
Expand Down Expand Up @@ -209,10 +209,18 @@ export class BedrockEmbedder implements IEmbedder {
requestBody = {
inputText: text,
}
} else if (model.startsWith("cohere.embed-v4")) {
// Cohere Embed v4 requires embedding_types parameter
requestBody = {
texts: [text],
input_type: "search_document",
embedding_types: ["float"],
}
} else if (model.startsWith("cohere.embed")) {
// Cohere Embed v3 format
requestBody = {
texts: [text],
input_type: "search_document", // or "search_query" depending on use case
input_type: "search_document",
}
} else {
// Default to Titan format
Expand Down Expand Up @@ -248,10 +256,15 @@ export class BedrockEmbedder implements IEmbedder {
embedding: responseBody.embedding,
inputTextTokenCount: responseBody.inputTextTokenCount,
}
} else if (model.startsWith("cohere.embed-v4")) {
// Cohere Embed v4 returns { embeddings: { float: [[...]] } }
return {
embedding: responseBody.embeddings?.float?.[0] || responseBody.embeddings?.[0],
}
} else if (model.startsWith("cohere.embed")) {
// Cohere Embed v3 returns { embeddings: [[...]] }
return {
embedding: responseBody.embeddings[0],
// Cohere doesn't provide token count in response
}
} else {
// Default to Titan format
Expand Down
4 changes: 3 additions & 1 deletion src/shared/embeddingModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export const EMBEDDING_MODEL_PROFILES: EmbeddingModelProfiles = {
"amazon.titan-embed-image-v1": { dimension: 1024, scoreThreshold: 0.4 },
// Amazon Nova Embed models
"amazon.nova-2-multimodal-embeddings-v1:0": { dimension: 1024, scoreThreshold: 0.4 },
// Cohere models available through Bedrock
// Cohere Embed v4 (supports only text for now; multimodal image support planned)
"cohere.embed-v4:0": { dimension: 1536, scoreThreshold: 0.4 },
// Cohere Embed v3 models available through Bedrock
"cohere.embed-english-v3": { dimension: 1024, scoreThreshold: 0.4 },
"cohere.embed-multilingual-v3": { dimension: 1024, scoreThreshold: 0.4 },
},
Expand Down
Loading