Rest API
Create or update a document
const url = 'https://api.unless.com/api/v1/ai/training/documents';const options = { method: 'POST', headers: { 'x-api-key': 'example', 'x-user-email': 'example', 'x-account-id': 'example', 'x-website-id': 'example', 'Content-Type': 'application/json' }, body: '{"document":{"trainingDataId":"example","websiteId":"example","title":"example","body":"example","segmentId":"example","restrictedAudiences":["example"]}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.unless.com/api/v1/ai/training/documents \ --header 'Content-Type: application/json' \ --header 'x-account-id: example' \ --header 'x-api-key: example' \ --header 'x-user-email: example' \ --header 'x-website-id: example' \ --data '{ "document": { "trainingDataId": "example", "websiteId": "example", "title": "example", "body": "example", "segmentId": "example", "restrictedAudiences": [ "example" ] } }'Add a document to the knowledge base, or update one by passing its trainingDataId. A document is a title with a markdown body. Unless trains the AI on it and adds it to the content library.
Use cases
- Fill a knowledge gap: Write down the answer to a question the AI could not answer
- Add internal knowledge: Add a policy, procedure or how-to that is not on a website or in a file
- Correct a document: Update the title or body of a document created earlier
Notes
- Omit
document.trainingDataIdto create a new document, pass it to update that document. Documents show up as sources of typefaqin the get training data endpoint document.websiteIdmust match thex-website-idheader- The body is markdown: use headings, lists, tables and links to structure longer documents
- The title and body together may be at most 20000 characters
- Ingestion runs asynchronously, poll the get training data endpoint to follow progress
Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Your API key from account settings.
The email address of your user.
The ID of your account. You can find this in the account settings.
The ID of the workspace you want to use.
Request Bodyrequired
Section titled “Request Bodyrequired”object
object
ID of an existing document to update. Omit to create a new document.
Must match the x-website-id header.
Title of the document. Used as its name in the dashboard and as its title in AI sources.
Content of the document in markdown.
Segment to train the document into. Omit to keep the current segment, null for the global knowledge base.
Audience IDs that may use this document. An empty list removes the restriction, omit to keep the current one.
Example generated
{ "document": { "trainingDataId": "example", "websiteId": "example", "title": "example", "body": "example", "segmentId": "example", "restrictedAudiences": [ "example" ] }}Responses
Section titled “Responses”The document was saved and ingestion was started.
object
Example
{ "message": "Document upserted", "trainingDataId": "3f2b8c1e-5d4a-4e7b-9c0f-1a2b3c4d5e6f"}Invalid document, too long, or the trainingDataId is not a document in this workspace.
Unauthorized - invalid API key.