Skip to main content
Open on GitHub

AWS

AmazonAWS平台相关的LangChain个集成。

第一方AWS集成可在langchain_aws包中使用。

pip install langchain-aws

此外,在 langchain_community 包中还提供了一些社区集成,这些集成依赖于可选的 boto3

pip install langchain-community boto3

聊天模型

Bedrock Chat

Amazon Bedrock is a fully managed service 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 using the AWS services you are already familiar with.

查看一个 使用示例

from langchain_aws import ChatBedrock
API 参考:ChatBedrock

Bedrock Converse

AWS Bedrock 提供了一个 Converse API ,该API为Bedrock模型提供了一个统一的对话接口。此API目前还不支持自定义模型。你可以查看此处列出的所有 受支持的模型

信息

我们建议不需要使用自定义模型的用户使用Converse API。可以使用 ChatBedrockConverse 进行访问。

查看一个 使用示例

from langchain_aws import ChatBedrockConverse
API 参考:ChatBedrockConverse

LLMs

Amazon Bedrock

查看一个 使用示例

from langchain_aws import BedrockLLM
API 参考:BedrockLLM

AmazonAPI网关

Amazon API Gateway is a fully managed service 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
API 参考:AmazonAPIGateway

Amazon SageMaker 服务端点

Amazon SageMaker is a system that can build, train, and deploy machine learning (ML) models with fully managed infrastructure, tools, and workflows.

我们使用 SageMaker 来托管我们的模型,并将其作为 SageMaker Endpoint 暴露出来。

查看一个 使用示例

from langchain_aws import SagemakerEndpoint
API 参考:SagemakerEndpoint

嵌入模型

Amazon Bedrock

查看一个 使用示例

from langchain_aws import BedrockEmbeddings
API 参考:BedrockEmbeddings

Amazon SageMaker 服务端点

查看一个 使用示例

from langchain_community.embeddings import SagemakerEndpointEmbeddings
from langchain_community.llms.sagemaker_endpoint import ContentHandlerBase

文档加载器

AWS S3 目录和文件

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

AmazonAthena

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
API 参考: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
API 参考: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

在AWS上部署DocumentDB

Amazon DocumentDB(与MongoDB兼容) 是一种快速、可靠且完全托管的数据库服务。Amazon DocumentDB 可让您轻松地在云中设置、操作和扩展与 MongoDB 兼容的数据库。

AWS提供计算、数据库、存储、分析及其他功能的服务。有关AWS服务的概览,请参见使用Amazon网络服务进行云计算

查看一个 使用示例

from langchain_community.vectorstores import DocumentDBVectorSearch

Amazon MemoryDB

Amazon MemoryDB 是一种持久的内存数据库服务,可提供超快的性能。MemoryDB 与 Redis OSS 兼容,这是一种流行的开源数据存储, 使您能够使用相同的灵活且友好的 Redis OSS API 和命令快速构建应用程序,这些 API 和命令是您今天已经使用的。

InMemoryVectorStore 类提供了一个向量存储,用于连接 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,
)
API 参考:InMemoryVectorStore

查看一个 使用示例

检索器

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. It supports 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 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). It helps 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

查看一个 使用示例

存储

AWS DynamoDB

AWS DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.

我们必须配置 AWS CLI

我们需要安装 boto3 库。

pip install boto3

查看一个 使用示例

from langchain_community.chat_message_histories import DynamoDBChatMessageHistory

图表

AmazonNeptune

Amazon Neptune is a high-performance graph analytics and serverless database for superior scalability and availability.

对于下面的Cypher和SPARQL集成,我们需要安装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

AmazonNeptune支持SPARQL

查看一个 使用示例

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

回调

Bedrock token usage

from langchain_community.callbacks.bedrock_anthropic_callback import BedrockAnthropicTokenUsageCallbackHandler

Amazon SageMaker 跟踪

Amazon SageMaker is a fully managed service 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 审核链

Amazon Comprehend is a natural-language processing (NLP) service that uses machine learning to uncover valuable insights and connections in text.

我们需要安装 boto3nltk 库。

pip install boto3 nltk

查看一个 使用示例

from langchain_experimental.comprehend_moderation import AmazonComprehendModerationChain