This guide explains the Knowledge Graph API and the File API.

Knowledge Graph, our graph-based retrieval-augmented generation (RAG), achieves higher accuracy than traditional RAG approaches that use vector retrieval. This guide will help you understand and use the Knowledge Graph (KG) API to integrate powerful Retrieval-Augmented Generation (RAG) capabilities into your no-code applications.

Our API allows you to seamlessly manage knowledge graphs and their associated files. Whether you’re building chat applications, content recommendation systems, or any other AI-powered tools, the KG API is designed to make your development process efficient and scalable.

Your API key can be generated using these steps.

Overview

The Knowledge Graph API is a critical part of the Writer suite of tools designed for advanced AI applications. By leveraging knowledge graphs, this API enables developers to create, manage, and use structured data to enhance AI capabilities, particularly in RAG scenarios.

Usage example

Here’s how you can use the KG API and File API in a practical scenario:

1

Create a Knowledge Graph

Creating a Knowledge Graph is the first step in organizing your data.

You can either make a POST call to the /v1/graphs endpoint directly or use one of our SDKs.

The response will have this structure:

{
  "id": "6029b226-1ee0-4239-a1b0-cdeebfa3ad5a",
  "created_at": "2024-06-24T12:34:56Z",
  "name": "financial_reports",
  "description": "Graph for financial reports"
}

You’ll need the Knowledge Graph ID i.e. 6029b226-1ee0-4239-a1b0-cdeebfa3ad5a to associate files to the Graph.

You can also update the name or description of a Knowledge Graph with a PUT request or delete the Knowledge Graph with a DELETE request.

2

Upload files

Once you have a Graph, you can start uploading files to Writer. This data is used for retrieval operations in RAG scenarios. See the pricing page for current pricing for file hosting, extraction, and parsing.

To use this endpoint, you’ll need to add Content-Type and Content-Disposition headers with the relevant media type and file name. Knowledge Graphs currently support txt, doc, docx, ppt, pptx, jpg, png, eml, html, pdf, srt, csv, xls, and xlsx files.

Endpoint: POST /v1/files

The response will have this structure:

  {
    "id": "1862f090-a281-48f3-8838-26c1e78b605e",
    "created_at": "2024-06-24T12:34:56Z",
    "name": "test.txt"
  }

You’ll need the file id i.e. 1862f090-a281-48f3-8838-26c1e78b605e to associate the files with a Graph.

3

Associate files with a Graph

Once a file is uploaded, you can associate it with a Knowledge Graph using the file ID.

Endpoint: POST /v1/graphs/{graph_id}/file

The response will have this structure:

{
  "id": "1862f090-a281-48f3-8838-26c1e78b605e",
  "created_at": "2024-07-01T20:41:44.159505Z",
  "name": "test.txt",
  "graph_ids": [
    "6029b226-1ee0-4239-a1b0-cdeebfa3ad5a"
  ]
}

To disassociate a file from a Knowledge Graph, send a DELETE request. The graph_id from the response will be needed at later steps, e.g. 6029b226-1ee0-4239-a1b0-cdeebfa3ad5a.

4

Retrieve and manage files

You can retrieve and manage files within your Graphs to ensure that your data is always up-to-date and relevant.

Get all files in all Graphs

Endpoint: GET /v1/files

See the API reference for this endpoint to see all available query parameters.

The response will have the following structure:

{
  "data": [
    {
      "id": "1862f090-a281-48f3-8838-26c1e78b605e",
      "created_at": "2024-06-24T12:34:56Z",
      "name": "Q1_report.pdf",
      "graph_ids": ["6029b226-1ee0-4239-a1b0-cdeebfa3ad5a"]
    }
  ],
  "has_more": false,
  "first_id": "8ac0a551-6f4b-4779-a0d2-a4464c68ceb4",
  "last_id": "2449ff3d-0cd6-4188-9e29-f8c7e02c08e4"
}

Use query parameters to get files from a specific graph

Endpoint: GET /v1/files?graph_id={graph_id}

The response will have the following structure:

{
  "data": [
      {
          "id": "5e7d9fa0-d582-40af-8c56-ec9634583eb6",
          "created_at": "2024-07-15T20:05:52.684560Z",
          "name": "example.pdf",
          "graph_ids": [
              "6029b226-1ee0-4239-a1b0-cdeebfa3ad5a"
          ]
      }
  ],
  "has_more": false,
  "first_id": "5e7d9fa0-d582-40af-8c56-ec9634583eb6",
  "last_id": "5e7d9fa0-d582-40af-8c56-ec9634583eb6"
}

Delete a file

Endpoint: DELETE /v1/files/{fileId}

The response will have the following structure:

{
  "id": "1862f090-a281-48f3-8838-26c1e78b605e",
  "deleted": true
}
5

Error handling

Ensure to handle potential errors such as timeouts or model errors gracefully.

6

Rate limiting

Be mindful of any rate limits that might apply to avoid service disruptions.

Integrate with AI applications

The most powerful aspect of the Knowledge Graph API is its integration with AI applications, enabling advanced RAG capabilities.

Chat completion with Knowledge Graph

Knowledge Graph chat is available as a pre-built tool for use with tool calling. Check out the Knowledge Graph chat support guide to learn how to implement this.

No-code chat application with Knowledge Graph

  1. Create a no-code chat application: Start by building a chat application and configuring the app. Read how to build it here.

  2. Enable Knowledge Graph in the application: Make sure you’ve enabled the Knowledge Graph mode and selected the right Graph — the one you sent via the Writer API. Read how to do this here.

  3. Use Knowledge Graph from the API in a no-code app: Deploy your app to Writer Workspaces or use our embedded application feature to easily embed chat apps with Knowledge Graph in any third-party software. Check out more details here.