Enhance KB Answers with KB Metadata

Adding metadata to your Knowledge Base (KB) can greatly improve the relevance and accuracy of responses generated by the conversational engine. Metadata serve as connections between business objects and KB data sources or data source elements, enabling more meaningful interactions with users.

Using KB Metadata

In DRUID, metadata is natively managed within the Knowledge Base. This allows seamless linking between KB elements (such as KBDataSource or KBWebsitePage) and your business objects.

By leveraging KB Metadata, you can categorize KB data sources using metadata applied at various levels within the data source hierarchy.

To use the KB metadata, follow these steps:

Step 1: Import the KB Toolkit solution (Versions Prior to 9.31)

NOTE: Starting with Druid version 9.31, importing the KB Toolkit solution is no longer required. Proceed directly to Step 2.

For Druidversions prior to 9.31:

  1. Navigate to the Solution Library.
  2. Search for the 'KB Toolkit2' solution template and import it.
  3. Go to Apps and click on the druid-kb2 app.
  4. In the Base URL field, provide your tenant URL.
  5. Set the necessary connection strings for the druid-kb2 connector app.
  6. In the variable table, set the password, userNameOrEmailAddress, tenant_name and tenant_id.

    IMPORTANT! Provide the credentials (username / email and password) of a Portal user who has full access privileges to the KB API endpoint; otherwise, the KB Metadata will not be available.
NOTE: Do not alter the integrations on the [[KBMetadata]] entity, otherwise, the metadata records will not be available.

Step 2: Establish nomenclature

You can add either tags (simple string metadata) or nomenclature metadata to your KB data sources / elements. However, relying solely on string metadata (tags) may not always be the most effective approach, especially when dealing with multiple nodes or leafs. Instead, consider using metadata nomenclature linked to existing business entities, such as product lists, for more accurate categorization.

Establishing nomenclature within your Knowledge Base (KB) is crucial for linking specific business objects and enhancing content relevance:

  1. Add the desired business objects (entities) in your solution to serve as KB metadata nomenclatures.
  2. Add fields of type Entity in the [[KBMetadata]] entity referring to the desired business objects.
  3. Go to Knowledge Base > Knowledge Base Settings and click Metadata Integrations.
  4. Select the desired KB Metadata field and choose the integration that brings its values.

Step 3A: Add KB metadata for standard data sources

To add KB Metadata for data sources other than custom data sources:

  1. Navigate to the desired KB data source and switch to Split view.
  2. Select the relevant node, leaf, or root.
  3. Click the Metadata (New) tab.
  4. The legacy Metadata tab remains available to allow validation against the new KB Metadata experience.

  5. Click + Add new. A new Metadata section appears on the page.
  6. Select the metadata field you want to use and select value.
  7. Info: If you want to add string metadata, select Tag and enter a value (e.g., "car loan").
    NOTE: Tags are case sensitive, so ensure consistent usage across data source elements and sources to prevent inconsistencies. Leave this field empty if you are using nomenclatures.

  8. Click Save at the bottom of the page.

You can add multiple metadata records to the same data source, node, or leaf based on your business needs. For example: If you want specific content within a data source to be taken into consideration based on different client type and product type, add multiple metadata records.

Info: A label displayed in the data source tree structure indicates if the data source element has associated metadata and excluded metadata. If you hover over the metadata label, you can see the number of metadata records associated with the metadata.
IMPORTANT! Train the KB; otherwise, the metadata will be disregarded at predict time. If multiple KB metadata records are applied to a node, the KB engine uses the OR operator between the defined metadata values during prediction time.

Step 3B: Add KB metadata for custom data sources

When working with custom data sources, go to the integration for data extraction and update the Custom Code task to include KB metadata tags.

Copy

Example

(function main() {
    let responseEntity = EntityFactory.CreateEntityByName("KBCustomDSProcessNodeTask");
    responseEntity.Node = EntityFactory.CreateEntityByName("KBWebsitePage");
    responseEntity.Node.Context = {};
    responseEntity.Node.Context.FileContent = Context.GetResponseEntity().Node.Content;
    
    // Add KB Metadata
    responseEntity.Node.Context.Metadata = [{"tag":"personal","Age":23},{"tag":"public"}];
 
    Context.SetResponseEntity(responseEntity);
    Context.CompleteAction();
})();

 

Step 4: Update flows to refine Conversational Engine search

  1. Adapt flows to gather necessary user information before the user starts asking questions (e.g., client type, product type).
  2. Set metadata filters within the conversation context based on user data by setting the user-related data in the [[Intent]] entity that handles the predict. The Conversation Engine will search within the KB only based on the metadata filters set in the flow.
  3. Example: Filter by ProductType and ClientType and Tag.

    You can set complex metadata filters within the conversation context by setting [[Intent]].KBQueryObject in the Set Variables component and using Code extension to define tailored conditions based on specific metadata fields.

    Info: You can use the following operators when defining metadata filters in Code extension: AND, OR, =, >, <, >=, <=, !=, EXISTS.

    Copy
    Example
    (
        function ()
        {
            let JResult=
              {
                operator : "AND",
                children : [
                ]
            }

            JResult.children.push (
                    {    operator: "=",
                        name: "DocType",
                        value: "Lease contract"                
                    }
            );
            JResult.children.push (
                    {
                        operator: "=",
                        name: "ProcessType",
                        value: "Risk assessment"
                    }
            )
            return JResult;
        }
    )()

    NOTE:
    • The name property must contain the field name (for example, DocType or ProcessType), without the [[KBMetadata]] prefix.
    • The value property must contain the actual metadata value (for example, 'Lease contract' or 'Risk assessment').
    • This configuration ensures that the prediction is made only on data sources or nodes that contain the specified metadata values.
  4. Ensure consistent updating of metadata filters throughout the conversation as needed. The metadata filters set in the flow are stored in the conversation context. If you want to widen or narrow the knowledge base search scope, add or remove metadata filters at different points in the conversation.