Salesforce

Customize engine output

« Go Back
Information
Customize engine output
000003962
Public
Product Selection
aiWare - aiWare
Article Details

An engine's output can be customized to contain additional data on top of what is required by the AION schema. To customize the engine's output, create and register a schema, and then update the engine output to include the schema. This creates a searchable engine output.

A common requirement is the need to include a summary block of data as part of an engine's output. The schemaless way to do it is to include a jsondata blob (arbitrary JSON data of your choosing) under a vendor field. The disadvantage of this approach is that the summary data will not be indexed and therefore not be searchable.

Another approach is to define a JSON schema for the summary blob, register that schema with Veritone (so a schema ID is obtained), and then include a properly structured summary blob in the final output, along with the schema ID. This allows aiWARE to validate the engine's entire output and index everything (for searchability). This is the approach shown below.

Steps

  1. Create a summary schema. For example:
        {
          "stats": {
            "totalWords": 950,
            "vocabWords": 223,
            "processingTimeMS": 4
          }
        }
  2. Register the schema using Register a schema.
        {
          "definitions": {},
          "$schema": "http://json-schema.org/draft-07/schema#",
          "$id": "http://example.com/root.json",
          "type": "object",
          "title": "The Root Schema",
          "required": [
            "stats"
          ],
          "properties": {
            "stats": {
              "$id": "#/properties/stats",
              "type": "object",
              "title": "The Stats Schema",
              "required": [
                "totalWords",
                "vocabWords",
                "processingTimeMS"
              ],
              "properties": {
                "totalWords": {
                  "$id": "#/properties/stats/properties/totalWords",
                  "type": "integer",
                  "title": "The Totalwords Schema",
                  "default": 0,
                  "examples": [
                    123
                  ]
                },
                "vocabWords": {
                  "$id": "#/properties/stats/properties/vocabWords",
                  "type": "integer",
                  "title": "The Vocabwords Schema",
                  "default": 0,
                  "examples": [
                    123
                  ]
                },
                "processingTimeMS": {
                  "$id": "#/properties/stats/properties/processingTimeMS",
                  "type": "integer",
                  "title": "The Processingtimems Schema",
                  "default": 0,
                  "examples": [
                    123
                  ]
                }
              }
            }
          }
        }
  3. Inside the getOutput() method of the keyword-extraction.js file, add this code that appends a proper stats object to your data immediately before the return statement of the getOutput() method.
        // First we'll put this inner method inline:
        function getStructuredData() {
          let schemaId = "1842b38c-ab34-401f-9715-d668f0c6ebd3"; // Use your own schema ID here!
          let sdo = {}; // create empty structured-data object (sdo)
          sdo.type = "object"; // start building the object
          sdo.structuredData = {};
          sdo.structuredData[schemaId] = {};
          sdo.structuredData[schemaId].stats = {};
          sdo.structuredData[schemaId].stats.totalWords = _words.length;
          sdo.structuredData[schemaId].stats.vocabWords = output.length;
          sdo.structuredData[schemaId].stats.processingTimeMS = (1 * new Date) - _startTime;
          return sdo;
        }
        // Now we can add the structured data to our output:
        output.push( getStructuredData() );
        return output;
  4. At the top of the file, add these two lines of code.
        let _startTime = 1 * new Date;
        // Track word count
        let _words = null;
  5. Once the engine is deployed to Veritone, run the modified engine on a text file. The stats object will appear in the output.
Additional Technical Documentation Information
Properties
1/18/2024 9:17 PM
1/18/2024 9:20 PM
1/18/2024 9:20 PM
Documentation
Documentation
000003962
Translation Information
English

Powered by