We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Retrieving relevant knowledge arcticle chunks using AI Search and Scripted REST API.

atharvsubhe
Tera Contributor

I recently started working on a project which requires external access to ServiceNow's AI Search feature. The goal here is to send a query to AI search using a scripted REST API and returning only the relevant chunks from the Knowledge base. 

Right now, I am stuck as the semantic configuration is set but the resulting applications is not returning relevant chunks but the entire text from the document. 

I have the indexed sources properly set to use semantic configuration. Additionally, I even created a new Search Application with correct search profile and search sources, to test it in the SN Preview utility tool, but the results from the tool states that semanticSearch = False and thus does not return relevant passages.  

Has anybody tried the creating a Scripted REST API to use AI Search? 

 

3 REPLIES 3

rpriyadarshy
Tera Guru

The goal here is to send a query to AI search using a scripted REST API and returning only the relevant chunks from the Knowledge base.---->@atharvsubhe Are you expecting the Output format which Comes when we have  Now Assist QnA Genius results configured where the Precise KB contents are Displayed?

 

Do you have Now Assist for AI Search enabled in Your environment?

 

 

   --  https://www.servicenow.com/community/now-assist-articles/now-assist-in-ai-search-nov-2024-release/ta...).

 

Regards

RP

I just enabled Genius Results and it is working as expected. Although I am seeing the results in the Preview Utility. But when I try to call the Search Application through the scripted REST API, it does not show me genius results. I believe it is still using the keyword search. 
Below is the code snippet I am using to get the results from the Search application. I tried adding a request level hint to replicate the call from preview utility, but it still does not seem to work. 

 

var contextObj = {
				citationVersion: "2",
				request_origin: { origin: "api", name: "scripted_rest" },
				searchMode: "hybrid"       // request-level hint (like Preview)
			};

            var payload = {
                rpSysId: RP_SYS_ID,
                searchContextConfigId: SEARCH_APP_CONFIG_ID,
                searchTerm: term,
                additionalContext: JSON.stringify(contextObj)
            };

            // IMPORTANT: This returns the FULL object from the platform.
            return new global.AISASearchUtil().search(payload);

 

 The response from the script looks like this. 

 

{
  "result": {
    "result": {
      "status": 200,
      "msg": "SUCCESS",
      "data": {
        "search": {
          "term": "[REDACTED]",
          "searchResults": [
            {
              "sysId": "e9f835a0870ffa106c2876e8cebb357d",
              "table": "kb_knowledge",
              "text": "[REDACTED]",
              "title": "[REDACTED]",
              "columns": [
                {
                  "fieldName": "short_description",
                  "label": "Short description",
                  "value": "[REDACTED]",
                  "displayValue": "[REDACTED]"
                },
                {
                  "fieldName": "number",
                  "label": "Number",
                  "value": "KB0010248",
                  "displayValue": "KB0010248"
                },
                {
                  "fieldName": "sys_id",
                  "label": "sys_id",
                  "value": "e9f835a0870ffa106c2876e8cebb357d",
                  "displayValue": "e9f835a0870ffa106c2876e8cebb357d"
                },
                {
                  "fieldName": "text",
                  "label": "Article body",
                  "value": "[REDACTED]"
                },
                {
                  "fieldName": "sys_updated_on",
                  "label": "Updated",
                  "value": "1770747860000",
                  "displayValue": "2026-02-10 10:24:20"
                }
              ]
            }
          ],
          "count": 1
        },
        "resultsActionsMap": {
          "kb_knowledge:e9f835a0870ffa106c2876e8cebb357d": [
            "40fdb34467fa1010b3d782f45685efe0"
          ]
        },
        "availableActions": {
          "40fdb34467fa1010b3d782f45685efe0": {
            "sysId": "40fdb34467fa1010b3d782f45685efe0",
            "actionId": "aisa_resolves",
            "actionLabel": "Solves my issue",
            "restPath": "/resolves",
            "resultTable": null,
            "isCardAction": false,
            "isDetailAction": true,
            "searchApp": null,
            "scriptedVisibility": false,
            "visibilityScript": null,
            "resultTableCondition": null,
            "priority": 0
          },
          "c6eefb4467fa1010b3d782f45685ef55": {
            "sysId": "c6eefb4467fa1010b3d782f45685ef55",
            "actionId": "aisa_sc_cat_item_order",
            "actionLabel": "Order",
            "restPath": "/sc_cat_item_order",
            "resultTable": "sc_cat_item",
            "isCardAction": true,
            "isDetailAction": true,
            "searchApp": null,
            "scriptedVisibility": false,
            "visibilityScript": null,
            "resultTableCondition": "sys_class_name!=sc_cat_item_content^sys_class_name!=sc_cat_item_wizard^EQ"
          }
        }
      }
    },
    "geniusResults": null
  }
}

 

 

@atharvsubhe  I still remember in one of our assignments Genius result output was not consistent, Sometime it was coming and some time not.

 

  • Genius Results only trigger when the system has very high confidence in the detected intent, which means valid queries may still return no Genius Result if confidence thresholds aren’t met.
  • The effectiveness of Genius Results is heavily dependent on data quality and structure, especially well‑maintained knowledge articles and correctly trained NLU models.

Just a small input

 

Items Now Assist (GenAI / Q&A Genius) Genius Results (AI Search / NLU)Primary Purpose Technology Behavior
Generates natural‑language answers and summaries using LLMs to assist users and agents directlyDisplays actionable result cards (catalog, people, KB snippets) at the top of search results
Large Language Models (LLMs) via ServiceNow Generative AI ControllerNatural Language Understanding (NLU) + AI Search intent detection
Synthesizes responses from multiple sources with conversational phrasing and citationsReturns pre‑configured, high‑confidence matches Only (not generative)

 

Regards

RP