NLQ Service

About

The NLQ Enables users to find information by making requests as if they were speaking to a person. service can be called via API from external components.

Details about the Endpoints used are below.

EndPoints

Two end points must be called:

  • Verify User Question
    • Description:
      • This endpoint tells you if the user query can be a natural language query.
      • The result of this query will determine if the endpoint Get NLQ Response below is necessary and beneficial to call.
    • This endpoint is called first.
    • Endpoint: https://<SmartHub-app-url>/Services/HelperBotService.svc/VerifyUserQuestion
    • POST request
    • Must include HTTP request header: X-SH-Authorization
    • Request body (see "Endpoint Sample Request Body" code below)
      • Format: JSON
  • Get NLQ Response
    • Description:
      • This endpoint calls your NLQ service, and returns the user intent and entities detected in the original query.
      • If a Bot Conversation matches the intent, this call returns the new query text, or the HTML snippet configured in the Bot Conversation.
      • Returns a query transformation
    • POST request
    • Must include HTTP request header: X-SH-Authorization
    • Call the Get NLQ Response endpoint only if the Verify User Question endpoint returns TRUE
    • Endpoint: https://<SmartHub-app-url/Services/HelperBotService.svc/PrelucrateUserQuestion

Endpoint Sample Request Body

This applies to both endpoints:

Sample Request Body
Copy
{
  "question": "show me diabetes treatment documents",
  "query": {
    "CorrelationId": "7bb46f7a-8b7c-8192-0376-84a53105f2bd",
    "QueryText": "show me diabetes treatment documents",
    "QueryTemplate": "{searchboxquery} FederatorBackends:\"*\"",
    "SortList": [
      {
        "SortType": 1,
        "PropertyName": "Rank",
        "Direction": 1
      }
    ],
    "EnableSorting": true,
    "PreferredLanguage": "en-US",
    "HitHighlightedProperties": [
      "Title"    ],
    "RowLimit": 10,
    "StartRow": 0,
    "SelectProperties": [
      "title",
      "escbasecrawurl",
      "Size",
      "DisplayAuthor"    ],
    "Refiners": "DisplayAuthor,filetype,ContentSource,RefinableString131",
    "SourceId": "221c396f-c525-4fe2-a210-c58c81ffeb99",
    "RefinementFilters": [],
    "TrimDuplicates": true,
    "EnableStemming": true,
    "Source": "ChatBot",
    "SummaryLength": 200,
    "ResultsUrl": "https://smarthuba.bainsight.com/SmartSearchNew/Results.html"  }
}

Verify User Question Sample Response Body

Copy
"{\"IsNLQ\":\"true\"}"

Get NLQ Sample Response Body

Copy
"{\"message\":\"\",\"queryText\":\"( diabetes treatment )\",\"additionalResultsQueryToRun\":\"( diabetes treatment )\",\"raw\":\"{\\r\\n  \\\"query\\\": \\\"show me diabetes treatment documents\\\",\\r\\n  \\\"topScoringIntent\\\": {\\r\\n    \\\"intent\\\": \\\"SearchForDocuments\\\",\\r\\n    \\\"score\\\": 0.885881841\\r\\n  },\\r\\n  \\\"intents\\\": [\\r\\n    {\\r\\n      \\\"intent\\\": \\\"SearchForDocuments\\\",\\r\\n      \\\"score\\\": 0.885881841\\r\\n    },\\r\\n    {\\r\\n      \\\"intent\\\": \\\"SearchForPeople\\\",\\r\\n      \\\"score\\\": 0.154521391\\r\\n    },\\r\\n    {\\r\\n      \\\"intent\\\": \\\"None\\\",\\r\\n      \\\"score\\\": 0.000812157639\\r\\n    },\\r\\n    {\\r\\n      \\\"intent\\\": \\\"AskForExperts\\\",\\r\\n      \\\"score\\\": 0.0005798265\\r\\n    }\\r\\n  ],\\r\\n  \\\"entities\\\": [\\r\\n    {\\r\\n      \\\"entity\\\": \\\"diabetes\\\",\\r\\n      \\\"type\\\": \\\"Diseases\\\",\\r\\n      \\\"startIndex\\\": 8,\\r\\n      \\\"endIndex\\\": 15,\\r\\n      \\\"resolution\\\": {\\r\\n        \\\"values\\\": [\\r\\n          \\\"diabetes\\\"\\r\\n        ]\\r\\n      }\\r\\n    },\\r\\n    {\\r\\n      \\\"entity\\\": \\\"diabetes treatment\\\",\\r\\n      \\\"type\\\": \\\"Information\\\",\\r\\n      \\\"startIndex\\\": 8,\\r\\n      \\\"endIndex\\\": 25,\\r\\n      \\\"resolution\\\": {\\r\\n        \\\"values\\\": [\\r\\n          \\\"diabetes treatment\\\"\\r\\n        ]\\r\\n      }\\r\\n    },\\r\\n    {\\r\\n      \\\"entity\\\": \\\"diabetes\\\",\\r\\n      \\\"type\\\": \\\"Skills\\\",\\r\\n      \\\"startIndex\\\": 8,\\r\\n      \\\"endIndex\\\": 15,\\r\\n      \\\"resolution\\\": {\\r\\n        \\\"values\\\": [\\r\\n          \\\"Diabetes\\\"\\r\\n        ]\\r\\n      }\\r\\n    }\\r\\n  ]\\r\\n}\",\"payload\":\"{\\\"UserIntent\\\":\\\"SearchForDocuments\\\",\\\"Entities\\\":[{\\\"Type\\\":\\\"Diseases\\\",\\\"Value\\\":\\\"diabetes\\\",\\\"Properties\\\":{\\\"values\\\":[\\\"diabetes\\\"]}},{\\\"Type\\\":\\\"Information\\\",\\\"Value\\\":\\\"diabetes treatment\\\",\\\"Properties\\\":{\\\"values\\\":[\\\"diabetes treatment\\\"]}},{\\\"Type\\\":\\\"Skills\\\",\\\"Value\\\":\\\"Diabetes\\\",\\\"Properties\\\":{\\\"values\\\":[\\\"Diabetes\\\"]}}]}\"}"

Response Body

To use the received response body, use the following JavaScript code:

var nlqResponse =JSON.parse(responseBodyHere)

The full RAW response from the configured NLQ service can be found by using this command:

JSON.parse(nlqResponse.raw)