Skip to content

Add Cohere Embed v4 support for Bedrock code indexing and fix credential refresh for long-running sessions #11823

@cscvenkatmadurai

Description

@cscvenkatmadurai

Problem

When indexing large codebases with the Bedrock embedding provider, two issues arise:

  1. Missing model: Cohere Embed v4 (cohere.embed-v4:0) is now available on AWS Bedrock but isn't supported as an embedding model for code indexing. It offers 1536-dimensional embeddings with 128k context — a significant upgrade over Cohere v3.

  2. Credential expiry on large codebases: The BedrockEmbedder uses fromEnv() as the credential fallback when no AWS profile is specified. fromEnv() only reads static environment variables and doesn't support auto-refresh. For large codebases where indexing takes >1 hour, temporary AWS credentials (from SSO, STS, or credential_process like ada) expire mid-session, causing indexing failures.

User Benefit

  • Access to the latest Cohere Embed v4 model for higher quality code embeddings via Bedrock
  • Reliable credential auto-refresh during long-running indexing sessions, supporting AWS SSO, IAM Identity Center, ECS, EC2 IMDS, and credential_process-based profiles
  • No more indexing failures on large codebases due to expired credentials

Proposed Solution

1. Add Cohere Embed v4 (cohere.embed-v4:0)

  • Add model to Bedrock embedding profiles with dimension 1536
  • Add v4-specific request format (embedding_types: ["float"])
  • Add v4-specific response parsing (embeddings.float[0] instead of embeddings[0])
  • Text-only support initially; multimodal image support planned as follow-up

2. Fix credential fallback

  • Replace fromEnv() with fromNodeProviderChain() — the AWS SDK v3 default credential chain
  • fromNodeProviderChain() checks env vars first (backward compatible), then SSO, INI, IMDS, ECS, etc.
  • Includes built-in memoization for efficient credential caching with auto-refresh

Files Changed (3 files, ~10 lines production code + tests)

  • src/services/code-index/embedders/bedrock.ts — Credential fix + Cohere v4 request/response
  • src/shared/embeddingModels.ts — New model profile entry
  • src/services/code-index/embedders/__tests__/bedrock.spec.ts — 5 new tests

Roadmap Alignment

This aligns with: "Expand robust support for a wide variety of AI providers and models."

Related: aws-samples/bedrock-access-gateway#212

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions