This guide explains how to reference a Knowledge Graph in chat sessions using the tool calling capability of the Chat completion endpoint.

This guide will help you understand how to send questions to a Knowledge Graph using tool calling. Knowledge Graph chat is a predefined tool you can quickly and easily use to reference a Knowledge Graph when users chat with a Palmyra LLM.

Your API key can be generated using these steps.

Overview

Knowledge Graph chat is a predefined tool supported by Palmyra-X-004 and later to be used with tool calling in the chat endpoint. You make the request as an object inside of the tools array with the following parameters:

  • type: The type of tool, which is graph for Knowledge Graph chat
  • function: An object containing the following parameters:
    • graph_ids: An array of graph IDs you wish to reference
    • description: A description of the graphs you are referencing
    • subqueries: A boolean indicating whether include the subqueries used by Palmyra in the response

To learn how to create a Knowledge Graph and upload files to it, follow this guide.

Here are examples of how a Knowledge Graph chat object looks in different programming languages:

Knowledge Graph chat is supported with both streaming and non-streaming responses.

Usage example

Here’s a practical example of how to use the Knowledge Graph chat tool in your application.

1

Use Knowledge Graph chat in a tools array

To use Knowledge Graph chat, reference it in your tools array:

2

Send the request using chat completions

Then, add the tools array to the chat method or endpoint call along with your array of messages.

3

Process the response

Finally, process the response from the chat endpoint using the first response in the choices array:

You may want to display the sources or subqueries in your UI to assist your user in understanding how the model derived the answer to the question.

The full response will have the following structure:

Note that the subqueries and sources examples shown here have been abbreviated for readability. If the subqueries parameter is set to false, this array will be empty.

By following this guide, you can reference Knowledge Graphs in your users’ chats in your application. To learn more about working with files and Knowledge Graphs, check out the Knowledge Graph guide.