Knowledge Agent
Overview
Knowledge agent is an AMD-based module that can be used with RequireJS. It exports the _gka variable into the local context where it is accessed.
Configuration
_gka.initialize(options) | Examples |
---|---|
Description: Configure the Knowledge agent.
Type: PlainObject
Type: String
Type: String
Type: String
Type: String Sub tenant identifier |
_gka.initialize({
host: 'http://localhost:8080', kbId: 'knowledge' }) |
Knowledge Agent API
Once configuration is complete, the Agent can receive data from the Knowledge API. The _gka variable contains the following interfaces:
Method | Description |
---|---|
Knowledge Base Operations | |
.getKnowledgeBases() | Retrieves list of knowledge bases supported |
.getKnowledgeBaseInfo() | Retrieves information about the particular knowledge base |
.getCategories() | Retrieves list of categories |
.getFullContent() | Retrieves full content of particular document |
FAQ retrival | |
.search() | Executes search for the answer for the given query |
.suggestions() | Provides autocomplete functionality |
.getSimilarContent() | Retrieves similar content for the document provided |
.guessSpelling() | Guess spelling correction for the entered query |
Feedback | |
.noAnswer() | Marks query as the one that do not have valid answer in knowledge base |
.like() | Records user rating for the document within query |
.visit() | Registers viewing the document |
Knowledge Base Operations
_gka.getKnowledgeBases(): Promise | Example |
---|---|
Description: Retrieves information about the particular knowledge base. | _gkn.getKnowledgeBases().done(function(response, status) {
console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
"knowledgebases": [{ "name": "knowledgefaq", "languages": [ "en" ] }, { "name": "the_bank", "languages": [ "en" ] }] } |
_gka.getKnowledgeBaseInfo([options]): Promise | Example |
---|---|
Description: Retrieves information about the knowledge base.
|
_gkn.getKnowledgeBaseInfo().done(function(response, status) {
console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
languages: [ 'en', 'fr', 'de' ] } |
_gka.getCategories(): Promise | Example |
---|---|
Description: Retrieves list of categories. | _gkn.getCategories().done(function(response, status) {
console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
"categories": [{ "id": "Home Mortgage", "name": "Home Mortgage", "count": 78 }, { "id": "Home Equity Basics", "name": "Home Equity Basics", "count": 78 }] } |
_gka.getFullContent(options): Promise | Example |
---|---|
Description: Retrieves full content of particular document.
|
_gkn.getFullContent({
docId: 'knowledge' }).done(function(response, status) { console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
"id":"knowledge", "language":"en", "typeName":"qna_document_en", "kbId":"knowledge", "categories":[ "Booking trips" ], "created":1402573911163, "modified":1402573911163, "snippet":"", "fields":{ "id":"knowledge", "created":1402573911163, "answer":"Every travel option we offer", "categories":[ "Booking trips" ], "question":"What’s the difference between", "modified":1402573911163 } } |
FAQ retrival
_gka.search([options]): Promise | Example |
---|---|
Description: Executes search for the answer for the given query.
|
_gkn.search({
from: 0, size: 10, query: , categories: [] }).done(function(response, status) { console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
"count": 78, "page": { "from": 0, "size": 10 }, "documents": [ { "id": "knowledge", "language": "en", "typeName": "qna_document_en", "kbId": "knowledge", "categories": [ "Home Equity Basics", "Home Mortgage" ], "created": 1404823845989, "modified": 1404823845989, "snippet": "What is the difference\n", "score": 4.20981, "fields": { "question": "What is the difference", "answer": "Locking ensures that you" }, "morelikethis": [ ], "confidence": 1.0 }, { "id": "knowledge", "language": "en", "typeName": "qna_document_en", "kbId": "knowledge", "categories": [ "Home Equity Basics", "Home Mortgage" ], "created": 1404823845989, "modified": 1404823845989, "snippet": "How long do I have to pay", "score": 4.20981, "fields": { "question": "How long do I have", "answer": "If you obtained your" }, "morelikethis": [ ], "confidence": 1.0 } ], "categories": [ { "id": "Home Equity Basics", "name": "Home Equity Basics", "count": 78 }, { "id": "Home Equity Rates & Services", "name": "Home Equity Rates & Services", "count": 2 } ] } |
_gka.suggestions(options): Promise | Example |
---|---|
Description: Provides autocomplete functionality.
|
_gkn.suggestions({
query: 'ipad' }).done(function(response, status) { console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
{
"suggestions":[ "What else do I need to know at check-in", "What is a Non-Sufficient Funds fee", "What’s a 401(k) plan?\n", ] } |
_gka.getSimilarContent(options): Promise | Example |
---|---|
Description: Retrieves similar content for the document provided.
|
_gkn.getSimilarContent({
docId: "knowledge" }).done(function(response, status) { console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
_gka.guessSpelling([options]): Promise | Example |
---|---|
Description: Guess spelling correction for the entered query.
|
_gkn.getSimilarContent({
number: 10 }).done(function(response, status) { console.log(response) }).fail(function(error, status) { console.log(error) }); |
Response | |
|
Feedback
_gka.noAnswer(options): Promise | Example |
---|---|
Description: Marks query as the one that do not have valid answer in knowledge base.
|
_gkn.noAnswer ({
from: 0, size: 10, query: , categories: [] }).fail(function(error, status) { console.log(error) }) |
_gka.visit(options): Promise | Example |
---|---|
Description: Registers viewing the document.
|
_gkn.visit({
docId: "knowledge", }).fail(function(error, status) { console.log(error) }); |
Promise Object
The object returned by all methods of _gka variable implements the Promise interface, giving them all the properties, methods, and behaviour of a Promise (see jQuery Deferred for more information). It represents a value that may not be available yet.
promise.done(doneCallbacks [, doneCallbacks ]): Promise | Example |
---|---|
Description: Add handlers to be called when the Deferred object is resolved.
|
promise.done(function(response, status) {
alert('ajax call succeeded'); console.log(response); console.log(status) }); |
promise.fail(failCallbacks [, failCallbacks ])): Promise | Example |
---|---|
Description: Add handlers to be called when the Deferred object is rejected.
|
promise.done(function() {
alert('ajax call succeeded'); }).fail(function(error, status) { alert('ajax call failed'); console.log(error); console.log(status) }); |
promise.always(alwaysCallbacks [, alwaysCallbacks ]): Promise | Example |
---|---|
Description: Add handlers to be called when the Deferred object is either resolved or rejected.
|
promise.always(function(responseOrError, status) {
alert('ajax call completed with success or error callback arguments'); console.log(responseOrError); console.log(status) }); |
promise.state(): String |
---|
Description: Determine the current state of a linked Deferred object. The .state() method returns a string representing the current state of the Deferred object. The Deferred object can be in one of three states:
|