启用 blob 存储
默认情况下,LangSmith 将运行输入、输出、错误、清单、额外信息和事件存储在 ClickHouse 中。如果您选择,您可以改为将此信息存储在 blob 存储中,这有几个显著的好处
- 在高追踪环境中,输入、输出、错误、清单、额外信息和事件可能会使您的数据库大小膨胀。
- 如果使用 LangSmith Managed ClickHouse,您可能希望将敏感信息存储在位于您环境中的 blob 存储中。为了缓解这种情况,LangSmith 支持将运行输入、输出、错误、清单、额外信息、事件和附件存储在外部 blob 存储系统中。
要求
Azure blob 存储在 Helm chart 版本 0.8.9 及更高版本中以 Beta 版提供。
在 Beta 版期间,不支持从 LangSmith 删除追踪项目。
- 访问有效的 blob 存储服务
- blob 存储中用于存储数据的存储桶/目录。我们强烈建议为 LangSmith 数据创建一个单独的存储桶/目录。
- 允许 LangSmith 服务访问存储桶/目录的凭据
- 您将需要为您的 LangSmith 实例提供必要的凭据以访问存储桶/目录。阅读下面的身份验证部分以获取更多信息。
- 如果使用 S3 或 GCS,则需要您的 blob 存储服务的 API URL
- 这将是 LangSmith 用于访问您的 blob 存储系统的 URL
- 对于 Amazon S3,这将是 S3 端点的 URL。类似于:
https://s3.amazonaws.com
或https://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 进行身份验证
- (推荐)服务账户的 IAM 角色:您可以为您的 LangSmith 实例创建一个 IAM 角色,并将策略附加到该角色。然后,您可以将角色提供给 LangSmith。这是在生产环境中验证 Amazon S3 的推荐方法。
- 您将需要创建一个附加了策略的 IAM 角色。
- 您将需要允许 LangSmith 服务账户承担该角色。
langsmith-queue
、langsmith-backend
和langsmith-platform-backend
服务账户将需要能够承担该角色。服务账户名称如果您使用自定义发布名称,则服务帐户名称将有所不同。您可以通过在集群中运行
kubectl get serviceaccounts
来查找服务帐户名称。 - 您将需要向 LangSmith 提供角色 ARN。您可以通过将
eks.amazonaws.com/role-arn: "<role_arn>"
注释添加到 Helm Chart 安装中的queue
、backend
和platform-backend
服务中来完成此操作。
- 访问密钥和秘密密钥:您可以向 LangSmith 提供访问密钥和秘密密钥。这是使用 Amazon S3 进行身份验证的最简单方法。但是,不建议在生产环境中使用,因为它安全性较低。
- 您将需要创建一个附加了策略的用户。然后,您可以为该用户配置访问密钥和秘密密钥。
Google Cloud Storage
要使用 Google Cloud Storage 进行身份验证,您需要创建一个服务账户
,并具有访问您的存储桶的必要权限。
您的服务账户将需要 Storage Admin
角色或具有等效权限的自定义角色。这可以限定为 LangSmith 将要使用的存储桶。
配置服务账户后,您将需要为该服务账户生成一个 HMAC 密钥
。此密钥和密钥将用于验证 Google Cloud Storage。
Azure Blob Storage
要使用 Azure Blob Storage 进行身份验证,您将需要使用以下方法之一来授予 LangSmith 工作负载访问您的容器的权限(按优先级顺序列出)
- 存储帐户和访问密钥
- 连接字符串
- 工作负载标识(推荐)、托管标识或
DefaultAzureCredential
支持的环境变量。当上述任一选项的配置不存在时,这是默认的身份验证方法。- 要使用工作负载标识,请将标签
azure.workload.identity/use: true
添加到queue
、backend
和platform-backend
部署。此外,将azure.workload.identity/client-id
注释添加到相应的服务帐户,这应该是现有的 Azure AD 应用程序的客户端 ID 或用户分配的托管标识的客户端 ID。有关更多详细信息,请参阅 Azure 的文档。
- 要使用工作负载标识,请将标签
某些部署可能需要使用服务 URL 覆盖而不是默认服务 URL (https://<storage_account_name>.blob.core.windows.net/
) 来进一步自定义连接配置。例如,为了使用不同的 blob 存储域(例如,政府或中国),此覆盖是必要的。
CH 搜索
默认情况下,LangSmith 仍会将用于搜索的令牌存储在 ClickHouse 中。如果您正在使用 LangSmith Managed Clickhouse,您可能希望禁用此功能,以避免将潜在的敏感信息发送到 ClickHouse。您可以在 blob 存储配置中执行此操作。
配置
创建存储桶并获得必要的凭据后,您可以配置 LangSmith 以使用您的 blob 存储系统。
- Helm
- Docker
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
# In your .env file
FF_BLOB_STORAGE_ENABLED=false # Set to true if you want to enable blob storage
BLOB_STORAGE_ENGINE=S3 # Or Azure
BLOB_STORAGE_BUCKET_NAME=langsmith-blob-storage # Required for using S3. Change to your desired blob storage bucket name
BLOB_STORAGE_API_URL=https://s3.us-west-2.amazonaws.com # Change to your desired blob storage API URL
BLOB_STORAGE_ACCESS_KEY=your-access-key # Change to your desired blob storage access key
BLOB_STORAGE_ACCESS_KEY_SECRET=your-access-key-secret # Change to your desired blob storage access key secret
AZURE_STORAGE_ACCOUNT_NAME=your-storage-account-name # Optional. Only required if using storage account and access key.
AZURE_STORAGE_ACCOUNT_KEY=your-storage-account-key # Optional. Only required if using storage account and access key.
AZURE_STORAGE_CONTAINER_NAME=your-container-name # Required for using Azure blob storage. Change to your desired container name
AZURE_STORAGE_CONNECTION_STRING=BlobEndpoint=https://storagesample.blob.core.windows.net;SharedAccessSignature=signature; # Optional.
AZURE_STORAGE_SERVICE_URL_OVERRIDE=https://your.override.domain.net # Optional
如果使用访问密钥和秘密密钥,您还可以提供包含身份验证信息的现有 Kubernetes 密钥。建议使用此方法,而不是直接在配置中提供访问密钥和秘密密钥。有关预期的密钥,请参阅生成的密钥模板。
TTL 配置
如果将 TTL 功能与 LangSmith 一起使用,您还需要为您的 blob 存储配置 TTL 规则。存储在 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 Cloud Storage
您将需要为您正在使用的 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
}
}
}
}