logo

NJP

How to index external content with AI Search (Example with Knowledge Base from second SN instance)

Import · Feb 15, 2022 · article

The big advantage of this approach over an integration of external content into the Knowledge base is, that NO KB articles will be created in Servicenow.

There will be no redundancy of articles in the external source and the target source.

For the following example, I indexed a knowledge article which exists on ServiceNow Instance B (Rome release) on another ServiceNow Instance A (SanDiego release)

Step 1: Base Setup in target instance A

Make sure AI Search is enabled and everything is installed.

You should see a Module "AI Search -> External Content"

Step 2: Create Schema table in target instance A

Navigate to "AI Search -> External Content -> Create Schema"

Give your Schema a name and click Submit. This will create a table that extends v_ais_external_search_content

The OOTB table should be sufficient, but if you want to include more than just the title to the indexed source, you can add additional columns (in my example, I added "u_body" with type string)

Step 3: Create Indexed Source and Search Source

Navigate to "AI Search -> AI Search Index -> Indexed Sources" and click New.

Give it a name and select the newly created table as source.

If you have created additional fields on your schema table, create a field mapping for your table in the indexed source (see screenshot).

image

Create a Search Source and add the Indexed Source to the newly created Search Source

Finally, you can use this Search Source in any Search Profile.

In my example, I added it to the "ESC Portal Default Search Profile".

STEP 4: Create REST integration from source instance B

Indexing of external Search Content via AI Search is always based on a data PUSH. So in my example, I created a REST call (by using IntegrationHub/Flow Designer) to push the data to instance A.

In your integration, you can use any other method if required. Like a python script or curl.

Step 4.0: Create a Connection and Credentials to use for Flow Actions

In my example, I created a connection that points to target instance A and a credentials record with Base authentication to log into the instance.

In your integration you can use other authentication mechanisms of your choice.

Step 4.1: Create a flow action with a REST step to create binary content

Use the following REST API (External Content Ingestion API) to store binary content as a content object in AI Search:

api/now/v2/ais/external_content/storeContent

This will create a binary content object and return a SysId which can be used in the next step to send external documents to AI Search.

The content-type can be anything from the following depending on the documents that need to be indexed. I created an input variable for the content-type.

  • * * application/msword
    * application/octet-stream
    * application/pdf
    * application/vnd.ms-excel
    * application/vnd.ms-powerpoint
    * application/vnd.ms-powerpoint.presentation.macroenabled.12
    * application/vnd.openxmlformats-officedocument.presentationml.presentation
    * application/vnd.openxmlformats-officedocument.presentationml.template
    * application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    * application/vnd.openxmlformats-officedocument.wordprocessingml.document
    * application/vnd.openxmlformats-officedocument.wordprocessingml.template
    * text/html
    * text/plain

Add a JSON parser step to parse the response body and extract the sysId of the binary object and map this to an outputs variable to use it in the next flow action.

image

Step 4.2: Create a flow action with a REST step to ingest documents.

Use the following REST API (External Content Ingestion API) to send documents to the previously created binary content object:

api/now/v2/ais/external_content/ingestDocument/u_xxxxxx

Create the following inputs:

image

Hint: "u_body" is an example for an additional field. See Step 3!

Configure a REST Step and map your inputs to the Request Body.

  • content_pointer -> sysId of binary content which was created in step 4.1
  • document_is -> unique identifier of the document. When there already exists a document with this identifier, it will be overwritten.
  • principals -> object with security settings
  • properties -> object with the fields that will be indexed

image

Step 5: Create Flow to run both actions on source instance B

image

Step 6: Try it out!

  1. Create a KB-Article on your source instance B
  2. Open your target instance A and go to a place where your Search Profile which was created in Step 3 is used. In my example it is used in the ESC Portal.
  3. Search for any term that is part of your indexed source (title or in my example "u_body")
  4. See the Result in your target instance A.
  5. If you click on the result, you will be redirected to the document (which was handed over with the url property. In my Case the KB article in the Service Portal of the source instance B)

Article in source instance B

image

ESC Portal AI Search in target instance A

(This article DOES NOT exist in instance A!)

image

Redirection to Service Portal in source instance B

image

View original source

https://www.servicenow.com/community/developer-articles/how-to-index-external-content-with-ai-search-example-with/ta-p/2318484