A vector index organizes and retrieves vector data. You can call the PutVectorIndex operation by using the OSS Java SDK V2 to create a vector index in a vector bucket.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default. The Alibaba Cloud account owner or an administrator must grant the required permissions by using a RAM policy or a bucket policy.
|
API |
Actions |
Description |
|
PutVectorIndex |
oss:PutVectorIndex |
Creates a vector index. |
Sample code
import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexRequest;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexResult;
public class PutVectorIndexSample {
public static void main(String[] args) throws Exception {
CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
.region("cn-hangzhou")
.accountId("1234567890")
.credentialsProvider(provider)
.build()) {
PutVectorIndexRequest request = PutVectorIndexRequest.newBuilder()
.bucket("examplebucket")
.indexName("exampleindex")
.dataType("float32")
.dimension(3)
.distanceMetric("cosine")
.build();
PutVectorIndexResult result = client.putVectorIndex(request);
System.out.printf("status code: %d, request id: %s%n", result.statusCode(), result.requestId());
}
}
}
Related documents
-
For the synchronous sample code, see PutVectorIndex.java.
-
For the asynchronous sample code, see PutVectorIndexAsync.java.
该文章对您有帮助吗?