Comment on page
📚

Knowledge base

ZBrain uses a knowledge base as the foundation for building LLM-based applications. Users can upload their data in any format, such as PDFs, Word documents or web pages, to create this knowledge base. The knowledge base is the source of your app's domain-specific information, allowing it to offer accurate and targeted responses.

Create knowledge base

To create a knowledge base on ZBrain, send a POST request to a given URL with their specific information. They ensure that the payload includes an optional description and the name of the knowledge base while confirming that the necessary headers are correctly incorporated.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base
  • Request Method: POST
  • Request Payload:
    1. 1.
      description: << "some description optional" >>
    2. 2.
      name: << knowledge base name >>
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API Key >>
    2. 2.
      Content-Type: application/json
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
description
description about knowledge base
name
name to the knowledge base
  • Sample Request Body Payload:
    {
    "description": "description",
    "name": "KnowledgeBaseName",
    }
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
},
body: JSON.stringify({
"description": "description",
"name": "KnowledgeBaseName"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://services.zbrain.ai:3000/api/knowledge-base"
payload = json.dumps({
"description": "description",
"name": "KnowledgeBaseName",
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-base' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API token>' \
--data '{
"description": "description",
"name": "KnowledgeBaseName",
}'
  • Sample Response:
    {
    "responseData": {
    "name": "string",
    "description": "string",
    "tenantId": "string",
    "createdBy": "string",
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0
    },
    "message": "Knowledge base created successfully",
    "success": true,
    "responseCode": 200
    }

Get Knowledge bases

Using the provided ZBrain API, users can easily fetch their knowledge base data. By sending a GET request to the given URL and adjusting the 'limit' and 'skip' parameters, users can tailor the amount of data retrieved and its starting point, simplifying access to their specific knowledge base content.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-bases?limit=10&skip=0
  • Request Method: GET
  • Query strings:
    1. 1.
      skip: << numeric value >>
    2. 2.
      limit: << numeric value >>
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API key>>
    2. 2.
      Content-Type: application/json
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
skip
no.of knowledge bases to skip
limit
no.of knowledge bases to listout
  • Sample Request Query Payload:
    ?limit=10&skip=0
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://services.zbrain.ai:3000/api/knowledge-bases?limit=10&skip=0',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
},
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://services.zbrain.ai:3000/api/knowledge-bases?limit=10&skip=0"
payload = {}
headers = {
'Authorization': 'Bearer <API token>'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-bases?limit=10&skip=0' \
--header 'Authorization: Bearer <API token>'
  • Sample Response:
    {
    "responseData": {
    "data": [
    {
    "_id": "string",
    "name": "string",
    "description": "string",
    "tenantId": "string",
    "createdBy": "string",
    "addedOn": number,
    "modifiedOn": number,
    "importsExists": boolean
    }
    ],
    "total": number
    },
    "message": "Information fetched successfully",
    "success": true,
    "responseCode": 200
    }

Get Knowledge base by Id

  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base/<knowledgeBaseId>
  • Request Method: GET
  • Path parameters:
    1. 1.
      knowledgebaseId : << knowledgebaseId >>
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API Key >>
    2. 2.
      Content-Type: application/json
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
knowledgeBaseId
unique id (_id) of knowledge base (get it from the Get knowledge bases Api)
  • Sample Path parameters:
    /knowledge-base/<knowledgeBaseId>
  • Code snippets:
Node Js
Python - Requests
cURL
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base/<knowledgebaseId>',
'headers': {
'Authorization': 'Bearer <API token>'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://services.zbrain.ai:3000/api/knowledge-base/<knowledgebaseId>"
payload = {}
headers = {
'Authorization': 'Bearer <API token>'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-base/<knowledgebaseId>' \
--header 'Authorization: Bearer <API token>'
  • Sample Response:
    {
    "responseData": {
    "_id": "string",
    "name": "string",
    "description": "string",
    "tenantId": "string",
    "createdBy": "string",
    "addedOn": number,
    "knowledgeBaseImports": [
    {
    "title": "string",
    "summary": "string",
    "knowledgeBaseId": "string",
    "importedType": "string",
    "status": "string",
    "embedding": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "file": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "document": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "visitedPages": ["string"],
    "characters": number,
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0
    }
    ]
    },
    "message": "Information fetched successfully",
    "success": true,
    "responseCode": 200
    }

Knowledge base import creation types

On ZBrain, users have multiple options to create a knowledge base by importing information. They can import data from files such as PDF, TXT, CSV, DOCX, or XLSX, website links, or even through APIs. This approach enables users to gather and integrate relevant information into their knowledge base, feeding their AI applications with accurate and domain-specific data from diverse sources.

Using FILE

ZBrain allows users to create a knowledge base by importing files directly into the system using a specified API. Users can seamlessly import file types such as PDF, TXT, CSV, DOCX, or XLSX into their designated knowledge base by initiating a POST request to the provided URL, ensuring that the AI applications have direct access to the required domain-specific information.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=FILE
  • Request Method: POST
  • Query Strings:
    1. 1.
      knowledgeBaseId: << knowledgeBaseId >>
    2. 2.
      importType:FILE
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API Key >>
    2. 2.
      Content-Type: application/json
  • form data:
    1. 1.
      file : << select file (Supported formats : PDF, TXT, CSV, DOCX or XLSX)>>
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
knowledgeBaseId
unique id (_id) of knowledge base to where the file to be imported (get it from the Get knowledge bases Api)
importType
method of importing the content
file
in formdata user needs to select the file to be uploaded and these are the supported file formates PDF, TXT, CSV, DOCX or XLSX
  • Sample Request Query Strings:
    ?knowledgeBaseId=<knowledgeBaseId>&importType=FILE
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=FILE',
'headers': {
'Authorization': 'Bearer <API token>'
},
formData: {
'file': {
'value': fs.createReadStream('</path/to/file>'),
'options': {
'filename': '<file name>',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=FILE"
payload = {}
files=[
('file',('fileName',open('/path/to/file','rb'),'application/pdf'))
]
headers = {
'Authorization': 'Bearer <API token>'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=FILE' \
--header 'Authorization: Bearer <API token>' \
--form 'file=@"<path/to/file>"'
  • Sample Response:
    {
    "responseData": [
    {
    "title": "string",
    "summary": "string",
    "knowledgeBaseId": "string",
    "importedType": "string",
    "status": "string",
    "embedding": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "file": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "document": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "visitedPages": ["string"],
    "characters": number,
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "input": object,
    "error": object,
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0,
    "storageBalance": number
    }
    ],
    "message": "Knowledge base import added successfully",
    "success": true,
    "responseCode": 200
    }

Using WEBSITE url

When one seeks to construct a Zbrain knowledge base using a website, they must employ a certain web address or API. This process involves providing necessary details such as the knowledge base's identification, the import type (in this instance, a website), and the desired number of pages for indexing. Including the website URL from which the knowledge base will be created is crucial. Additionally, they must authenticate their request with their API key.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE
  • Request Method: POST
  • Query Strings:
    1. 1.
      knowledgeBaseId: << knowledgeBaseId >>
    2. 2.
      importType:WEBSITE
  • Request Payload:
    1. 1.
      numberOfPages: << No.of pages to index>>
    2. 2.
      websiteUrl:<< URL >>
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API Key>>
    2. 2.
      Content-Type: application/json
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
knowledgeBaseId
unique id (_id) of knowledge base to where the file to be imported (get it from the Get knowledge bases Api)
importType
method of importing the content
numberOfPages
no.of pages to index
websiteUrl
URL of the website
  • Sample Request Body Payload:
    {
    "numberOfPages": 4,
    "websiteUrl": "https://www.leewayhertz.com"
    }
  • Sample Request Query Payload:
    ?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
},
body: JSON.stringify({
"numberOfPages": <No.of pages to index>,
"websiteUrl": "<url>"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE"
payload = json.dumps({
"numberOfPages": <No.of pages to index>,
"websiteUrl": "<url>"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API token>' \
--data '{
"numberOfPages":<No.of pages to index>,
"websiteUrl":"<url>"
}'
  • Sample Response:
    {
    "responseData": {
    "title": "string",
    "summary": "string",
    "knowledgeBaseId": "string",
    "importedType": "string",
    "status": "string",
    "embedding": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "file": {
    ""url": "string",
    "path": "string",
    "bucket": "string"
    },
    "document": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "visitedPages": ["string"],
    "characters": number,
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0
    },
    "message": "Knowledge base import added successfully",
    "success": true,
    "responseCode": 200
    }

Using API

When someone aims to construct a Zbrain knowledge base utilizing an API, they send specific data to a Zbrain web address. The information comprises the type of activity (API), a title for their data, and the data content itself, which should span at least 100 characters. They also need to include their API key for security purposes.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base-import-by-api?importType=API
  • Request Method: POST
  • Query Strings:
    1. 1.
      importType: API
  • Request Headers:
    1. 1.
      Authorization: Bearer <<api key>>
    2. 2.
      Content-Type: application/json
  • Request Payload:
    1. 1.
      title: <Enter your file name>
    2. 2.
      content: <<Enter your content not less than 100 characters>>
    3. 3.
      knowledgeBaseId : << knowledgeBaseId >>
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
importType
method of importing the content
title
title of the file
content
the content that will be uploaded to knowledge base and it should not be less than 100 characters
knowledgeBaseId
unique id (_id) of knowledge base to where the file to be imported (get it from the Get knowledge bases Api)
  • Sample Request Body Payload:
    {
    "title": "fileName",
    "content": "file content",
    "knowledgeBaseId": "knowledgeBaseId"
    }
Note: If knowledgeBaseId is empty, new knowledge base will be created. Otherwise, specified knowledge base will get updated.
  • Sample Request Query Payload:
    ?importType=API
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base-import-by-api?importType=API',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
},
body: JSON.stringify({
"title": "<name>",
"content": "<content>",
"knowledgeBaseId": "<knowledgeBaseId>"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://services.zbrain.ai:3000/api/knowledge-base-import-by-api?importType=API"
payload = json.dumps({
"title": "<name>",
"content": "<content>",
"knowledgeBaseId": "<knowledgeBaseId>"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
curl --location 'https://services.zbrain.ai:3000/api/knowledge-base-import-by-api?importType=API' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API token>' \
--data '{
"title": "<name>",
"content": "<content>",
"knowledgeBaseId" :"<knowledgeBaseId>"
}'
  • Sample Response:
    {
    "responseData": {
    "title": "string",
    "summary": "string",
    "knowledgeBaseId": "string",
    "importedType": "string",
    "status": "string",
    "embedding": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "file": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "document": {
    "url": "string",
    "path": "string",
    "bucket": "string"
    },
    "visitedPages": ["string"],
    "characters": number,
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0
    },
    "message": "Knowledge base import added successfully",
    "success": true,
    "responseCode": 200
    }

Update Knowledge base

When a user wishes to update an existing knowledge base in Zbrain, they can utilize the following specific API, which sends a PUT request, along with their API key, to modify the knowledge base's name and description. Providing the correct knowledge base ID is important to ensure the updates are applied to the desired base.
  • Request URL:https://services.zbrain.ai:3000/api/knowledge-base
  • Request Method: PUT
  • Request Payload:
    1. 1.
      description: << Enter new description (optional)>>
    2. 2.
      knowledgeBaseId: << knowledgeBaseId >>
    3. 3.
      name: << Enter new knowledge base name >>
  • Request Headers:
    1. 1.
      Authorization: Bearer <<API Key>>
    2. 2.
      Content-Type: application/json
Parameters
Authorization
Bearer API-Key (get it from settings > profile from https://app.zbrain.ai/settings/profile )
knowledgeBaseId
unique id (_id) of knowledge base to where the file to be imported (get it from the Get knowledge bases Api)
name
knowledge base name
description
description about knowledge base
  • Sample Request Body Payload:
{
"knowledgeBaseId": "knowledgeBaseId",
"name": "sample name",
"description": "description",
}
  • Code snippets:
Node Js
Python
cURL
var request = require('request');
var options = {
'method': 'PUT',
'url': 'https://services.zbrain.ai:3000/api/knowledge-base',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
},
body: JSON.stringify({
"description": "<description>",
"knowledgeBaseId": "<knowledgeBaseId>",
"name": "<name>"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://services.zbrain.ai:3000/api/knowledge-base"
payload = json.dumps({
"description": "<description>",
"knowledgeBaseId": "<knowledgeBaseId>",
"name": "<name>"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <API token>'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
curl --location --request PUT 'https://services.zbrain.ai:3000/api/knowledge-base' \
--header 'Content-Type: application/json' \
--header 'Authorization': 'Bearer <API token>' \
--data '{
"description": "<description>",
"knowledgeBaseId": "<knowledgeBaseId>",
"name": "<name>"
}'
  • Sample Response:
    {
    "responseData": {
    "name": "string",
    "description": "string",
    "tenantId": "string",
    "createdBy": "string",
    "isDeleted": boolean,
    "isActive": boolean,
    "_id": "string",
    "addedOn": number,
    "modifiedOn": number,
    "__v": 0
    },
    "message": "Information added successfully",
    "success": true,
    "responseCode": 200
    }

Delete Knowledge base

If a user wishes to delete a specific knowledge base in Zbrain, the following API is used, which sends a DELETE request to the designated URL, including the knowledge base's unique ID in the path. The request must also contain its API key in the header for authorization.
  • Request URL: https://services.zbrain.ai:3000/api/knowledge-base/<knowledgebaseId>
  • Request Method: DELETE
  • Path parameters: