This library provides an integration for connecting LlamaIndex with AWS Bedrock Large Language Models (LLMs). It allows users to leverage various Bedrock models for text completion and chat functionalities within their LlamaIndex applications, including streaming responses. The library is part of the broader LlamaIndex ecosystem, which maintains an active development pace with frequent updates and a move towards modular integrations.
pip install llama-index-llms-bedrockVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Bedrock` LLM, perform a simple text completion, engage in a chat conversation using `ChatMessage` objects, and stream a completion response. Authentication is handled via environment variables for AWS credentials (or a configured AWS CLI profile).
Migrate your code to use `llama-index-llms-bedrock-converse`. Install it with `pip install llama-index-llms-bedrock-converse` and import `BedrockConverse` from `llama_index.llms.bedrock_converse`.
Explicitly set `region_name` when initializing `Bedrock` (e.g., `region_name='us-east-1'`) or ensure the `AWS_REGION` environment variable is correctly set.
Verify that the IAM role or user credentials used have the necessary `bedrock:InvokeModel` permissions for the specific foundation model and region you are trying to access. Check for any explicit deny policies.
Ensure you use `llm.complete(prompt_string)` for single-turn text completions and `llm.chat([ChatMessage(role='user', content='...')])` for multi-turn conversations or when expecting a chat-like interface. Check model-specific documentation for any unique prompt requirements.
This is a known issue. Consider using `llama-index-llms-bedrock-converse` as it has seen fixes for similar issues regarding parameter passing. Alternatively, implement guardrails at the AWS service level or ensure your `guardrail_config` is being correctly translated and applied in your specific `llama-index` version (check the relevant GitHub issues for updates).
When initializing `Bedrock`, provide the `region_name` argument (e.g., `Bedrock(..., region_name='us-west-2')`) or set the `AWS_REGION` environment variable.
Verify the exact model ID string from AWS Bedrock documentation (e.g., 'mistral.mixtral-8x7b-instruct-v0:1' or 'amazon.titan-text-express-v1'). Also, ensure the model is enabled and available in your AWS account and the specified `region_name`.
Review your AWS IAM policies and ensure the user/role has permission to invoke Bedrock models, specifically `bedrock:InvokeModel` on the target resource (e.g., `arn:aws:bedrock:us-west-2::foundation-model/mistral.mixtral-8x7b-instruct-v0:1`). Also, check for any Service Control Policies (SCPs) that might be explicitly denying access.
For `llm.complete(prompt_string)`, `prompt_string` must be a `str`. For `llm.chat(messages)`, `messages` must be a `list` of `ChatMessage` objects. Convert your input to the expected type for the method being called.