Knowledge connectors complement defined intents. They parse knowledge documents (for example, FAQs or articles) to find automated responses. To configure them, you define one or more knowledge bases, which are collections of knowledge documents.
You can enable knowledge bases for your agent, so all detect intent requests can find automated responses using your knowledge bases. Alternatively, you can specify one or more knowledge bases in your individual detect intent requests.
It is common for an agent using knowledge connectors to also use defined intents. Knowledge connectors offer less response precision and control than intents. You should define your intents to handle complex user requests, and let knowledge connectors handle simple requests.
For a list of supported languages, see the Knowledge Connectors column in the languages reference.
Limitations
The knowledge connectors feature is only available for the global
region.
Enable beta features
Ensure that beta features are enabled:
- Go to the Dialogflow ES console.
- Select an agent.
- Click the settings settings button next to the agent's name.
- Scroll down while on the General tab and ensure that Beta Features is enabled.
- If you have made changes, click Save.
Create a knowledge base and document
Follow the instructions in the knowledge bases how-to to create a knowledge base and document.
Settings for knowledge connectors
You can enable or disable knowledge bases for your agent. Enabled knowledge bases will be considered for all intent matching requests that do not specify knowledge bases. To enable or disable knowledge bases:
- Go to the Dialogflow ES console.
- Select an agent.
- Click Knowledge in the left sidebar menu.
- Select one or more knowledge bases from the list.
- Click Enable or Disable.
When an end-user expression also matches an intent, you can specify how strongly you prefer knowledge results:
- Scroll down to the Adjust Knowledge Results Preference section.
- Adjust the slider from weaker (preference given to intent) to stronger (preference given to knowledge). For more information, see Detect intent responses below.
Configure responses
By default, a knowledge base is configured with a single default text response populated with the best matching knowledge answer. You can change this response and add rich response messages. Knowledge responses may contain up to three answers per knowledge base, and you can reference these answers in your configured responses. To add responses:
- From the Knowledge page, click your knowledge base name.
- Scroll down to the Responses section and add responses as desired:
- When defining the first response,
use
$Knowledge.Question[1]
and$Knowledge.Answer[1]
where you want the question and answer to be supplied. - The index for
$Knowledge.Question
and$Knowledge.Answer
starts at 1, so increase this index when adding more responses.
- When defining the first response,
use
- Click Save once you are done editing.
When defining responses, you should consider these points:
- If the number of defined responses is greater than the number N of knowledge connector response matches, only N responses will be returned.
- Given that the accuracy could be lower than matching explicitly defined intents, we recommend returning three responses to your users when possible.
Example:
Detect intent with knowledge base
When making a detect intent request, you can specify one or more knowledge bases for a possible response. Explicitly supplying knowledge bases in a request overrides the settings for enabled and disabled knowledge bases.
The samples below show you how to
use the Dialogflow Console, REST API (including command line),
or client libraries to detect intent.
To use the API, call the detectIntent
method on the
Sessions
type.
Web UI
You can interact with the agent and receive knowledge connector responses via the Dialogflow simulator:- Follow the steps above to enable a knowledge base.
- Follow the steps above to define responses.
- Type "How do I sign up?" in the simulator.
REST
Call thedetectIntent
method on the
Sessions
type and specify the knowledge base in the queryParams
field.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your GCP project ID
- KNOWLEDGE_BASE_ID: your knowledge base ID
HTTP method and URL:
POST https://dialogflow.googleapis.com/v2beta1/projects/PROJECT_ID/agent/sessions/123456789:detectIntent
Request JSON body:
{ "queryInput": { "text": { "text": "How do I sign up?", "languageCode": "en-US" } }, "queryParams": { "knowledgeBaseNames": ["projects/PROJECT_ID/knowledgeBases/KNOWLEDGE_BASE_ID"] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ ... "queryResult": { "queryText": "How do I sign up?", "parameters": {}, "allRequiredParamsPresent": true, "fulfillmentText": "Sign up for Cloud Storage by turning on the Cloud Storage service in the Google Cloud Platform Console.", "intent": { "name": "projects/my-gcp-project/agent/intents/487c7242-a769-408a-a339-47b95e10dac4", "displayName": "Knowledge.KnowledgeBase.MzkzNTAyMDE3NDQxNDk3MDg4MA" }, "intentDetectionConfidence": 0.99371547, "languageCode": "en-us", "knowledgeAnswers": { "answers": [ { "answer": "Sign up for Cloud Storage by turning on the Cloud Storage service in the Google Cloud Platform Console.", "matchConfidenceLevel": "HIGH", "matchConfidence": 0.99371547 }, { "answer": "Certain types of content are not allowed on this service; please refer to the Terms of Services and Platform Policies for details. If you believe a piece of content is in violation of our policies, report it here (select See more products, then Google Cloud Storage and Cloud Bigtable).", "matchConfidenceLevel": "LOW", "matchConfidence": 0.0012244871 }, { "answer": "From the Cloud Storage documentation click \"Send feedback\" near the top right of the page. This will open a feedback form. Your comments will be reviewed by the Cloud Storage team.", "matchConfidenceLevel": "LOW", "matchConfidence": 0.0011537358 } ] } } }
Java
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Detect intent responses
The response for the
Sessions
type detectIntent
method is a DetectIntentResponse
.
Multiple factors affect how response fields are populated.
If a defined intent and a knowledge base are both potential matches,
the match confidence of each and the knowledge results preference
(see Settings for knowledge connectors)
are used to determine which match is the selected match.
The selected match is populated in the DetectIntentResponse.queryResult
field,
and other potential matches are populated in the DetectIntentResponse.alternativeQueryResults
field.
Both of these fields contain QueryResult
messages.
If a knowledge base provides a potential match:
QueryResult.knowledgeAnswers
is populated with a list of potential knowledge answers ordered by decreasing match confidence.- If rich responses have been defined for the knowledge base,
QueryResult.fulfillmentMessages
is populated with rich response messages.
When performing a detect intent request,
it is possible for the knowledge query to fail.
When this happens, defined intents will be selected,
so the overall detect intent request will not fail.
You can find knowledge query error information in the DetectIntentResponse.alternativeQueryResults[i].diagnosticInfo
field.
Manage knowledge bases
To learn more about managing knowledge bases, see Manage knowledge bases.