You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a
.env
file with the name WRITER_API_KEY
.Create a Knowledge Graph
A Knowledge Graph is a collection of files that are used to answer questions. To start working with a Knowledge Graph, create an empty Knowledge Graph that you can add files to. Endpoint:POST https://api.writer.com/v1/graphs
Request body
The request body is a JSON object that contains the following fields:Parameter | Type | Description |
---|---|---|
name | string | The name of the Knowledge Graph. |
description | string | The description of the Knowledge Graph. The description should help the model understand the purpose of the Knowledge Graph and when it should be used. |
Response format
The response has the following structure:Parameter | Type | Description |
---|---|---|
id | string | The ID of the Knowledge Graph. |
created_at | string | The date and time the Knowledge Graph was created. |
name | string | The name of the Knowledge Graph. |
description | string | The description of the Knowledge Graph. |
Add a file to a Knowledge Graph
Once you’ve created a Knowledge Graph, you can add files to it. The files you add to a Knowledge Graph are used to answer questions and enhance the accuracy of the responses from the LLM You must upload the file to the Writer API before adding it to a Knowledge Graph. See Manage files for more information about how to upload files. Endpoint:POST /v1/graphs/{graph_id}/file
Path parameters
Parameter | Description |
---|---|
graph_id | The ID of the Knowledge Graph to update. |
Request body
The request body is a JSON object that contains the following fields:Parameter | Description |
---|---|
file_id | The ID of the file to add to the Knowledge Graph. |
Remove a file from a Knowledge Graph
Endpoint:DELETE /v1/graphs/{graph_id}/file/{file_id}
Path parameters
Parameter | Description |
---|---|
graph_id | The ID of the Knowledge Graph to update. |
file_id | The ID of the file to remove from the Knowledge Graph. |
Response format
The response has this structure:Add URLs to a Knowledge Graph
You can add URLs to a Knowledge Graph to enhance the model’s knowledge with content from websites. The LLM can then query and use this information when responding to questions. This example adds a web connector URL to a Knowledge Graph. It first retrieves the Knowledge Graph to see the current URLs and then adds a new URL to the Knowledge Graph. Note that this operation replaces the entire list of URLs attached to the Knowledge Graph, which is why it is important to retrieve the existing list of URLs first.Add a Knowledge Graph to a no-code agent
After you’ve created a Knowledge Graph, you can add it to a no-code agent to add RAG capabilities. You can use this endpoint to add or remove Knowledge Graphs from a no-code agent. Endpoint:PUT /v1/applications/{application_id}/graphs
Path parameters
Parameter | Description |
---|---|
application_id | The ID of the no-code agent to update. |
Request body
The request body is a JSON object that contains the following fields:Parameter | Type | Description |
---|---|---|
graph_ids | array[string] | The IDs of the Knowledge Graphs to associate with the no-code agent. |
graph_ids
parameter to an array containing the IDs of all the other Knowledge Graphs associated with the no-code agent, excluding the ID of the Knowledge Graph to remove. To remove all Knowledge Graphs from the no-code agent, set this parameter to an empty array.
Response format
The response contains the new list of IDs of the Knowledge Graphs associated with the no-code agent.Next steps
- Learn how to ask your Knowledge Graph questions in a chat completion via tool calling
- Query your Knowledge Graph directly using the question endpoint
- Fine-tune how your Knowledge Graph searches and retrieves content using the
query_config
parameter in the Knowledge Graph query configuration guide