Bedrock features and configuration options, please refer to the API reference.
Overview
Integration details
| Class | Package | Local | Py support | Downloads | Version |
|---|---|---|---|---|---|
| Bedrock | @langchain/aws | ❌ | ✅ |
Setup
To access Bedrock embedding models you’ll need to create an AWS account, get an API key, and install the@langchain/aws integration package.
Head to the AWS docs to sign up for AWS and setup your credentials. You’ll also need to turn on model access for your account, which you can do by following these instructions.
Credentials
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:Installation
The LangChain Bedrock integration lives in the@langchain/aws package:
Instantiation
Now we can instantiate our model object and embed text. There are a few different ways to authenticate with AWS - the below examples rely on an access key, secret access key and region set in your environment variables:Indexing and Retrieval
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials under the Learn tab. Below, see how to index and retrieve data using theembeddings object we initialized above. In this example, we will index and retrieve a sample document using the demo MemoryVectorStore.
Direct Usage
Under the hood, the vectorstore and retriever implementations are callingembeddings.embedDocument(...) and embeddings.embedQuery(...) to create embeddings for the text(s) used in fromDocuments and the retriever’s invoke operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single texts
You can embed queries for search withembedQuery. This generates a vector representation specific to the query:
Embed multiple texts
You can embed multiple texts for indexing withembedDocuments. The internals used for this method may (but do not have to) differ from embedding queries:
Configuring the Bedrock Runtime Client
You can pass in your own instance of theBedrockRuntimeClient if you want to customize options like
credentials, region, retryPolicy, etc.
API reference
For detailed documentation of all Bedrock features and configurations head to the API reference.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.