Skip to content

Add a file to a knowledge base

POSThttps://gptunnel.ru/v1/database/file/add

Send the text and the databaseId from the knowledge base list. The endpoint queues the file for processing. Save the response’s id and send it as fileId when you check the file’s status.

Request headers

ParameterTypeDescription
Authorization*stringAPI key

Request parameters

ParameterTypeDescription
databaseId*stringKnowledge base ID
text*stringFile contents as text
namestringFile name
chunkSizenumberChunk size in tokens. Integer from 0 to 32767. The default is 1024, which is also used when you send 0.
overlapSizenumberOverlap between adjacent chunks in tokens. Integer from 0 to 32767. The default is 128. Set it to 0 to disable overlap.
splitVariablestringText delimiter, up to 12 characters. If this field is nonempty, splitting ignores chunkSize and overlapSize.

When processing the file, the service raises chunk sizes below 256 tokens to 256 and caps overlap at half the chunk size. With splitVariable, it splits the text at the delimiter first. Longer pieces are then split into chunks of up to 4096 tokens without overlap.

Set GPTUNNEL_API_KEY to your API key and GPTUNNEL_DATABASE_ID to the ID from the knowledge base list. The cURL example requires version 8.3 or later.

import json
import os
from urllib.request import Request, urlopen
fields = {
'databaseId': os.environ['GPTUNNEL_DATABASE_ID'],
'name': 'Sample document',
'text': 'The sample document code is NORTH-17.',
}
request = Request(
'https://gptunnel.ru/v1/database/file/add',
headers={'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json'},
method='POST',
data=json.dumps(fields).encode('utf-8'),
)
with urlopen(request, timeout=30) as response:
print(json.load(response))

Identifiers and time are given for example.

{
"id": "66a346f64dcb57627c03d596",
"createDate": "2024-07-26T06:49:27.430Z",
"status": "idle",
"name": "Sample document",
"databaseId": "669b1824c0d8dbde07d07d10",
"chunkSize": 1024,
"overlapSize": 128,
"splitVariable": null,
"tokenCount": 0,
"tokenCost": "0",
"error": null,
"progress": null,
"chunkCount": 0
}