or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mdchat-models.mdembeddings.mdindex.mdretrievers.md
tile.json

tessl/npm-langchain--aws

LangChain AWS integration providing chat models, embeddings, and retrievers for seamless AWS service connections.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@langchain/aws@0.1.x

To install, run

npx @tessl/cli install tessl/npm-langchain--aws@0.1.0

index.mddocs/

@langchain/aws

@langchain/aws provides comprehensive LangChain integrations for AWS services, enabling developers to seamlessly connect their applications with AWS Bedrock chat models, embeddings, and Kendra/Knowledge Base retrievers. Built with TypeScript for enhanced developer experience, it offers production-ready authentication mechanisms and maintains compatibility with the broader LangChain ecosystem.

Package Information

  • Package Name: @langchain/aws
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @langchain/aws
  • Node.js Requirements: >= 18

Core Imports

import {
  ChatBedrockConverse,
  BedrockEmbeddings,
  AmazonKendraRetriever,
  AmazonKnowledgeBaseRetriever
} from "@langchain/aws";

For CommonJS:

const {
  ChatBedrockConverse,
  BedrockEmbeddings,
  AmazonKendraRetriever,
  AmazonKnowledgeBaseRetriever
} = require("@langchain/aws");

Basic Usage

import { ChatBedrockConverse } from "@langchain/aws";
import { HumanMessage } from "@langchain/core/messages";

// Initialize chat model with AWS credentials
const model = new ChatBedrockConverse({
  region: process.env.BEDROCK_AWS_REGION ?? "us-east-1",
  credentials: {
    secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY,
    accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID,
  },
  model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
  temperature: 0.7,
  maxTokens: 1000
});

// Generate response
const response = await model.invoke([
  new HumanMessage("What is the capital of France?")
]);

console.log(response.content);

Architecture

@langchain/aws is built around several key components:

  • Chat Models: ChatBedrockConverse class providing both streaming and non-streaming interfaces with full AWS Bedrock Converse API support
  • Embeddings: BedrockEmbeddings for generating text embeddings using Amazon Titan and other Bedrock embedding models
  • Retrievers: Document retrieval through AmazonKendraRetriever for intelligent search and AmazonKnowledgeBaseRetriever for RAG workflows
  • Authentication: Flexible credential management supporting AWS access keys, bearer tokens, and credential provider chains
  • Type Safety: Complete TypeScript integration with interfaces for all configuration options and responses

Capabilities

Chat Models

Advanced conversational AI capabilities using AWS Bedrock's Converse API with support for streaming, function calling, multimodal input, and structured output.

class ChatBedrockConverse extends BaseChatModel {
  constructor(fields?: ChatBedrockConverseInput);
  invoke(messages: BaseMessage[], options?: ChatBedrockConverseCallOptions): Promise<AIMessage>;
  stream(messages: BaseMessage[], options?: ChatBedrockConverseCallOptions): AsyncGenerator<AIMessageChunk>;
  bindTools(tools: ChatBedrockConverseToolType[], kwargs?: Partial<ChatBedrockConverseCallOptions>): Runnable;
  withStructuredOutput<T>(outputSchema: InteropZodType<T> | Record<string, any>, config?: StructuredOutputMethodOptions): Runnable<BaseLanguageModelInput, T>;
}

interface ChatBedrockConverseInput extends BaseChatModelParams {
  client?: BedrockRuntimeClient;
  clientOptions?: BedrockRuntimeClientConfig;
  streaming?: boolean;
  model?: string;
  region?: string;
  credentials?: CredentialType;
  temperature?: number;
  maxTokens?: number;
  endpointHost?: string;
  topP?: number;
  additionalModelRequestFields?: __DocumentType;
  streamUsage?: boolean;
  guardrailConfig?: GuardrailConfiguration;
  performanceConfig?: PerformanceConfiguration;
  supportsToolChoiceValues?: Array<"auto" | "any" | "tool">;
}

Chat Models

Text Embeddings

Generate high-quality text embeddings using AWS Bedrock embedding models with automatic batching and text preprocessing.

class BedrockEmbeddings extends Embeddings {
  constructor(fields?: BedrockEmbeddingsParams);
  embedQuery(document: string): Promise<number[]>;
  embedDocuments(documents: string[]): Promise<number[][]>;
}

interface BedrockEmbeddingsParams extends EmbeddingsParams {
  model?: string;
  client?: BedrockRuntimeClient;
  clientOptions?: BedrockRuntimeClientConfig;
  region?: string;
  credentials?: CredentialType;
}

Embeddings

Document Retrieval

Retrieve relevant documents from AWS services for RAG applications and knowledge search workflows.

class AmazonKendraRetriever extends BaseRetriever {
  constructor(args: AmazonKendraRetrieverArgs);
  getRelevantDocuments(query: string): Promise<Document[]>;
}

class AmazonKnowledgeBaseRetriever extends BaseRetriever {
  constructor(args: AmazonKnowledgeBaseRetrieverArgs);
  getRelevantDocuments(query: string): Promise<Document[]>;
}

interface AmazonKendraRetrieverArgs {
  indexId: string;
  topK: number;
  region: string;
  attributeFilter?: AttributeFilter;
  clientOptions?: KendraClientConfig;
}

interface AmazonKnowledgeBaseRetrieverArgs {
  knowledgeBaseId: string;
  topK: number;
  region: string;
  clientOptions?: BedrockAgentRuntimeClientConfig;
  filter?: RetrievalFilter;
  overrideSearchType?: SearchType;
}

Retrievers

Authentication & Configuration

Flexible authentication mechanisms supporting multiple AWS credential types and custom client configurations.

type CredentialType = AwsCredentialIdentity | Provider<AwsCredentialIdentity>;

type ConverseCommandParams = ConstructorParameters<typeof ConverseCommand>[0];

type BedrockToolChoice = ToolChoice.AnyMember | ToolChoice.AutoMember | ToolChoice.ToolMember;

type ChatBedrockConverseToolType = BindToolsInput | BedrockTool;

type BedrockConverseToolChoice = "auto" | "any" | string | BedrockToolChoice;

Authentication

Types

interface ChatBedrockConverseCallOptions extends BaseChatModelCallOptions {
  stop?: string[];
  tools?: ChatBedrockConverseToolType[];
  tool_choice?: BedrockConverseToolChoice;
  additionalModelRequestFields?: __DocumentType;
  streamUsage?: boolean;
  guardrailConfig?: GuardrailConfiguration;
  performanceConfig?: PerformanceConfiguration;
}

type MessageContentReasoningBlock = 
  | MessageContentReasoningBlockReasoningText
  | MessageContentReasoningBlockRedacted
  | MessageContentReasoningBlockReasoningTextPartial;

interface MessageContentReasoningBlockReasoningText {
  type: "reasoning_content";
  reasoningText: {
    text: string;
    signature: string;
  };
}

interface MessageContentReasoningBlockRedacted {
  type: "reasoning_content";
  redactedContent: string;
}

interface MessageContentReasoningBlockReasoningTextPartial {
  type: "reasoning_content";
  reasoningText: { text: string } | { signature: string };
}