Class IndexServiceClient (2.9.5)

public class IndexServiceClient implements BackgroundResource

Service Description: A service for creating and managing Vertex AI's Index resources.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   IndexName name = IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]");
   Index response = indexServiceClient.getIndex(name);
 }
 

Note: close() needs to be called on the IndexServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

The surface of this class includes several types of Java methods for each of the API's methods:

  1. A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
  2. A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
  3. A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of IndexServiceSettings to create(). For example:

To customize credentials:


 IndexServiceSettings indexServiceSettings =
     IndexServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 IndexServiceClient indexServiceClient = IndexServiceClient.create(indexServiceSettings);
 

To customize the endpoint:


 IndexServiceSettings indexServiceSettings =
     IndexServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 IndexServiceClient indexServiceClient = IndexServiceClient.create(indexServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > IndexServiceClient

Implements

BackgroundResource

Static Methods

create()

public static final IndexServiceClient create()

Constructs an instance of IndexServiceClient with default settings.

Returns
TypeDescription
IndexServiceClient
Exceptions
TypeDescription
IOException

create(IndexServiceSettings settings)

public static final IndexServiceClient create(IndexServiceSettings settings)

Constructs an instance of IndexServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
NameDescription
settingsIndexServiceSettings
Returns
TypeDescription
IndexServiceClient
Exceptions
TypeDescription
IOException

create(IndexServiceStub stub)

public static final IndexServiceClient create(IndexServiceStub stub)

Constructs an instance of IndexServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(IndexServiceSettings).

Parameter
NameDescription
stubIndexServiceStub
Returns
TypeDescription
IndexServiceClient

Constructors

IndexServiceClient(IndexServiceSettings settings)

protected IndexServiceClient(IndexServiceSettings settings)

Constructs an instance of IndexServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
NameDescription
settingsIndexServiceSettings

IndexServiceClient(IndexServiceStub stub)

protected IndexServiceClient(IndexServiceStub stub)
Parameter
NameDescription
stubIndexServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

createIndexAsync(CreateIndexRequest request)

public final OperationFuture<Index,CreateIndexOperationMetadata> createIndexAsync(CreateIndexRequest request)

Creates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   CreateIndexRequest request =
       CreateIndexRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setIndex(Index.newBuilder().build())
           .build();
   Index response = indexServiceClient.createIndexAsync(request).get();
 }
 
Parameter
NameDescription
requestCreateIndexRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Index,CreateIndexOperationMetadata>

createIndexAsync(LocationName parent, Index index)

public final OperationFuture<Index,CreateIndexOperationMetadata> createIndexAsync(LocationName parent, Index index)

Creates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   Index index = Index.newBuilder().build();
   Index response = indexServiceClient.createIndexAsync(parent, index).get();
 }
 
Parameters
NameDescription
parentLocationName

Required. The resource name of the Location to create the Index in. Format: projects/{project}/locations/{location}

indexIndex

Required. The Index to create.

Returns
TypeDescription
OperationFuture<Index,CreateIndexOperationMetadata>

createIndexAsync(String parent, Index index)

public final OperationFuture<Index,CreateIndexOperationMetadata> createIndexAsync(String parent, Index index)

Creates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   Index index = Index.newBuilder().build();
   Index response = indexServiceClient.createIndexAsync(parent, index).get();
 }
 
Parameters
NameDescription
parentString

Required. The resource name of the Location to create the Index in. Format: projects/{project}/locations/{location}

indexIndex

Required. The Index to create.

Returns
TypeDescription
OperationFuture<Index,CreateIndexOperationMetadata>

createIndexCallable()

public final UnaryCallable<CreateIndexRequest,Operation> createIndexCallable()

Creates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   CreateIndexRequest request =
       CreateIndexRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setIndex(Index.newBuilder().build())
           .build();
   ApiFuture<Operation> future = indexServiceClient.createIndexCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<CreateIndexRequest,Operation>

createIndexOperationCallable()

public final OperationCallable<CreateIndexRequest,Index,CreateIndexOperationMetadata> createIndexOperationCallable()

Creates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   CreateIndexRequest request =
       CreateIndexRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setIndex(Index.newBuilder().build())
           .build();
   OperationFuture<Index, CreateIndexOperationMetadata> future =
       indexServiceClient.createIndexOperationCallable().futureCall(request);
   // Do something.
   Index response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<CreateIndexRequest,Index,CreateIndexOperationMetadata>

deleteIndexAsync(DeleteIndexRequest request)

public final OperationFuture<Empty,DeleteOperationMetadata> deleteIndexAsync(DeleteIndexRequest request)

Deletes an Index. An Index can only be deleted when all its DeployedIndexes had been undeployed.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   DeleteIndexRequest request =
       DeleteIndexRequest.newBuilder()
           .setName(IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString())
           .build();
   indexServiceClient.deleteIndexAsync(request).get();
 }
 
Parameter
NameDescription
requestDeleteIndexRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Empty,DeleteOperationMetadata>

deleteIndexAsync(IndexName name)

public final OperationFuture<Empty,DeleteOperationMetadata> deleteIndexAsync(IndexName name)

Deletes an Index. An Index can only be deleted when all its DeployedIndexes had been undeployed.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   IndexName name = IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]");
   indexServiceClient.deleteIndexAsync(name).get();
 }
 
Parameter
NameDescription
nameIndexName

Required. The name of the Index resource to be deleted. Format: projects/{project}/locations/{location}/indexes/{index}

Returns
TypeDescription
OperationFuture<Empty,DeleteOperationMetadata>

deleteIndexAsync(String name)

public final OperationFuture<Empty,DeleteOperationMetadata> deleteIndexAsync(String name)

Deletes an Index. An Index can only be deleted when all its DeployedIndexes had been undeployed.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   String name = IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString();
   indexServiceClient.deleteIndexAsync(name).get();
 }
 
Parameter
NameDescription
nameString

Required. The name of the Index resource to be deleted. Format: projects/{project}/locations/{location}/indexes/{index}

Returns
TypeDescription
OperationFuture<Empty,DeleteOperationMetadata>

deleteIndexCallable()

public final UnaryCallable<DeleteIndexRequest,Operation> deleteIndexCallable()

Deletes an Index. An Index can only be deleted when all its DeployedIndexes had been undeployed.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   DeleteIndexRequest request =
       DeleteIndexRequest.newBuilder()
           .setName(IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString())
           .build();
   ApiFuture<Operation> future = indexServiceClient.deleteIndexCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<DeleteIndexRequest,Operation>

deleteIndexOperationCallable()

public final OperationCallable<DeleteIndexRequest,Empty,DeleteOperationMetadata> deleteIndexOperationCallable()

Deletes an Index. An Index can only be deleted when all its DeployedIndexes had been undeployed.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   DeleteIndexRequest request =
       DeleteIndexRequest.newBuilder()
           .setName(IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString())
           .build();
   OperationFuture<Empty, DeleteOperationMetadata> future =
       indexServiceClient.deleteIndexOperationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
OperationCallable<DeleteIndexRequest,Empty,DeleteOperationMetadata>

getIndex(GetIndexRequest request)

public final Index getIndex(GetIndexRequest request)

Gets an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   GetIndexRequest request =
       GetIndexRequest.newBuilder()
           .setName(IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString())
           .build();
   Index response = indexServiceClient.getIndex(request);
 }
 
Parameter
NameDescription
requestGetIndexRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
Index

getIndex(IndexName name)

public final Index getIndex(IndexName name)

Gets an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   IndexName name = IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]");
   Index response = indexServiceClient.getIndex(name);
 }
 
Parameter
NameDescription
nameIndexName

Required. The name of the Index resource. Format: projects/{project}/locations/{location}/indexes/{index}

Returns
TypeDescription
Index

getIndex(String name)

public final Index getIndex(String name)

Gets an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   String name = IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString();
   Index response = indexServiceClient.getIndex(name);
 }
 
Parameter
NameDescription
nameString

Required. The name of the Index resource. Format: projects/{project}/locations/{location}/indexes/{index}

Returns
TypeDescription
Index

getIndexCallable()

public final UnaryCallable<GetIndexRequest,Index> getIndexCallable()

Gets an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   GetIndexRequest request =
       GetIndexRequest.newBuilder()
           .setName(IndexName.of("[PROJECT]", "[LOCATION]", "[INDEX]").toString())
           .build();
   ApiFuture<Index> future = indexServiceClient.getIndexCallable().futureCall(request);
   // Do something.
   Index response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<GetIndexRequest,Index>

getOperationsClient()

public final OperationsClient getOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
TypeDescription
OperationsClient

getSettings()

public final IndexServiceSettings getSettings()
Returns
TypeDescription
IndexServiceSettings

getStub()

public IndexServiceStub getStub()
Returns
TypeDescription
IndexServiceStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listIndexes(ListIndexesRequest request)

public final IndexServiceClient.ListIndexesPagedResponse listIndexes(ListIndexesRequest request)

Lists Indexes in a Location.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   ListIndexesRequest request =
       ListIndexesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   for (Index element : indexServiceClient.listIndexes(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListIndexesRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
IndexServiceClient.ListIndexesPagedResponse

listIndexes(LocationName parent)

public final IndexServiceClient.ListIndexesPagedResponse listIndexes(LocationName parent)

Lists Indexes in a Location.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   for (Index element : indexServiceClient.listIndexes(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentLocationName

Required. The resource name of the Location from which to list the Indexes. Format: projects/{project}/locations/{location}

Returns
TypeDescription
IndexServiceClient.ListIndexesPagedResponse

listIndexes(String parent)

public final IndexServiceClient.ListIndexesPagedResponse listIndexes(String parent)

Lists Indexes in a Location.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   for (Index element : indexServiceClient.listIndexes(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The resource name of the Location from which to list the Indexes. Format: projects/{project}/locations/{location}

Returns
TypeDescription
IndexServiceClient.ListIndexesPagedResponse

listIndexesCallable()

public final UnaryCallable<ListIndexesRequest,ListIndexesResponse> listIndexesCallable()

Lists Indexes in a Location.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   ListIndexesRequest request =
       ListIndexesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   while (true) {
     ListIndexesResponse response = indexServiceClient.listIndexesCallable().call(request);
     for (Index element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListIndexesRequest,ListIndexesResponse>

listIndexesPagedCallable()

public final UnaryCallable<ListIndexesRequest,IndexServiceClient.ListIndexesPagedResponse> listIndexesPagedCallable()

Lists Indexes in a Location.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   ListIndexesRequest request =
       ListIndexesRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setFilter("filter-1274492040")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setReadMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Index> future = indexServiceClient.listIndexesPagedCallable().futureCall(request);
   // Do something.
   for (Index element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListIndexesRequest,ListIndexesPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

updateIndexAsync(Index index, FieldMask updateMask)

public final OperationFuture<Index,UpdateIndexOperationMetadata> updateIndexAsync(Index index, FieldMask updateMask)

Updates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   Index index = Index.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Index response = indexServiceClient.updateIndexAsync(index, updateMask).get();
 }
 
Parameters
NameDescription
indexIndex

Required. The Index which updates the resource on the server.

updateMaskFieldMask

The update mask applies to the resource. For the FieldMask definition, see google.protobuf.FieldMask.

Returns
TypeDescription
OperationFuture<Index,UpdateIndexOperationMetadata>

updateIndexAsync(UpdateIndexRequest request)

public final OperationFuture<Index,UpdateIndexOperationMetadata> updateIndexAsync(UpdateIndexRequest request)

Updates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   UpdateIndexRequest request =
       UpdateIndexRequest.newBuilder()
           .setIndex(Index.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Index response = indexServiceClient.updateIndexAsync(request).get();
 }
 
Parameter
NameDescription
requestUpdateIndexRequest

The request object containing all of the parameters for the API call.

Returns
TypeDescription
OperationFuture<Index,UpdateIndexOperationMetadata>

updateIndexCallable()

public final UnaryCallable<UpdateIndexRequest,Operation> updateIndexCallable()

Updates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   UpdateIndexRequest request =
       UpdateIndexRequest.newBuilder()
           .setIndex(Index.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Operation> future = indexServiceClient.updateIndexCallable().futureCall(request);
   // Do something.
   Operation response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateIndexRequest,Operation>

updateIndexOperationCallable()

public final OperationCallable<UpdateIndexRequest,Index,UpdateIndexOperationMetadata> updateIndexOperationCallable()

Updates an Index.

Sample code:


 try (IndexServiceClient indexServiceClient = IndexServiceClient.create()) {
   UpdateIndexRequest request =
       UpdateIndexRequest.newBuilder()
           .setIndex(Index.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   OperationFuture<Index, UpdateIndexOperationMetadata> future =
       indexServiceClient.updateIndexOperationCallable().futureCall(request);
   // Do something.
   Index response = future.get();
 }
 
Returns
TypeDescription
OperationCallable<UpdateIndexRequest,Index,UpdateIndexOperationMetadata>