Skip to main content

Overview

Upload document files to create a knowledge base entry. The system automatically extracts text content and performs asynchronous vectorization using embeddings, enabling semantic search and RAG (Retrieval-Augmented Generation) capabilities. Endpoint: POST /api/knowledgebase/upload Rate Limit: 3 requests per time window (Global + IP-based)

Vectorization Workflow

The upload process involves asynchronous vectorization:
  1. Upload & Storage - File is validated and stored with metadata
  2. Status: PENDING - Knowledge base entry is created with initial status
  3. Status: PROCESSING - Background job extracts text and generates embeddings
  4. Status: COMPLETED - Vectors are stored and ready for querying
  5. Status: FAILED - If vectorization fails, use the revectorize endpoint to retry
Vectorization happens asynchronously. After upload, poll the status using GET /api/knowledgebase/ or list endpoint to check when vectorStatus becomes COMPLETED.

Request

Headers

Content-Type
string
required
Must be multipart/form-data

Body Parameters

file
file
required
The document file to upload. Supported formats include PDF, DOCX, DOC, TXT, and other text-extractable formats.Max file size: Check your server configuration (typically 10-50 MB)
name
string
Custom display name for the knowledge base entry. If not provided, the original filename will be used.Example: "Technical Documentation v2.1"
category
string
Category to organize the knowledge base. Can be used for filtering and grouping.Example: "Technical"

Response

code
integer
Response status code. 200 indicates success.
message
string
Response message. "success" on successful upload.
data
object
Upload result containing knowledge base metadata.

Examples

curl -X POST 'http://localhost:8080/api/knowledgebase/upload' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@/path/to/document.pdf' \
  -F 'name=Technical Documentation' \
  -F 'category=Engineering'

Response Example

{
  "code": 200,
  "message": "success",
  "data": {
    "id": 42,
    "name": "Technical Documentation",
    "originalFilename": "document.pdf",
    "fileSize": 2457600,
    "contentType": "application/pdf",
    "category": "Engineering",
    "vectorStatus": "PENDING",
    "uploadedAt": "2026-03-10T14:30:00"
  }
}

Error Responses

code
integer
Error code (non-200 value)
message
string
Error description

Common Errors

  • 400 Bad Request - Missing required file parameter or invalid file format
  • 413 Payload Too Large - File exceeds maximum allowed size
  • 429 Too Many Requests - Rate limit exceeded (3 requests per window)
  • 500 Internal Server Error - File storage or processing failure
{
  "code": 400,
  "message": "文件不能为空"
}

Post-Upload: Check Vectorization Status

After uploading, monitor the vectorization status:
# Get detailed status
curl 'http://localhost:8080/api/knowledgebase/{id}'
Once vectorStatus is COMPLETED, the knowledge base is ready for querying. If status is FAILED, check the vectorError field and use the revectorize endpoint to retry.

Revectorize Endpoint

If vectorization fails, manually retry the process: Endpoint: POST /api/knowledgebase/{id}/revectorize Rate Limit: 2 requests per time window

Request

curl -X POST 'http://localhost:8080/api/knowledgebase/42/revectorize'

Response

{
  "code": 200,
  "message": "success",
  "data": null
}
The vectorization process will restart asynchronously. Check the status again to monitor progress.

See Also

Build docs developers (and LLMs) love