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.
|
_gka.initialize({
host: 'http://localhost:8080',
knowledgebases: ['knowledgefaq', 'knowledgearticles']
}) |
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 |
.getDocumentsByCategory() | Retrieves documents associated to a specific category |
.getTrending() | Retrieves trending documents |
.suggestions() | Provides autocomplete functionality |
Feedback | |
.noAnswer() | Marks query as the one that do not have valid answer in knowledge base |
.vote() | Records user rating for the document within query |
.advancedVote() | Advanced version of .vote() |
.visit() | Registers viewing the document |
.rating() | Registers 5-star rating for the document |
.addRating() | Adds rating feedback to an existing vote |
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.getDocumentsByCategory(): Promise | Example |
---|---|
Description: Retrieves documents associated to a specific category.
|
_gka.getDocumentsByCategory({
catId: options.categories[0]
}).done(function(reponse) {
console.log(response)
}).fail(function (error, status) {
console.warn(error)
}); |
Response | |
For additional information, please refer to the Knowledge API page. |
{
"count": 78,
"page": {
"from": 0,
"size": 10
},
"documents": [
{
"id": "GBank_458",
"language": "en",
"typeName": "qna_document_en",
"kbId": "GBank",
"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": "GBank_477",
"language": "en",
"typeName": "qna_document_en",
"kbId": "GBank",
"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.getTrending([options]): Promise | Example |
---|---|
Description: Retrieves trending documents.
|
_gka.getTrending().done(function(reponse) {
console.log(response)
}).fail(function (error, status) {
console.warn(error)
}); |
Response | |
For additional information, please refer to the Knowledge API page. |
{
"count": 78,
"documents": [
{
"id": "GBank_458",
"language": "en",
"typeName": "qna_document_en",
"kbId": "GBank",
"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": "GBank_477",
"language": "en",
"typeName": "qna_document_en",
"kbId": "GBank",
"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 | |
For additional information, please refer to the Knowledge API page. |
{
"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",
]
} |
Feedback
_gka.noAnswer(options): Promise | Example |
---|---|
Description: Marks query as the one that do not have valid answer in knowledge base.
For additional information, please refer to the Knowledge API page. |
_gkn.noAnswer ({
from: 0,
size: 10,
query: '',
categories: []
}).fail(function(error, status) {
console.log(error)
}) |
_gka.vote(options): Promise | Example |
---|---|
Description: Records user ratings for the document within a query.
|
_gkn.like({
docId: ''groupon_22'',
relevant: false
}).fail(function(error, status) {
console.log(error)
}); |
Response | |
|
_gka.advancedVote(options): Promise | Example |
---|---|
Description: Marks queries that do not have a valid answer in knowledge base.
|
_gka.advancedVote({
likeDocId: 'id2', selection: ['id1', 'id2', id3']
}); |
Response | |
|
_gka.visit(options): Promise | Example |
---|---|
Description: Registers document views.
|
_gkn.visit({
docId: "knowledge",
}).fail(function(error, status) {
console.log(error)
}); |
_gka.rating(options):Promise | Example |
---|---|
Description: Registers 5-star rating for the document
|
_gka.rating({
kbId: 'knowledgefaq',
docId: '550e8400-e29b-41d4-a716-446655440000',
comment: 'This document was very helpful',
rating: 5
}); |
Response | |
|
_gka.addRating(options): Promise | Example |
---|---|
Description: Add rating & comment to an existing vote.
|
_gka.addRating({
voteId: 'vote_id',
comment: 'some comment',
rating: 5
}); |
Response | |
Not Provided |
_gka.addComment(options): Promise | Example |
---|---|
Description: Registers document views.
|
_gka.addComment({
voteId: 'vote_id', comment: 'some comment'
}); |
Response | |
|
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:
|