Jump to: navigation, search

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.
  • Options

Type: PlainObject
A set of key/value pairs that configure the Agent.

  • host

Type: String
A network host where Knowledge API is stored.

  • kbId

Type: String
Knowledgebase default identifier to be used.

  • lang(default: EMPTY)

Type: String
Default language to be used.

  • subTenantId (default: EMPTY)

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

Important
For additional information, please refer to the Knowledge API page.
_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

    Type: PlainObject[]
    List of supported knowledgebases

    • name
      Type: String
      Name of knowledgebase
    • languages
      Type: String[]
      List of supported languages
{
   "knowledgebases": [{
       "name": "knowledgefaq",
       "languages": [
           "en"
       ]
   }, {
       "name": "the_bank",
       "languages": [
           "en"
       ]
   }]

}

_gka.getKnowledgeBaseInfo([options]): Promise Example
Description: Retrieves information about the knowledge base.
  • options
    Type: PlainObject
    A set of key/value pairs that contains arguments for the RESTful API.
    • kbId (default: stored _gka.kbId)
      Type: String
      Particular knowledge base identifier.
_gkn.getKnowledgeBaseInfo().done(function(response, status) {
   console.log(response)

}).fail(function(error, status) {

   console.log(error)

});

Response
  • languages

    Type: String[]
    List of supported languages for given knowledgebase

{
   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

    Type: PlainObject[]
    List of supported categories

    • id
      Type: String
      Category identifier
    • name
      Type: String
      Category name
    • count
      Type: Number
      Total count of documents in category
{
   "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.
  • options
    Type: PlainObject
    A set of key/value pairs that contains arguments for the RESTful API.
    • docId
      Type: String
      Particular document identifier.
    _gkn.getFullContent({
       docId: 'knowledge'
    

    }).done(function(response, status) {

       console.log(response)
    

    }).fail(function(error, status) {

       console.log(error)
    

    });

    Response
    • id

      Type: String

    • language
      Type: String
    • typeName
      Type: String
    • kbId
      Type: String
    • categories
      Type: String[]
    • created
      Type: Number
    • modified
      Type: Number
    • snippet
      Type: String
    • fields
      • id
        Type: String
      • created
        Type: Number
      • answer
        Type: String
      • categories
        Type: String[]
      • question
        Type: String
      • modified
        Type: Number
    {
       "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.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • from (default: 0)
        Type: Number
        Pagination offset.
      • size (default: 10)
        Type: Number
        Pagination page size
      • query (default: )
        Type: String
        User typed query string
      • categories (default: [])
        Type: String[]
        List of categories that is used as a context for the current query
      • spellcheck (default: 'AUTO')
        Type String enum ("YES", "NO", "AUTO")
        Spell checking strategy.
    _gkn.search({
       from: 0,
       size: 10,
       query: ,
       categories: []
    

    }).done(function(response, status) {

       console.log(response)
    

    }).fail(function(error, status) {

       console.log(error)
    

    });

    Response
    • count

      Type: Number

    • page
      Type: PlainObject
      • from
        Type: Number
      • size
        Type: Number
    • documents
      Type: PlainObject[]
      • id
        Type: String
      • language
        Type: String
      • typeName
        Type: String
      • kbId
        Type: String
      • categories
        Type: String[]
      • created
        Type: Number
      • modified
        Type: Number
      • snippet
        Type: String
      • score
        Type: Number
      • fields
        Type: PlainObject
        • question
          Type: String
        • answer
          Type: String
      • morelikethis
        Type: String[]
      • confidence
        Type: Number
    • categories
      Type: PlainObject[]
      • id
        Type: String
      • name
        Type: String
      • count
        Type: String
    {
       "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.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • query
        Type: String
        User typed query string.
    _gkn.suggestions({
       query: 'ipad'
    

    }).done(function(response, status) {

       console.log(response)
    

    }).fail(function(error, status) {

       console.log(error)
    

    });

    Response
    • suggestions
      Type: String[]
    {
       "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.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • docId
        Type: String
        Particular document identifier.
    _gkn.getSimilarContent({
       docId: "knowledge"
    

    }).done(function(response, status) {

       console.log(response)
    

    }).fail(function(error, status) {

       console.log(error)
    

    });

    Response
    • count

      Type: Number

    • suggestions
      Type: String[]
    • page
      Type: PalinObject
      • from
        Type: Number
      • size
        Type: Number
    • documents
      Type: PlainObject[]
      • id
        Type: String
      • language
        Type: String
      • typeName
        Type: String
      • kbId
        Type: String
      • categories
        Type: String[]
      • created
        Type: Number
      • modified
        Type: Number
      • snippet
        Type: String
      • score
        Type: Number
      • fields
        Type: PlainObject
        • question
          Type: String
          answer
          Type: String
      • morelikethis
        Type: String[]
      • confidence
        Type: Number
    _gka.guessSpelling([options]): Promise Example
    Description: Guess spelling correction for the entered query.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • number (default: 1)
        Type: Number
        Number of suggestions to be proposed.
    _gkn.getSimilarContent({
       number: 10
    

    }).done(function(response, status) {

       console.log(response)
    

    }).fail(function(error, status) {

       console.log(error)
    

    });

    Response
    • suggestions

      Type: PlainObject[]

      • word
        Type: String
      • suggestions
        Type: String[]

    Feedback

    _gka.noAnswer(options): Promise Example
    Description: Marks query as the one that do not have valid answer in knowledge base.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • from
        Type: Number
        Pagination offset.
      • size
        Type: Number
        Pagination page size
      • query
        Type: String
        User typed query string
      • categories
        Type: String[]
        List of categories that is used as a context for the current query
      • spellcheck
        Type String enum ("YES", "NO", "AUTO")
        Spell checking strategy
    _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.
    • options
      Type: PlainObject
      A set of key/value pairs that contains arguments for the RESTful API.
      • docId
        Type: String
        Particular document identifier.
    _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.
    • doneCallbacks
      Type: Function(response, status)
      A function, or array of functions, that are called when the Deferred is resolved.
    • doneCallbacks
      Type: Function(response, status)
      Optional additional functions, or arrays of functions, that are called when the Deferred 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.
    • doneCallbacks
      Type: Function(error, status)
      A function, or array of functions, that are called when the Deferred is rejected.
    • doneCallbacks
      Type: Function(error, status)
      Optional additional functions, or arrays of functions, that are called when the Deferred 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.
    • doneCallbacks
      Type: Function(response|error, status)
      A function, or array of functions, that is called when the Deferred is resolved or rejected.
    • doneCallbacks
      Type: Function(response|error, status)
      Optional additional functions, or arrays of functions, that are called when the Deferred is 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:

    • pending: The Deferred object is not yet in a completed state (neither "rejected" nor "resolved").
    • resolved: The Deferred object is in the resolved state, meaning that the doneCallbacks have been called (or are in the process of being called).
    • rejected: The Deferred object is in the rejected state, meaning that the failCallbacks have been called (or are in the process of being called).
    This page was last edited on May 27, 2015, at 12:54.
    Comments or questions about this documentation? Contact us for support!