Dialogflow Knowledge connectors

Knowledge connectors can be configured for your agent either though the web console or using the client library that is available in Java, node.

js & python.

You can also configure from command line.

A sample node.

js script to create a knowledge base would looke like thisconst dialogflow = require('dialogflow').

v2beta1;const client = new dialogflow.

KnowledgeBasesClient();// const projectId = 'ID of GCP project associated with your Dialogflow agent';// const displayName = `your knowledge base display name, e.

g.

myKnowledgeBase`;const formattedParent = client.

projectPath(projectId);const knowledgeBase = { displayName: displayName,};const request = { parent: formattedParent, knowledgeBase: knowledgeBase,};const [result] = await client.

createKnowledgeBase(request);console.

log(`Name: ${result.

name}`);console.

log(`displayName: ${result.

displayName}`);Sample script to add a document to the knowledge base// Imports the Dialogflow client libraryconst dialogflow = require('dialogflow').

v2beta1;// Instantiate a DialogFlow Documents client.

const client = new dialogflow.

DocumentsClient({ projectId: projectId,});// const projectId = 'ID of GCP project associated with your Dialogflow agent';// const knowledgeBaseFullName = `the full path of your knowledge base, e.

g my-Gcloud-project/myKnowledgeBase`;// const documentPath = `path of the document you'd like to add, e.

g.

https://dialogflow.

com/docs/knowledge-connectors`;// const documentName = `displayed name of your document in knowledge base, e.

g.

myDoc`;// const knowledgeTypes = `The Knowledge type of the Document.

e.

g.

FAQ`;// const mimeType = `The mime_type of the Document.

e.

g.

text/csv, text/html,text/plain, text/pdf etc.

`;const request = { parent: knowledgeBaseFullName, document: { knowledgeTypes: [knowledgeTypes], displayName: documentName, contentUri: documentPath, source: `contentUri`, mimeType: mimeType, },};const [operation] = await client.

createDocument(request);const [response] = await operation.

promise();console.

log(`Document created`);console.

log(`Content URI.

${response.

contentUri}`);console.

log(`displayName.

${response.

displayName}`);console.

log(`mimeType.

${response.

mimeType}`);console.

log(`name.

${response.

name}`);console.

log(`source.

${response.

source}`);To create knowledge base from the web console, login to dialogflow & go to the knowledge tab.

The UX is fairly self explanatory.

When to use ?.If you want to convert your FAQ page into a bot, just supplying the url of the FAQ page as a datasource to the knowledge connectors works wonders.

Also, if you have a PRFAQ document that you want to integrate with your bot, knowledge connectors are a great way to do that.

When not to use ?.The feature doesn’t seem to work well with manuals describing step-by-step procedures.

Also, knowledge don’t provide full control like intents do in terms of context, priority of matching queries.

It’s always good to use knowledge connectors to quickly bring up the bot and later convert them to intents to gain full control.

.

. More details

Leave a Reply