@Generated(value="by gapic-generator") @BetaApi public class KnowledgeBasesClient extends Object implements com.google.api.gax.core.BackgroundResource
Allows users to setup and maintain knowledge bases with their knowledge data.
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 (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
KnowledgeBase response = knowledgeBasesClient.getKnowledgeBase(name);
}
Note: close() needs to be called on the knowledgeBasesClient 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:
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 KnowledgeBasesSettings to create(). For example:
To customize credentials:
KnowledgeBasesSettings knowledgeBasesSettings =
KnowledgeBasesSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
KnowledgeBasesClient knowledgeBasesClient =
KnowledgeBasesClient.create(knowledgeBasesSettings);
To customize the endpoint:
KnowledgeBasesSettings knowledgeBasesSettings =
KnowledgeBasesSettings.newBuilder().setEndpoint(myEndpoint).build();
KnowledgeBasesClient knowledgeBasesClient =
KnowledgeBasesClient.create(knowledgeBasesSettings);
Modifier and Type | Class and Description |
---|---|
static class |
KnowledgeBasesClient.ListKnowledgeBasesFixedSizeCollection |
static class |
KnowledgeBasesClient.ListKnowledgeBasesPage |
static class |
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
KnowledgeBasesClient(KnowledgeBasesSettings settings)
Constructs an instance of KnowledgeBasesClient, using the given settings.
|
protected |
KnowledgeBasesClient(KnowledgeBasesStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static KnowledgeBasesClient |
create()
Constructs an instance of KnowledgeBasesClient with default settings.
|
static KnowledgeBasesClient |
create(KnowledgeBasesSettings settings)
Constructs an instance of KnowledgeBasesClient, using the given settings.
|
static KnowledgeBasesClient |
create(KnowledgeBasesStub stub)
Constructs an instance of KnowledgeBasesClient, using the given stub for making calls.
|
KnowledgeBase |
createKnowledgeBase(CreateKnowledgeBaseRequest request)
Creates a knowledge base.
|
KnowledgeBase |
createKnowledgeBase(ProjectName parent,
KnowledgeBase knowledgeBase)
Creates a knowledge base.
|
KnowledgeBase |
createKnowledgeBase(String parent,
KnowledgeBase knowledgeBase)
Creates a knowledge base.
|
com.google.api.gax.rpc.UnaryCallable<CreateKnowledgeBaseRequest,KnowledgeBase> |
createKnowledgeBaseCallable()
Creates a knowledge base.
|
void |
deleteKnowledgeBase(DeleteKnowledgeBaseRequest request)
Deletes the specified knowledge base.
|
void |
deleteKnowledgeBase(KnowledgeBaseName name)
Deletes the specified knowledge base.
|
void |
deleteKnowledgeBase(String name)
Deletes the specified knowledge base.
|
com.google.api.gax.rpc.UnaryCallable<DeleteKnowledgeBaseRequest,Empty> |
deleteKnowledgeBaseCallable()
Deletes the specified knowledge base.
|
KnowledgeBase |
getKnowledgeBase(GetKnowledgeBaseRequest request)
Retrieves the specified knowledge base.
|
KnowledgeBase |
getKnowledgeBase(KnowledgeBaseName name)
Retrieves the specified knowledge base.
|
KnowledgeBase |
getKnowledgeBase(String name)
Retrieves the specified knowledge base.
|
com.google.api.gax.rpc.UnaryCallable<GetKnowledgeBaseRequest,KnowledgeBase> |
getKnowledgeBaseCallable()
Retrieves the specified knowledge base.
|
KnowledgeBasesSettings |
getSettings() |
KnowledgeBasesStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
listKnowledgeBases(ListKnowledgeBasesRequest request)
Returns the list of all knowledge bases of the specified agent.
|
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
listKnowledgeBases(ProjectName parent)
Returns the list of all knowledge bases of the specified agent.
|
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
listKnowledgeBases(String parent)
Returns the list of all knowledge bases of the specified agent.
|
com.google.api.gax.rpc.UnaryCallable<ListKnowledgeBasesRequest,ListKnowledgeBasesResponse> |
listKnowledgeBasesCallable()
Returns the list of all knowledge bases of the specified agent.
|
com.google.api.gax.rpc.UnaryCallable<ListKnowledgeBasesRequest,KnowledgeBasesClient.ListKnowledgeBasesPagedResponse> |
listKnowledgeBasesPagedCallable()
Returns the list of all knowledge bases of the specified agent.
|
void |
shutdown() |
void |
shutdownNow() |
KnowledgeBase |
updateKnowledgeBase(KnowledgeBase knowledgeBase)
Updates the specified knowledge base.
|
KnowledgeBase |
updateKnowledgeBase(UpdateKnowledgeBaseRequest request)
Updates the specified knowledge base.
|
com.google.api.gax.rpc.UnaryCallable<UpdateKnowledgeBaseRequest,KnowledgeBase> |
updateKnowledgeBaseCallable()
Updates the specified knowledge base.
|
protected KnowledgeBasesClient(KnowledgeBasesSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected KnowledgeBasesClient(KnowledgeBasesStub stub)
public static final KnowledgeBasesClient create() throws IOException
IOException
public static final KnowledgeBasesClient create(KnowledgeBasesSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final KnowledgeBasesClient create(KnowledgeBasesStub stub)
public final KnowledgeBasesSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public KnowledgeBasesStub getStub()
public final KnowledgeBasesClient.ListKnowledgeBasesPagedResponse listKnowledgeBases(ProjectName parent)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (KnowledgeBase element : knowledgeBasesClient.listKnowledgeBases(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The project to list of knowledge bases for. Format:
`projects/<Project ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBasesClient.ListKnowledgeBasesPagedResponse listKnowledgeBases(String parent)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
for (KnowledgeBase element : knowledgeBasesClient.listKnowledgeBases(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The project to list of knowledge bases for. Format:
`projects/<Project ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBasesClient.ListKnowledgeBasesPagedResponse listKnowledgeBases(ListKnowledgeBasesRequest request)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListKnowledgeBasesRequest request = ListKnowledgeBasesRequest.newBuilder()
.setParent(parent.toString())
.build();
for (KnowledgeBase element : knowledgeBasesClient.listKnowledgeBases(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListKnowledgeBasesRequest,KnowledgeBasesClient.ListKnowledgeBasesPagedResponse> listKnowledgeBasesPagedCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListKnowledgeBasesRequest request = ListKnowledgeBasesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListKnowledgeBasesPagedResponse> future = knowledgeBasesClient.listKnowledgeBasesPagedCallable().futureCall(request);
// Do something
for (KnowledgeBase element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListKnowledgeBasesRequest,ListKnowledgeBasesResponse> listKnowledgeBasesCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
ListKnowledgeBasesRequest request = ListKnowledgeBasesRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListKnowledgeBasesResponse response = knowledgeBasesClient.listKnowledgeBasesCallable().call(request);
for (KnowledgeBase element : response.getKnowledgeBasesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final KnowledgeBase getKnowledgeBase(KnowledgeBaseName name)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
KnowledgeBase response = knowledgeBasesClient.getKnowledgeBase(name);
}
name
- Required. The name of the knowledge base to retrieve. Format `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBase getKnowledgeBase(String name)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
KnowledgeBase response = knowledgeBasesClient.getKnowledgeBase(name.toString());
}
name
- Required. The name of the knowledge base to retrieve. Format `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBase getKnowledgeBase(GetKnowledgeBaseRequest request)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
GetKnowledgeBaseRequest request = GetKnowledgeBaseRequest.newBuilder()
.setName(name.toString())
.build();
KnowledgeBase response = knowledgeBasesClient.getKnowledgeBase(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetKnowledgeBaseRequest,KnowledgeBase> getKnowledgeBaseCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
GetKnowledgeBaseRequest request = GetKnowledgeBaseRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<KnowledgeBase> future = knowledgeBasesClient.getKnowledgeBaseCallable().futureCall(request);
// Do something
KnowledgeBase response = future.get();
}
public final KnowledgeBase createKnowledgeBase(ProjectName parent, KnowledgeBase knowledgeBase)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
KnowledgeBase response = knowledgeBasesClient.createKnowledgeBase(parent, knowledgeBase);
}
parent
- Required. The project to create a knowledge base for. Format:
`projects/<Project ID>`.knowledgeBase
- Required. The knowledge base to create.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBase createKnowledgeBase(String parent, KnowledgeBase knowledgeBase)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
KnowledgeBase response = knowledgeBasesClient.createKnowledgeBase(parent.toString(), knowledgeBase);
}
parent
- Required. The project to create a knowledge base for. Format:
`projects/<Project ID>`.knowledgeBase
- Required. The knowledge base to create.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBase createKnowledgeBase(CreateKnowledgeBaseRequest request)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
CreateKnowledgeBaseRequest request = CreateKnowledgeBaseRequest.newBuilder()
.setParent(parent.toString())
.setKnowledgeBase(knowledgeBase)
.build();
KnowledgeBase response = knowledgeBasesClient.createKnowledgeBase(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<CreateKnowledgeBaseRequest,KnowledgeBase> createKnowledgeBaseCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
ProjectName parent = ProjectName.of("[PROJECT]");
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
CreateKnowledgeBaseRequest request = CreateKnowledgeBaseRequest.newBuilder()
.setParent(parent.toString())
.setKnowledgeBase(knowledgeBase)
.build();
ApiFuture<KnowledgeBase> future = knowledgeBasesClient.createKnowledgeBaseCallable().futureCall(request);
// Do something
KnowledgeBase response = future.get();
}
public final void deleteKnowledgeBase(KnowledgeBaseName name)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
knowledgeBasesClient.deleteKnowledgeBase(name);
}
name
- Required. The name of the knowledge base to delete. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteKnowledgeBase(String name)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
knowledgeBasesClient.deleteKnowledgeBase(name.toString());
}
name
- Required. The name of the knowledge base to delete. Format: `projects/<Project
ID>/knowledgeBases/<Knowledge Base ID>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void deleteKnowledgeBase(DeleteKnowledgeBaseRequest request)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
DeleteKnowledgeBaseRequest request = DeleteKnowledgeBaseRequest.newBuilder()
.setName(name.toString())
.build();
knowledgeBasesClient.deleteKnowledgeBase(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<DeleteKnowledgeBaseRequest,Empty> deleteKnowledgeBaseCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBaseName name = KnowledgeBaseName.of("[PROJECT]", "[KNOWLEDGE_BASE]");
DeleteKnowledgeBaseRequest request = DeleteKnowledgeBaseRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Void> future = knowledgeBasesClient.deleteKnowledgeBaseCallable().futureCall(request);
// Do something
future.get();
}
public final KnowledgeBase updateKnowledgeBase(KnowledgeBase knowledgeBase)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
KnowledgeBase response = knowledgeBasesClient.updateKnowledgeBase(knowledgeBase);
}
knowledgeBase
- Required. The knowledge base to update.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final KnowledgeBase updateKnowledgeBase(UpdateKnowledgeBaseRequest request)
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
UpdateKnowledgeBaseRequest request = UpdateKnowledgeBaseRequest.newBuilder()
.setKnowledgeBase(knowledgeBase)
.build();
KnowledgeBase response = knowledgeBasesClient.updateKnowledgeBase(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<UpdateKnowledgeBaseRequest,KnowledgeBase> updateKnowledgeBaseCallable()
Note: The `projects.agent.knowledgeBases` resource is deprecated; only use `projects.knowledgeBases`.
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
KnowledgeBase knowledgeBase = KnowledgeBase.newBuilder().build();
UpdateKnowledgeBaseRequest request = UpdateKnowledgeBaseRequest.newBuilder()
.setKnowledgeBase(knowledgeBase)
.build();
ApiFuture<KnowledgeBase> future = knowledgeBasesClient.updateKnowledgeBaseCallable().futureCall(request);
// Do something
KnowledgeBase response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.