Use Python SDK V2 para llamar a la operación GetVectorIndex y obtener información sobre un índice vectorial específico.
Permisos
Las cuentas de Alibaba Cloud tienen todos los permisos de forma predeterminada. Los usuarios y roles de RAM requieren autorización explícita mediante una RAM policy o una bucket policy.
|
API |
Acción |
Descripción |
|
GetVectorIndex |
|
Obtiene información del índice vectorial. |
Definición del método
get_vector_index(request: GetVectorIndexRequest, **kwargs) → GetVectorIndexResult
Parámetros de solicitud
|
Parámetro |
Tipo |
Descripción |
|
request |
GetVectorIndexRequest |
Parámetros de la solicitud que incluyen el nombre del bucket a consultar y el nombre del índice. Para más información, consulte GetVectorIndexRequest. |
Valores de retorno
|
Tipo |
Descripción |
|
GetVectorIndexResult |
Valor de retorno que contiene información detallada sobre el índice vectorial. Para más información, consulte GetVectorIndexResult. |
Para ver la definición completa del método get_vector_index, consulte get_vector_index.
Código de ejemplo
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors
parser = argparse.ArgumentParser(description="vector get vector index sample")
parser.add_argument('--region', help='The region of the bucket.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain name for accessing 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()
# Use 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 OSS over the public network, set this 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.get_vector_index(oss_vectors.models.GetVectorIndexRequest(
bucket=args.bucket,
index_name=args.index_name,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
if result.index:
print(f'index name: {result.index}')
if __name__ == "__main__":
main()
Referencias
Para consultar el código de ejemplo completo, véase get_vector_index.py.