@Generated(value="by gapic-generator") @BetaApi public class KnowledgeBasesClient extends Object implements 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.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
createKnowledgeBase(com.google.cloud.dialogflow.v2beta1.CreateKnowledgeBaseRequest request)
Creates a knowledge base.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
createKnowledgeBase(com.google.cloud.dialogflow.v2beta1.ProjectName parent,
com.google.cloud.dialogflow.v2beta1.KnowledgeBase knowledgeBase)
Creates a knowledge base.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
createKnowledgeBase(String parent,
com.google.cloud.dialogflow.v2beta1.KnowledgeBase knowledgeBase)
Creates a knowledge base.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.CreateKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.KnowledgeBase> |
createKnowledgeBaseCallable()
Creates a knowledge base.
|
void |
deleteKnowledgeBase(com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest request)
Deletes the specified knowledge base.
|
void |
deleteKnowledgeBase(com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName name)
Deletes the specified knowledge base.
|
void |
deleteKnowledgeBase(String name)
Deletes the specified knowledge base.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest,Empty> |
deleteKnowledgeBaseCallable()
Deletes the specified knowledge base.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
getKnowledgeBase(com.google.cloud.dialogflow.v2beta1.GetKnowledgeBaseRequest request)
Retrieves the specified knowledge base.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
getKnowledgeBase(com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName name)
Retrieves the specified knowledge base.
|
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
getKnowledgeBase(String name)
Retrieves the specified knowledge base.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.GetKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.KnowledgeBase> |
getKnowledgeBaseCallable()
Retrieves the specified knowledge base.
|
KnowledgeBasesSettings |
getSettings() |
KnowledgeBasesStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
listKnowledgeBases(com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest request)
Returns the list of all knowledge bases of the specified agent.
|
KnowledgeBasesClient.ListKnowledgeBasesPagedResponse |
listKnowledgeBases(com.google.cloud.dialogflow.v2beta1.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.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest,com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesResponse> |
listKnowledgeBasesCallable()
Returns the list of all knowledge bases of the specified agent.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest,KnowledgeBasesClient.ListKnowledgeBasesPagedResponse> |
listKnowledgeBasesPagedCallable()
Returns the list of all knowledge bases of the specified agent.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.cloud.dialogflow.v2beta1.KnowledgeBase |
updateKnowledgeBase(com.google.cloud.dialogflow.v2beta1.UpdateKnowledgeBaseRequest request)
Updates the specified knowledge base.
|
UnaryCallable<com.google.cloud.dialogflow.v2beta1.UpdateKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.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(com.google.cloud.dialogflow.v2beta1.ProjectName parent)
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>`.ApiException
- if the remote call failspublic final KnowledgeBasesClient.ListKnowledgeBasesPagedResponse listKnowledgeBases(String parent)
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>`.ApiException
- if the remote call failspublic final KnowledgeBasesClient.ListKnowledgeBasesPagedResponse listKnowledgeBases(com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest request)
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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest,KnowledgeBasesClient.ListKnowledgeBasesPagedResponse> listKnowledgeBasesPagedCallable()
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 UnaryCallable<com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesRequest,com.google.cloud.dialogflow.v2beta1.ListKnowledgeBasesResponse> listKnowledgeBasesCallable()
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 com.google.cloud.dialogflow.v2beta1.KnowledgeBase getKnowledgeBase(com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName name)
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>`.ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2beta1.KnowledgeBase getKnowledgeBase(String name)
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>`.ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2beta1.KnowledgeBase getKnowledgeBase(com.google.cloud.dialogflow.v2beta1.GetKnowledgeBaseRequest request)
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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2beta1.GetKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.KnowledgeBase> getKnowledgeBaseCallable()
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 com.google.cloud.dialogflow.v2beta1.KnowledgeBase createKnowledgeBase(com.google.cloud.dialogflow.v2beta1.ProjectName parent, com.google.cloud.dialogflow.v2beta1.KnowledgeBase knowledgeBase)
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.ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2beta1.KnowledgeBase createKnowledgeBase(String parent, com.google.cloud.dialogflow.v2beta1.KnowledgeBase knowledgeBase)
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.ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2beta1.KnowledgeBase createKnowledgeBase(com.google.cloud.dialogflow.v2beta1.CreateKnowledgeBaseRequest request)
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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2beta1.CreateKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.KnowledgeBase> createKnowledgeBaseCallable()
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(com.google.cloud.dialogflow.v2beta1.KnowledgeBaseName name)
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>`.ApiException
- if the remote call failspublic final void deleteKnowledgeBase(String name)
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>`.ApiException
- if the remote call failspublic final void deleteKnowledgeBase(com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest request)
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.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2beta1.DeleteKnowledgeBaseRequest,Empty> deleteKnowledgeBaseCallable()
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 com.google.cloud.dialogflow.v2beta1.KnowledgeBase updateKnowledgeBase(com.google.cloud.dialogflow.v2beta1.UpdateKnowledgeBaseRequest request)
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
UpdateKnowledgeBaseRequest request = UpdateKnowledgeBaseRequest.newBuilder().build();
KnowledgeBase response = knowledgeBasesClient.updateKnowledgeBase(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2beta1.UpdateKnowledgeBaseRequest,com.google.cloud.dialogflow.v2beta1.KnowledgeBase> updateKnowledgeBaseCallable()
Sample code:
try (KnowledgeBasesClient knowledgeBasesClient = KnowledgeBasesClient.create()) {
UpdateKnowledgeBaseRequest request = UpdateKnowledgeBaseRequest.newBuilder().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 BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.