Skip to main content

Documentation Index

Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

本页面涵盖了 LangChain 与the Amazon Web Services (AWS) platform.

聊天模型

Bedrock chat

Amazon Bedrock 是一项完全托管的服务 that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon via a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and evaluate top FMs for your use case, privately customize them with your data using techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that execute tasks using your enterprise systems and data sources. Since Amazon Bedrock is serverless, you don’t have to manage any infrastructure, and you can securely integrate and deploy generative AI capabilities into your applications 使用 AWS services you are already familiar with.
查看使用示例.
from langchain_aws import ChatBedrock

Bedrock converse

AWS Bedrock maintains a Converse API that provides a unified conversational interface for Bedrock models. This API does not yet support custom models. 您可以查看 a list of all models that are supported here.
We recommend the Converse API for users who do not need to use custom models. It can be accessed using ChatBedrockConverse.
查看使用示例.
from langchain_aws import ChatBedrockConverse

大语言模型 (LLM)

Bedrock

查看使用示例.
from langchain_aws import BedrockLLM

Amazon API Gateway

Amazon API Gateway 是一项完全托管的服务 that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. APIs act as the “front door” for applications to access data, business logic, or functionality from your backend services. Using API Gateway, you can create RESTful APIs and WebSocket APIs that enable real-time two-way communication applications. API Gateway supports containerized and serverless workloads, as well as web applications. API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, CORS support, authorization and access control, throttling, monitoring, and API version management. API Gateway has no minimum fees or startup costs. You pay for the API calls you receive and the amount of data transferred out and, with the API Gateway tiered pricing model, you can reduce your cost as your API usage scales.
查看使用示例.
from langchain_community.llms import AmazonAPIGateway

SageMaker endpoint

Amazon SageMaker is a system that can build, train, and deploy machine learning (ML) models with fully managed infrastructure, tools, and workflows.
We use SageMaker to host our model and expose it as the SageMaker Endpoint. 查看使用示例.
from langchain_aws import SagemakerEndpoint

向量嵌入模型

Bedrock

查看使用示例.
from langchain_aws import BedrockEmbeddings

SageMaker endpoint

查看使用示例.
from langchain_community.embeddings import SagemakerEndpointEmbeddings
from langchain_community.llms.sagemaker_endpoint import ContentHandlerBase

文档加载器

AWS S3 directory and file

Amazon Simple Storage Service (Amazon S3) is an object storage service. AWS S3 Directory AWS S3 Buckets
查看S3DirectoryLoader. 查看S3FileLoader.
from langchain_community.document_loaders import S3DirectoryLoader, S3FileLoader

Amazon textract

Amazon Textract is a machine learning (ML) service that automatically extracts text, handwriting, and data from scanned documents.
查看使用示例.
from langchain_community.document_loaders import AmazonTextractPDFLoader

Amazon athena

Amazon Athena is a serverless, interactive analytics service built on open-source frameworks, supporting open-table and file formats.
查看使用示例.
from langchain_community.document_loaders.athena import AthenaLoader

AWS glue

The AWS Glue Data Catalog is a centralized metadata repository that allows you to manage, access, and share metadata about your data stored in AWS. It acts as a metadata store for your data assets, enabling various AWS services and your applications to query and connect to the data they need efficiently.
查看使用示例.
from langchain_community.document_loaders.glue_catalog import GlueCatalogLoader

向量存储

Amazon OpenSearch Service

Amazon OpenSearch Service performs interactive log analytics, real-time application monitoring, website search, and more. OpenSearch is an open source, distributed search and analytics suite derived from Elasticsearch. Amazon OpenSearch Service offers the latest versions of OpenSearch, support for many versions of Elasticsearch, as well as visualization capabilities powered by OpenSearch Dashboards and Kibana.
我们需要安装几个 Python 库。
pip install boto3 requests requests-aws4auth
查看使用示例.
from langchain_community.vectorstores import OpenSearchVectorSearch
Amazon DocumentDB (with MongoDB Compatibility) makes it easy to set up, operate, and scale MongoDB-compatible databases in the cloud. With Amazon DocumentDB, you can run the same application code and use the same drivers and tools that you use with MongoDB. Vector search for Amazon DocumentDB combines the flexibility and rich querying capability of a JSON-based document database with the power of vector search.

安装和设置

查看详细配置说明. 我们需要安装 pymongo Python 包.
pip install pymongo

Deploy DocumentDB on AWS

Amazon DocumentDB (with MongoDB Compatibility) is a fast, reliable, and fully managed database service. Amazon DocumentDB makes it easy to set up, operate, and scale MongoDB-compatible databases in the cloud. AWS offers services for computing, databases, storage, analytics, and other functionality. For an overview of all AWS services, see Cloud Computing with Amazon Web Services. 查看使用示例.
from langchain_community.vectorstores import DocumentDBVectorSearch

Amazon MemoryDB

Amazon MemoryDB is a durable, in-memory database service that delivers ultra-fast performance. MemoryDB is compatible with Redis OSS, a popular open source data store, enabling you to quickly build applications 使用 same flexible and friendly Redis OSS APIs, and commands that they already use today. InMemoryVectorStore class provides a vectorstore to connect with Amazon MemoryDB.
from langchain_aws.vectorstores.inmemorydb import InMemoryVectorStore

vds = InMemoryVectorStore.from_documents(
            chunks,
            embeddings,
            redis_url="rediss://cluster_endpoint:6379/ssl=True ssl_cert_reqs=none",
            vector_schema=vector_schema,
            index_name=INDEX_NAME,
        )
查看使用示例.

Valkey

Valkey 是一个开源的, high-performance key/value datastore that supports workloads such as caching, message queues, and can act as a primary database. Use ValkeyVectorStore to connect with Amazon ElastiCache for Valkey or Amazon MemoryDB for Valkey.
from langchain_aws.vectorstores import ValkeyVectorStore
查看使用示例.

检索器

Amazon kendra

Amazon Kendra is an intelligent search service provided by Amazon Web Services (AWS). It utilizes advanced natural language processing (NLP) and machine learning algorithms to enable powerful search capabilities across various data sources within an organization. Kendra is designed to help users find the information they need quickly and accurately, improving productivity and decision-making.
With Kendra, we can search across a wide range of content types, including documents, FAQs, knowledge bases, manuals, and websites. 它支持 multiple languages and can understand complex queries, synonyms, and contextual meanings to provide highly relevant search results.
我们需要安装 langchain-aws 库。
pip install langchain-aws
查看使用示例.
from langchain_aws import AmazonKendraRetriever

Amazon Bedrock (Knowledge bases)

Knowledge bases for Amazon Bedrock is an Amazon Web Services (AWS) offering which lets you quickly build RAG applications by using your private data to customize foundation model response.
我们需要安装 langchain-aws 库。
pip install langchain-aws
查看使用示例.
from langchain_aws import AmazonKnowledgeBasesRetriever

工具

AWS lambda

Amazon AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). 它帮助 developers to build and run applications and services without provisioning or managing servers. This serverless architecture enables you to focus on writing and deploying code, while AWS automatically takes care of scaling, patching, and managing the infrastructure required to run your applications.
我们需要安装 boto3 Python 库.
pip install boto3
查看使用示例.
from langchain_community.chat_message_histories import DynamoDBChatMessageHistory

Amazon Bedrock AgentCore Browser

Amazon Bedrock AgentCore Browser enables agents to interact with web pages through a managed Chrome browser for navigation, content extraction, and web automation.
pip install langchain-aws bedrock-agentcore playwright beautifulsoup4
查看使用示例.
from langchain_aws.tools import create_browser_toolkit

# 创建工具包
toolkit, browser_tools = create_browser_toolkit(region="us-west-2")

# 与智能体一起使用
agent = create_react_agent(model=llm, tools=browser_tools)
result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "Go to example.com and get the heading"}]},
    config={"configurable": {"thread_id": "session-1"}}
)

# 完成后清理
await toolkit.cleanup()

Amazon Bedrock AgentCore Code Interpreter

Amazon Bedrock AgentCore Code Interpreter enables agents to execute Python, JavaScript, and TypeScript code in secure, managed sandbox environments for calculations, data analysis, and visualizations.
pip install langchain-aws bedrock-agentcore
查看使用示例.
from langchain_aws.tools import create_code_interpreter_toolkit

# 创建工具包(异步)
toolkit, code_tools = await create_code_interpreter_toolkit(region="us-west-2")

# 与智能体一起使用
agent = create_react_agent(model=llm, tools=code_tools)
result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "Calculate factorial of 10"}]},
    config={"configurable": {"thread_id": "session-1"}}
)

# 完成后清理
await toolkit.cleanup()

沙箱

AgentCoreSandbox

Amazon Bedrock AgentCore Code Interpreter sandbox backend for deepagents.

Amazon neptune

Amazon Neptune is a high-performance graph analytics and serverless database for superior scalability and availability.
For the Cypher and SPARQL integrations below, we need to install the langchain-aws 库。
pip install langchain-aws

Amazon neptune with cypher

查看使用示例.
from langchain_aws.graphs import NeptuneGraph
from langchain_aws.graphs import NeptuneAnalyticsGraph
from langchain_aws.chains import create_neptune_opencypher_qa_chain

Amazon neptune with SPARQL

from langchain_aws.graphs import NeptuneRdfGraph
from langchain_aws.chains import create_neptune_sparql_qa_chain

记忆

Amazon Bedrock AgentCore Memory

Amazon Bedrock AgentCore Memory provides managed persistence for LangGraph agents, enabling conversation history and state management across sessions with automatic scaling and high availability.
pip install langgraph-checkpoint-aws
from langgraph_checkpoint_aws import AgentCoreMemorySaver

# 创建检查点
checkpointer = AgentCoreMemorySaver(
    memory_id="your-memory-id",
    region_name="us-west-2"
)

# 与 LangGraph 一起使用
graph = workflow.compile(checkpointer=checkpointer)

# 使用 thread_id 和 actor_id 调用以持久化对话
config = {
    "configurable": {
        "thread_id": "user-123",
        "actor_id": "my-agent"  # Required for AgentCore
    }
}
result = graph.invoke({"messages": []}, config)
主要特性:
  • Managed infrastructure with no database setup required
  • Automatic scaling and high availability
  • Multi-agent support via actor_id isolation
  • Encryption at rest and in transit

Amazon Bedrock AgentCore Memory Store

Amazon Bedrock AgentCore Memory Store provides long-term memory with semantic search capabilities for LangGraph agents, enabling storage and retrieval of user preferences, facts, and extracted memories across sessions.
from langgraph_checkpoint_aws import AgentCoreMemoryStore

# 初始化长期记忆存储
store = AgentCoreMemoryStore(memory_id="your-memory-id", region_name="us-west-2")

# 在预模型钩子中使用以保存和检索记忆
def pre_model_hook(state, config, *, store):
    actor_id = config["configurable"]["actor_id"]
    thread_id = config["configurable"]["thread_id"]
    namespace = (actor_id, thread_id)

    # 保存消息
    store.put(namespace, str(uuid.uuid4()), {"message": msg})

    # 搜索相关记忆
    results = store.search(("preferences", actor_id), query="user preferences", limit=5)
    return {"model_input_messages": state["messages"]}

回调

Bedrock token usage

from langchain_community.callbacks.bedrock_anthropic_callback import BedrockAnthropicTokenUsageCallbackHandler

SageMaker tracking

Amazon SageMaker 是一项完全托管的服务 that is used to quickly and easily build, train and deploy machine learning (ML) models.
Amazon SageMaker Experiments is a capability of Amazon SageMaker that lets you organize, track, compare and evaluate ML experiments and model versions.
我们需要安装几个 Python 库。
pip install google-search-results sagemaker
查看使用示例.
from langchain_community.callbacks import SageMakerCallbackHandler

Amazon Comprehend moderation chain

Amazon Comprehend is a natural-language processing (NLP) service that uses machine learning to uncover valuable insights and connections in text.
我们需要安装 boto3 and nltk 库。
pip install boto3 nltk
查看使用示例.
from langchain_experimental.comprehend_moderation import AmazonComprehendModerationChain

运行时

Amazon Bedrock AgentCore Runtime

Amazon Bedrock AgentCore Runtime provides managed, serverless execution for LangGraph agents with built-in observability, automatic scaling, and seamless integration with other AgentCore services.
pip install bedrock-agentcore
from bedrock_agentcore.runtime import BedrockAgentCoreApp

app = BedrockAgentCoreApp()

@app.entrypoint
def agent_invocation(payload, context):
    result = graph.invoke({"messages": [{"role": "user", "content": payload["prompt"]}]})
    return {"result": result["messages"][-1].content}

app.run()
使用 AgentCore CLI 部署:
# 配置你的智能体
agentcore configure

# 部署到 AgentCore 运行时
agentcore launch -e your_agent.py