Knowledge graph
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:
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:
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.
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:
You’ll need the file id
i.e. 1862f090-a281-48f3-8838-26c1e78b605e
to associate the files with a Graph.
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:
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
.
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:
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:
Delete a file
Endpoint: DELETE /v1/files/{fileId}
The response will have the following structure:
Error handling
Ensure to handle potential errors such as timeouts or model errors gracefully.
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
-
Create a no-code chat application: Start by building a chat application and configuring the app. Read how to build it here.
-
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.
-
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.