Skip to main content
This tutorial will provide a detailed guide on how to use the XperAI platform’s Knowledgebase API to create a knowledgebase, upload files, and process documents.
Reference code: XpertAI SDK Example

Preparation

Before making API calls, you need to prepare the following credentials and information, which can be configured in an environment variables file (XPERTAI_API_URL and XPERTAI_API_KEY):

How to Obtain These Credentials

  1. API_URL and API_KEY
    • Log in to the XperAI platform’s Digital Expert or Knowledgebase.
    • Navigate to the “Settings” -> “API Keys” page.
    • Generate or copy your API key.
    • The API base URL is typically https://api.xpertai.cn/api/ai/.
  2. Workspace ID
    • In the XperAI console, access your workspace.
    • The workspace ID can be found in the browser’s address bar.
    • The format is typically a UUID (e.g., 23f2b2ff-9318-43b6-a986-928fcf70d4ea).
  3. Copilot ID
    • In the XperAI settings page, go to the “AI Copilot” section.
    • Select the copilot you want to associate.
    • The ID can be found on the copilot provider icon.
    • The format is typically a UUID (e.g., 9ff28c7c-3e63-4ced-b855-2782d79a21b3).
  4. Knowledgebase System Integration ID (optional, required only for external knowledgebase)
    • If you are using an external knowledgebase integration, find this ID in the integration settings.

Install Required Dependencies

API Call Steps

1. Create a Knowledgebase

First, we need to create a knowledgebase container:

2. Upload a File

Upload a local file to the XperAI platform:

3. Create a Document Association

Create a document in the knowledgebase from the uploaded file:

4. Start Embedding Process

Initiate the vectorization process for the document:

5. Check Processing Status

Check the progress of document processing:

Complete Usage Example

Notes

  1. Ensure all ID parameters use the correct values obtained from the XperAI platform.
  2. Safeguard your API key and do not expose it or commit it to version control systems.
  3. File uploads have size limits; refer to the official documentation for specific restrictions.
  4. Document processing time depends on file size and content complexity.
  5. It is recommended to implement appropriate error handling and retry mechanisms for improved reliability.
By following these steps, you can successfully create a knowledgebase, upload documents, and complete the vectorization process, preparing for subsequent intelligent Q&A and retrieval functions.