Vektör paketinde bir vektör dizini oluşturmak için Python SDK V2 ile PutVectorIndex işlemini çağırın.
İzinler
Varsayılan olarak Alibaba Cloud hesaplarının tüm izinleri bulunurken Resource Access Management (RAM) kullanıcılarının ve RAM rollerinin hiçbir izni yoktur. Alibaba Cloud hesabı veya bir yönetici, RAM ilkesi veya paket ilkesi aracılığıyla izin vermelidir.
|
|
|
|
|
|
|
|
Yöntem tanımı
put_vector_index(request: PutVectorIndexRequest, **kwargs) → PutVectorIndexResult
İstek parametreleri
|
|
|
|
|
|
|
|
Dönüş değerleri
|
|
|
|
|
|
Yöntemin tam tanımı için bkz. put_vector_index.
Örnek kod
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="vector put vector index sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain name that other services can use to access OSS')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account ID.', required=True)
def main():
args = parser.parse_args()
# Load credentials from environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
cfg.account_id = args.account_id
cfg.use_internal_endpoint = True # To access the service over the public network, set this parameter to False or remove this line.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
vector_client = oss_vectors.Client(cfg)
result = vector_client.put_vector_index(oss_vectors.models.PutVectorIndexRequest(
bucket=args.bucket,
index_name=args.index_name,
dimension=512,
data_type='float32',
distance_metric='euclidean',
metadata={"nonFilterableMetadataKeys": ["key1", "key2"]}
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
if __name__ == "__main__":
main()
Referanslar
Tam örnek kod için bkz. put_vector_index.py.