
关于
Azure AI Projects Java SDK。用于 Azure AI Foundry 项目管理的高级 SDK,包括连接、数据集、索引和评估。
name: azure-ai-projects-java description: Azure AI Projects SDK for Java。用于 Azure AI Foundry 项目管理的高级 SDK,包括连接、数据集、索引和评估。 risk: unknown source: community date_added: '2026-02-27'
Azure AI Projects SDK for Java
用于 Azure AI Foundry 项目管理的高级 SDK,可访问连接、数据集、索引和评估。
安装
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-projects</artifactId>
<version>1.0.0-beta.1</version>
</dependency>
环境变量
PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
认证
import com.azure.ai.projects.AIProjectClientBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
AIProjectClientBuilder builder = new AIProjectClientBuilder()
.endpoint(System.getenv("PROJECT_ENDPOINT"))
.credential(new DefaultAzureCredentialBuilder().build());
客户端层级结构
SDK 提供多个子客户端用于不同操作:
| 客户端 | 用途 |
|--------|------|
| ConnectionsClient | 枚举已连接的 Azure 资源 |
| DatasetsClient | 上传文档和管理数据集 |
| DeploymentsClient | 枚举 AI 模型部署 |
| IndexesClient | 创建和管理搜索索引 |
| EvaluationsClient | 运行 AI 模型评估 |
| EvaluatorsClient | 管理评估器配置 |
| SchedulesClient | 管理计划任务 |
// 从 builder 构建子客户端
ConnectionsClient connectionsClient = builder.buildConnectionsClient();
DatasetsClient datasetsClient = builder.buildDatasetsClient();
DeploymentsClient deploymentsClient = builder.buildDeploymentsClient();
IndexesClient indexesClient = builder.buildIndexesClient();
EvaluationsClient evaluationsClient = builder.buildEvaluationsClient();
核心操作
列举连接
import com.azure.ai.projects.models.Connection;
import com.azure.core.http.rest.PagedIterable;
PagedIterable<Connection> connections = connectionsClient.listConnections();
for (Connection connection : connections) {
System.out.println("Name: " + connection.getName());
System.out.println("Type: " + connection.getType());
System.out.println("Credential Type: " + connection.getCredentials().getType());
}
列举索引
indexesClient.listLatest().forEach(index -> {
System.out.println("Index name: " + index.getName());
System.out.println("Version: " + index.getVersion());
System.out.println("Description: " + index.getDescription());
});
创建或更新索引
import com.azure.ai.projects.models.AzureAISearchIndex;
import com.azure.ai.projects.models.Index;
String indexName = "my-index";
String indexVersion = "1.0";
String searchConnectionName = System.getenv("AI_SEARCH_CONNECTION_NAME");
String searchIndexName = System.getenv("AI_SEARCH_INDEX_NAME");
Index index = indexesClient.createOrUpdate(
indexName,
indexVersion,
new AzureAISearchIndex()
.setConnectionName(searchConnectionName)
.setIndexName(searchIndexName)
);
System.out.println("Created index: " + index.getName());
访问 OpenAI 评估
SDK 暴露 OpenAI 官方 SDK 用于评估:
import com.openai.services.EvalService;
EvalService evalService = evaluationsClient.getOpenAIClient();
// 直接使用 OpenAI 评估 API
最佳实践
- 使用 DefaultAzureCredential 进行生产环境认证
- 复用客户端 builder 高效创建多个子客户端
- 处理分页 使用
PagedIterable列举资源时 - 使用环境变量 存储连接名称和配置
- 检查连接类型 访问凭据前先确认
错误处理
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceNotFoundException;
try {
Index index = indexesClient.get(indexName, version);
} catch (ResourceNotFoundException e) {
System.err.println("Index not found: " + indexName);
} catch (HttpResponseException e) {
System.err.println("Error: " + e.getResponse().getStatusCode());
}
参考链接
| 资源 | URL | |------|-----| | 产品文档 | https://learn.microsoft.com/azure/ai-studio/ | | API 参考 | https://learn.microsoft.com/rest/api/aifoundry/aiprojects/ | | GitHub 源码 | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-projects | | 示例 | https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-projects/src/samples |
何时使用
此技能适用于执行概述中描述的工作流或操作。
限制
- 仅在任务明确匹配上述范围时使用此技能。
- 不要将输出视为特定环境验证、测试或专家审查的替代品。
- 如果缺少必要的输入、权限、安全边界或成功标准,请停下来寻求澄清。