Knowledge base
Creating a Knowledge Base
In this tutorial, you will learn how to create a knowledge base using ZBrain's API. The knowledge base serves as the foundation for building LLM-based (Language Model) applications, allowing you to provide accurate and targeted responses. You can upload data in various formats like PDFs, Word documents, or web pages to populate your knowledge base.
To create a knowledge base using ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To create a knowledge base, you need to send a POST request to a specific URL. The request should include the necessary headers and payload with the knowledge base information.
Request URL:
https://app.zbrain.ai:3000/api/knowledge-base
Request Method:
POST
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Step 2: Craft the Request Payload
The payload should include the optional description and the name of the knowledge base. Ensure that the payload is in a valid JSON format.
Sample Request Body Payload:
Replace "description"
with an optional description for your knowledge base, and "KnowledgeBaseName"
with the desired name for your knowledge base.
Step 3: Send the Request
Using your preferred programming language or API testing tool, send the POST request to the provided URL with the necessary headers and payload. Make sure to replace
<<API Key>>
in theAuthorization
header with your actual API key.
Step 4: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain information about the created knowledge base.
Sample Response:
The
responseData
field contains the details of the created knowledge base, including its name, description, tenant ID, creator, deletion status, activation status, unique ID, creation timestamp, modification timestamp, and version.The
message
field confirms the successful creation of the knowledge base.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully created a knowledge base using ZBrain's API. You can now populate it with relevant data and use it to build LLM-based applications that offer accurate and targeted responses.
Fetching Knowledge Bases
In this tutorial, you will learn how to fetch your knowledge base data using ZBrain's API. By sending a GET request to the provided URL and adjusting the 'limit' and 'skip' parameters, you can retrieve a specific amount of data starting from a particular point. This allows for easy access to your knowledge base content.
To fetch knowledge bases using ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To fetch knowledge bases, you need to send a GET request to a specific URL. The request should include the necessary headers and query parameters.\
Request URL:
https://app.zbrain.ai:3000/api/knowledge-bases?limit=10&skip=0
Request Method:
GET
Query Parameters:
limit
: The number of knowledge bases to retrieve (adjust as needed).skip
: The starting point from which to retrieve the knowledge bases (adjust as needed).
Step 2: Set the Request Headers
Include the required headers in the GET request. These headers help authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API key>>
Content-Type: application/json
Replace <<API key>>
in the Authorization
header with your actual API key.
Step 3: Send the Request
Using your preferred programming language or API testing tool, send the GET request to the provided URL with the necessary headers and query parameters.
Step 4: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain the fetched knowledge base data.
Sample Response:
The
responseData
field contains an array of knowledge bases retrieved. Each knowledge base object includes its unique ID (_id
), name, description, tenant ID, creator, creation timestamp (addedOn
), modification timestamp (modifiedOn
), and a boolean indicating whether imports exist (importsExists
).Thetotal
field specifies the total number of knowledge bases available.The
message
field confirms the successful retrieval of information.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully fetched knowledge bases using ZBrain's API. You can now process and utilize the retrieved data as needed in your application.
How to Get Knowledge Base by ID
In this tutorial, you will learn how to fetch a specific knowledge base by its ID using ZBrain's API. By sending a GET request to the provided URL with the appropriate path parameter, you can retrieve detailed information about the knowledge base, including its name, description, creator, and any associated knowledge base imports.
To fetch a knowledge base by ID using ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To fetch a knowledge base by ID, you need to send a GET request to a specific URL. The request URL should include the placeholder
<knowledgeBaseId>
, which will be replaced with the actual ID of the knowledge base you want to retrieve.Request URL:
https://app.zbrain.ai:3000/api/knowledge-base/<knowledgeBaseId>
Request Method:
GET
Replace <knowledgeBaseId>
in the URL with the ID of the knowledge base you want to fetch.
Step 2: Set the Request Headers
Include the required headers in the GET request. These headers help authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Send the Request
Using your preferred programming language or API testing tool, send the GET request to the provided URL with the necessary headers.
Step 4: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain detailed information about the fetched knowledge base.
Sample Response:
The
responseData
field contains the detailed information about the fetched knowledge base. This includes the knowledge base's unique ID (_id
), name, description, tenant ID, creator, creation timestamp (addedOn
), and an array of knowledge base imports (knowledgeBaseImports
).Each knowledge base import object within theknowledgeBaseImports
array contains details such as the import title, summary, import type, status, embedding information (URL, path, and bucket), file information (URL, path, and bucket), document information (URL, path, and bucket), visited pages, character count, deletion status (isDeleted
), activation status (isActive
), unique ID (_id
), and timestamps (addedOn
andmodifiedOn
).The
message
field confirms the successful retrieval of information.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully fetched a knowledge base by its ID using ZBrain's API. You can now process and utilize the retrieved information as needed in your application.
Creating a Knowledge Base Import
Using FILE
In this tutorial, you will learn how to create a knowledge base import by uploading a file directly into ZBrain using the FILE import type. ZBrain allows users to import various file formats such as PDF, TXT, CSV, DOCX, or XLSX, enabling them to incorporate diverse and relevant information into their knowledge bases.
To create a knowledge base import using the FILE import type in ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To initiate the knowledge base import process, you need to send a POST request to a specific URL. The request URL should include the query parameters
knowledgeBaseId
andimportType
, specifying the ID of the target knowledge base and the import type as "FILE," respectively.Request URL:
https://app.zbrain.ai:3003/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=FILE
Request Method:
POST
Replace <knowledgeBaseId>
in the URL with the actual ID of the target knowledge base.
Step 2: Set the Request Headers
Include the required headers in the POST request. These headers help authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Set the Form Data
When making the POST request, you need to include the file you want to import as part of the form data. Select the desired file, ensuring it is one of the supported formats: PDF, TXT, CSV, DOCX, or XLSX.
Form Data:
file: <<select file>>
Step 4: Send the Request
Using your preferred programming language or API testing tool, send the POST request to the provided URL with the necessary headers and form data, including the selected file.
Step 5: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain information about the knowledge base import that was created.
Sample Response:
The
responseData
field contains an array of knowledge base imports. Each import object provides detailed information about the imported file, including the title, summary, knowledge base ID, imported type (FILE), import status, embedding information (URL, path, and bucket), file information (URL, path, and bucket), document information (URL, path, and bucket), visited pages, character count, deletion status (`isDeleted), activation status (
isActive), unique ID (
_id), input object, error object, timestamps (
addedOnand
modifiedOn`), and storage balance.The
message
field confirms the successful addition of the knowledge base import.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully created a knowledge base import using the FILE import type in ZBrain's API. The uploaded file is now integrated into the designated knowledge base, providing domain-specific information to your AI applications.
Using WEBSITE url
In this tutorial, you will learn how to create a knowledge base import by using a website URL in ZBrain's API. This method allows you to construct a knowledge base by providing the necessary details, such as the knowledge base ID, import type (WEBSITE), the desired number of pages for indexing, and the URL of the website from which you want to create the knowledge base.
To create a knowledge base import using the WEBSITE import type in ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To initiate the knowledge base import process, you need to send a POST request to a specific URL. The request URL should include the query parameters
knowledgeBaseId
andimportType
, specifying the ID of the target knowledge base and the import type as "WEBSITE," respectively.Request URL:
https://app.zbrain.ai:3003/api/knowledge-base-import?knowledgeBaseId=<knowledgeBaseId>&importType=WEBSITE
Request Method:
POST
Replace <knowledgeBaseId>
in the URL with the actual ID of the target knowledge base.
Step 2: Set the Request Headers
Include the required headers in the POST request. These headers help authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Set the Request Payload
When making the POST request, you need to include the request payload, which specifies the number of pages to index and the website URL.
Request Payload:
In the above example, we are indexing 4 pages from the website https://www.leewayhertz.com
. Adjust the values based on your requirements.
Step 4: Send the Request
Using your preferred programming language or API testing tool, send the POST request to the provided URL with the necessary headers and request payload.
Step 5: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain information about the knowledge base import that was created.
Sample Response:
The
responseData
field contains information about the knowledge base import. It includes the title, summary, knowledge base ID, imported type (WEBSITE), import status, embedding information (URL, path, and bucket), file information (URL, path, and bucket), document information (URL, path, and bucket), visited pages, character count, deletion status (isDeleted
), activation status (isActive
), unique ID (_id
), timestamps (addedOn
andmodifiedOn
), and version (__v
).The
message
field confirms the successful addition of the knowledge base import.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully created a knowledge base import using the WEBSITE import type in ZBrain's API. The specified website's pages are now indexed and integrated into the designated knowledge base, providing domain-specific information to your AI applications.
Using API
In this tutorial, you will learn how to create a knowledge base import by using the API import type in ZBrain's API. This method allows you to construct a knowledge base by sending specific data to a ZBrain web address, including the import type (API), a title for the data, the content itself (at least 100 characters), and the API key for security purposes. You can also specify a knowledge base ID to update an existing knowledge base or leave it empty to create a new knowledge base.
To create a knowledge base import using the API import type in ZBrain's API, follow the steps below:
Step 1: Prepare the Request
To initiate the knowledge base import process, you need to send a POST request to a specific URL. The request URL should include the query parameter
importType
with the value set as "API".Request URL:
https://app.zbrain.ai:3003/api/knowledge-base-import-by-api?importType=API
Request Method:
POST
Step 2: Set the Request Headers
Include the required headers in the POST request. These headers help authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Set the Request Payload
When making the POST request, you need to include the request payload, which consists of the title, content, and knowledge base ID.
Request Payload:
In the above example, provide a suitable title for your data in the title
field. The content
field should contain the data content, which should be at least 100 characters long. Specify the knowledgeBaseId
if you want to update an existing knowledge base. Leave it empty to create a new knowledge base.
Step 4: Send the Request
Using your preferred programming language or API testing tool, send the POST request to the provided URL with the necessary headers and request payload.
Step 5: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain information about the knowledge base import that was created.
Sample Response:
The
responseData
field contains information about the knowledge base import. It includes the title, summary, knowledge base ID, imported type (API), import status, embedding information (URL, path, and bucket), file information (URL,path, and bucket), document information (URL, path, and bucket), visited pages, character count, deletion status (isDeleted
), activation status (isActive
), unique ID (_id
), timestamps (addedOn
andmodifiedOn
), and version (__v
).The
message
field confirms the successful addition of the knowledge base import.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully created a knowledge base import using the API import type in ZBrain's API. The specified data has been added to the designated knowledge base, providing domain-specific information to your AI applications.
Updating a Knowledge Base
In this tutorial, you will learn how to update an existing knowledge base in ZBrain using the Update Knowledge Base API. By sending a PUT request with your API key, you can modify the name and description of the knowledge base. It is essential to provide the correct knowledge base ID to ensure the updates are applied to the desired knowledge base.
To update a knowledge base in ZBrain, follow the steps below:
Step 1: Prepare the Request
To update the knowledge base, you need to send a PUT request to the specified URL.
Request URL:
https://app.zbrain.ai:3000/api/knowledge-base
Request Method:
PUT
Step 2: Set the Request Headers
Include the required headers in the PUT request to authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Set the Request Payload
When making the PUT request, include the request payload, which contains the knowledge base ID, the new knowledge base name, and the updated description (optional).
Request Payload:
Replace "knowledgeBaseId"
with the actual ID of the knowledge base you want to update. In the name
field, provide the new name for the knowledge base. If you wish to update the description, provide the new description in the description
field.
Step 4: Send the Request
Using your preferred programming language or API testing tool, send the PUT request to the provided URL with the necessary headers and request payload.
Step 5: Process the Response
Upon successful execution of the request, you will receive a response from the API. The response will contain information about the updated knowledge base.
Sample Response:
The
responseData
field contains the updated information of the knowledge base, including thename
,description
,tenantId
,createdBy
, deletion status (isDeleted
), activation status (isActive
), unique ID (_id
), timestamps (addedOn
andmodifiedOn
), and version (__v
).The
message
field confirms the successful addition of the updated information.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully updated an existing knowledge base in ZBrain using the Update Knowledge Base API. The specified knowledge base's name and description have been modified according to the provided information.
Deleting a Knowledge Base
In this tutorial, you will learn how to delete a specific knowledge base in ZBrain using the Delete Knowledge Base API. By sending a DELETE request to the designated URL with the knowledge base's unique ID in the path and your API key in the headers, you can delete the knowledge base.
To delete a knowledge base in ZBrain, follow the steps below:
Step 1: Prepare the Request
To delete the knowledge base, you need to send a DELETE request to the specified URL, including the knowledge base's unique ID in the path.
Request URL:
https://app.zbrain.ai:3000/api/knowledge-base/<knowledgebaseId>
Request Method:
DELETE
Replace <knowledgebaseId>
in the URL with the actual ID of the knowledge base you want to delete.
Step 2: Set the Request Headers
Include the required headers in the DELETE request to authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Send the Request
Using your preferred programming language or API testing tool, send the DELETE request to the provided URL with the necessary headers.
Step 4: Process the Response
Upon successful execution of the request, you will receive a response from the API indicating that the knowledge base has been deleted.
Sample Response:
The
responseData
field contains the message indicating the successful deletion of the knowledge base.The
message
field confirms the successful deletion of the knowledge base.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully deleted a specific knowledge base in ZBrain using the Delete Knowledge Base API. The knowledge base with the specified ID has been removed from the system.
Deleting a Knowledge Base Import
In this tutorial, you will learn how to delete a specific knowledge base import in ZBrain using the Delete Import API. By sending a DELETE request to the designated URL with the knowledge base import's unique ID in the request payload and your API key in the headers, you can delete the import.
To delete a knowledge base import in ZBrain, follow the steps below:
Step 1: Prepare the Request
To delete the knowledge base import, you need to send a DELETE request to the specified URL.
Request URL:
https://app.zbrain.ai:3000/api/knowledge-base-import
Request Method:DELETE
Step 2: Set the Request Headers
Include the required headers in the DELETE request to authenticate your request and specify the content type.
Request Headers:
Authorization: Bearer <<API Key>>
Content-Type: application/json
Replace <<API Key>>
in the Authorization
header with your actual API key.
Step 3: Set the Request Payload
In the request payload, provide an array of knowledge base import IDs that you want to delete.
Request Payload:
Replace "knowledgeBaseImportId"
with the actual ID of the knowledge base import you want to delete.
Step 4: Send the Request
Using your preferred programming language or API testing tool, send the DELETE request to the provided URL with the necessary headers and payload.
Step 5: Process the Response
Upon successful execution of the request, you will receive a response from the API indicating that the knowledge base import has been deleted.
Sample Response:
The
responseData
field contains the message indicating the successful deletion of the knowledge base import.The
message
field confirms the successful deletion of the knowledge base import.The
success
field indicates whether the request was successful (true
in this case).The
responseCode
field indicates the HTTP response code (200 for success).
That's it! You have successfully deleted a specific knowledge base import in ZBrain using the Delete Import API. The knowledge base import with the specified ID has been removed from the system.
Last updated