add_file

Function

Adds a single document to a knowledge base, embeds information obtained after file splitting, and saves the information to a vector database. Document chunks are saved in a document database, and document records are saved in a knowledge base. These operations can be performed only by the knowledge base administrator.

Prototype

def add_file(file, texts, embed_func, metadatas)

Parameters

Parameter

Data Type

Required/Optional

Description

file

pathlib.Path

Required

pathlib.Path object of the uploaded document. The file path length is [1, 1024]. The file path cannot be a soft link and cannot contain two consecutive dots (..). The file name length cannot exceed 200 characters. The storage path cannot include the following paths: ["/etc", "/usr/bin", "/usr/lib", "/usr/lib64", "/sys/", "/dev/", "/sbin", "/tmp"].

texts

List[str]

Required

List after document splitting. The value must be the same as that of metadatas. The list length range is [1, 1000 × 1000], and the character string length range is [1, 128 × 1024 × 1024].

embed_func

Dict

Required

An embedded function that converts text or images into vectors.

Only the {'dense': x, 'sparse': y} format is allowed. x and y are the callback functions of dense and sparse vectors, respectively. x and y cannot be None at the same time.

metadatas

List[dict]

Optional

Metadata of document chunks. The default value is None. The string length of the element dictionary in the list cannot exceed 128 × 1024 × 1024 characters, the dictionary length cannot exceed 1024 characters, and the dictionary can contain a maximum of one nested layer. The value must be the same as that of texts. The list length range is [1, 1000 × 1000].