Skip to main content

启用 blob 存储

默认情况下,LangSmith 将运行输入、输出、错误、清单、额外内容和事件存储在 ClickHouse 中。如果愿意,可以改为将此信息存储在 Blob 存储中,这有几个显著的好处:

  1. 在高跟踪环境中,输入、输出、错误、清单、额外内容和事件可能会使数据库的大小膨胀。
  2. 如果使用 LangSmith 托管 ClickHouse,则可能需要将敏感信息存储在环境中的 blob 存储中。 为了缓解这种情况,LangSmith 支持将运行输入、输出、错误、清单、额外内容、事件和附件存储在外部 blob 存储系统中。

要求

注意

Azure Blob 存储在 Helm 图表版本 0.8.9 及更高版本的 Beta 版中提供。
在 Beta 版中,不支持删除跟踪项目

  • 访问有效的 blob 存储服务
  • Blob 存储中用于存储数据的 bucket/directory。我们强烈建议为 LangSmith 数据创建单独的存储桶/目录。
    • 如果您使用的是 TTL,则需要设置生命周期策略以删除旧数据。您可以在此处找到有关配置 TTL 的更多信息。这些策略应反映您在 LangSmith 配置中设置的 TTL,否则您可能会遇到数据丢失的情况。 请参阅此处,了解如何为 blob 存储的 TTL 设置生命周期规则。
  • 允许 LangSmith Services 访问存储桶/目录的凭证
    • 您需要为 LangSmith 实例提供访问存储桶/目录所需的凭证。有关更多信息,请阅读下面的身份验证部分
  • 如果使用 S3 或 GCS,则为 Blob 存储服务的 API URL
    • 这将是 LangSmith 用于访问 blob 存储系统的 URL
    • 对于 Amazon S3,这将是 S3 终端节点的 URL。类似:https://s3.amazonaws.comhttps://s3.us-west-1.amazonaws.com如果使用区域终端节点。
    • 对于 Google Cloud Storage,这将是 GCS 端点的 URL。类似:https://storage.googleapis.com

认证

Amazon S3

要对 Amazon S3 进行身份验证,您需要创建一个 IAM 策略,以授予对存储桶的管理员权限。 这将如下所示:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::your-bucket-name",
"arn:aws:s3:::your-bucket-name/*"
]
}
]
}

拥有正确的策略后,有两种方法可以使用 Amazon S3 进行身份验证:

  1. 服务账户的(推荐)IAM 角色:您可以为 LangSmith 实例创建 IAM 角色,并将策略附加到该角色。然后,您可以向 LangSmith 提供该角色。这是在生产环境中使用 Amazon S3 进行身份验证的推荐方法。
    1. 您需要创建一个附加了策略的 IAM 角色。
    2. 您需要允许 LangSmith 服务账户代入该角色。这langsmith-queue,langsmith-backendlangsmith-platform-backend服务账户需要能够代入该角色。
      服务帐户名称

      如果您使用的是自定义版本名称,则服务帐户名称将有所不同。您可以通过运行kubectl get serviceaccounts在您的集群中。

    3. 您需要向 LangSmith 提供角色 ARN。您可以通过添加eks.amazonaws.com/role-arn: "<role_arn>"注解添加到queue,backendplatform-backend服务。
  2. Access Key 和 Secret Key:您可以向 LangSmith 提供 Access Key 和 Secret Key。这是使用 Amazon S3 进行身份验证的最简单方法。但是,不建议将其用于生产环境,因为它的安全性较低。
    1. 您需要创建一个附加了策略的用户。然后,您可以为该用户预置访问密钥和私有密钥。

Google 云存储

要使用 Google Cloud Storage 进行身份验证,您需要创建一个service account具有访问存储桶所需的权限。

您的服务帐户将需要Storage Adminrole 或具有同等权限的自定义角色。这可以限定为 LangSmith 将使用的存储桶。

拥有预置的服务账户后,您需要生成一个HMAC key对于该服务帐户。此密钥和密钥将用于向 Google Cloud Storage 进行身份验证。

Azure Blob 存储

若要使用 Azure Blob 存储进行身份验证,需要使用以下方法之一 以授予 LangSmith 工作负载访问容器的权限(按优先顺序列出):

  1. 存储帐户和访问密钥
  2. 连接字符串
  3. 工作负载标识(推荐)、托管标识或支持的环境变量DefaultAzureCredential. 当上述任一选项的配置不存在时,这是默认身份验证方法。
    1. 要使用工作负载标识,请添加标签azure.workload.identity/use: truequeue,backendplatform-backend部署。此外,添加azure.workload.identity/client-id注释添加到相应的服务帐户中,该帐户应该是现有 Azure AD 应用程序的客户端 ID 或用户分配的托管身份的客户端 ID。 有关更多详细信息,请参阅 Azure 的文档
注意

某些部署可能需要使用服务 URL 覆盖而不是默认服务 URL (https://<storage_account_name>.blob.core.windows.net/).例如,为了使用不同的 blob 存储域(例如政府或中国),此替代是必需的。

默认情况下,LangSmith 仍会存储 Token 以供在 ClickHouse 中搜索。如果您使用的是 LangSmith 托管的 Clickhouse,则 可能希望关闭此功能,以避免向 ClickHouse 发送潜在的敏感信息。可以在 Blob 存储配置中执行此作。

配置

创建存储桶并获取必要的凭据后,您可以将 LangSmith 配置为使用 blob 存储系统。


config:
blobStorage:
enabled: true
engine: "S3" # Or "Azure"
chSearchEnabled: true # Set to false if you want to disable CH search (Recommended for LangSmith Managed Clickhouse)
bucketName: "your-bucket-name"
apiURL: "Your connection url"
accessKey: "Your access key" # Optional. Only required if using S3 access key and secret key
accessKeySecret: "Your access key secret" # Optional. Only required if using access key and secret key
# The following blob storage configuration values are for Azure and require blobStorage.engine = "Azure". Omit otherwise.
azureStorageAccountName: "Your storage account name" # Optional. Only required if using storage account and access key.
azureStorageAccountKey: "Your storage account access key" # Optional. Only required if using storage account and access key.
azureStorageContainerName: "your-container-name" # Required
azureStorageConnectionString: "" # Optional.
azureStorageServiceUrlOverride: "" # Optional

backend: # Optional, only required if using IAM role for service account on AWS or workload identity on AKS
deployment: # Azure only
labels:
azure.workload.identity/use: true
serviceAccount:
annotations:
azure.workload.identity/client-id: "<client_id>" # Azure only
eks.amazonaws.com/role-arn: "<role_arn>" # AWS only

platformBackend: # Optional, only required if using IAM role for service account on AWS or workload identity on AKS
deployment: # Azure only
labels:
azure.workload.identity/use: true
serviceAccount:
annotations:
azure.workload.identity/client-id: "<client_id>" # Azure only
eks.amazonaws.com/role-arn: "<role_arn>" # AWS only

queue: # Optional, only required if using IAM role for service account on AWS or workload identity on AKS
deployment: # Azure only
labels:
azure.workload.identity/use: true
serviceAccount:
annotations:
azure.workload.identity/client-id: "<client_id>" # Azure only
eks.amazonaws.com/role-arn: "<role_arn>" # AWS only
使用现有密钥

如果使用访问密钥和密钥,您还可以提供包含身份验证信息的现有 Kubernetes 密钥。 建议直接在配置中提供访问密钥和密钥。 请参阅生成的密钥模板,了解预期的密钥。

TTL 配置

如果将 TTL 功能与 LangSmith 一起使用,您还必须为 您的 Blob 存储。存储在 Blob 存储上的跟踪信息存储在特定的前缀路径上,该路径确定数据的 TTL。 延长跟踪的保留期时,其相应的 blob 存储路径会发生变化,以确保它与新的延长保留期匹配。

使用以下 TTL 前缀:

  • ttl_s/:短期 TTL,配置为 14 天。
  • ttl_l/:长期 TTL,配置为 400 天。

如果已在 LangSmith 配置中自定义了 TTL,则需要调整 blob 存储配置中的 TTL 以匹配。

Amazon S3

如果将 S3 用于 blob 存储,则需要设置与 前缀。您可以在 Amazon 文档中找到相关信息。

例如,如果您使用 Terraform 来管理 S3 存储桶,则可以设置如下内容:

  rule {
id = "short-term-ttl"
prefix = "ttl_s/"
enabled = true

expiration {
days = 14
}
}

rule {
id = "long-term-ttl"
prefix = "ttl_l/"
enabled = true

expiration {
days = 400
}
}

Google 云存储

您需要为正在使用的 GCS 存储桶设置生命周期条件。 您可以在 Google 文档 特别是使用 matchesPrefix。

例如,如果您使用 Terraform 来管理 GCS 存储桶,则可以设置如下内容:

  lifecycle_rule {
condition {
age = 14
matches_prefix = ["ttl_s"]
}
action {
type = "Delete"
}
}

lifecycle_rule {
condition {
age = 400
matches_prefix = ["ttl_l"]
}
action {
type = "Delete"
}
}

Azure Blob 存储

您需要在容器上配置生命周期管理策略 以便使与上述前缀匹配的对象过期。

例如,如果使用 Terraform 管理 blob 存储容器,则可以设置如下内容:

resource "azurerm_storage_management_policy" "example" {
storage_account_id = "my-storage-account-id"

rule {
name = "base"
enabled = true
type = "Lifecycle"
filters {
prefix_match = ["my-container/ttl_s"]
blob_types = ["blockBlob"]
}
actions {
base_blob {
delete_after_days_since_creation_greater_than = 14
}
snapshot {
delete_after_days_since_creation_greater_than = 14
}
version {
delete_after_days_since_creation_greater_than = 14
}
}
}

rule {
name = "extended"
enabled = true
type = "Lifecycle"
filters {
prefix_match = ["my-container/ttl_l"]
blob_types = ["blockBlob"]
}
actions {
base_blob {
delete_after_days_since_creation_greater_than = 400
}
snapshot {
delete_after_days_since_creation_greater_than = 400
}
version {
delete_after_days_since_creation_greater_than = 400
}
}
}
}

这个页面有帮助吗?


您可以在 GitHub 上留下详细的反馈。