feat(client): enhance knowledge file upload with process configuration support

- Updated the `CreateKnowledgeFromFile` function to accept an optional `processConfig` parameter for per-upload parse configuration overrides.
- Introduced the `KnowledgeProcessOverrides` type to define various parsing settings, including parser engine rules and chunking configurations.
- Modified the API client and related components to handle the new process configuration, improving flexibility in knowledge file uploads.
- Updated documentation and API specifications to reflect the new `process_config` parameter in the upload process.
- Added a new `UploadConfirmHost` component to facilitate user confirmation for uploads, integrating with the updated upload logic.
- Enhanced user experience by providing detailed configuration options during the upload process.
This commit is contained in:
wizardchen
2026-06-09 17:49:39 +08:00
committed by lyingbug
parent 589d2a6e52
commit ed9e780c8c
41 changed files with 3546 additions and 596 deletions
+27
View File
@@ -83,6 +83,19 @@ var ErrDuplicateFile = errors.New("file already exists")
// ErrDuplicateURL is returned when attempting to create a knowledge entry with a URL that already exists
var ErrDuplicateURL = errors.New("URL already exists")
// KnowledgeProcessOverrides stores per-upload parse config overrides sent as process_config.
// When nil, the server uses the knowledge base defaults only.
type KnowledgeProcessOverrides struct {
ParserEngineRules []ParserEngineRule `json:"parser_engine_rules,omitempty"`
ChunkingConfig *ChunkingConfig `json:"chunking_config,omitempty"`
EnableMultimodel *bool `json:"enable_multimodel,omitempty"`
VLMConfig *VLMConfig `json:"vlm_config,omitempty"`
ASRConfig *ASRConfig `json:"asr_config,omitempty"`
QuestionGenerationConfig *QuestionGenerationConfig `json:"question_generation_config,omitempty"`
GraphEnabled *bool `json:"graph_enabled,omitempty"`
ExtractConfig *ExtractConfig `json:"extract_config,omitempty"`
}
// CreateKnowledgeFromFile creates a knowledge entry from a local file path
// Parameters:
// - knowledgeBaseID: The ID of the knowledge base
@@ -91,8 +104,10 @@ var ErrDuplicateURL = errors.New("URL already exists")
// - enableMultimodel: Optional flag to enable multimodal processing
// - customFileName: Optional custom file name (useful for folder uploads with path)
// - channel: Optional ingestion channel (e.g. "web", "api", "wechat"); empty defaults to "web"
// - processConfig: Optional parse config overrides (serialized as process_config form field)
func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
knowledgeBaseID string, filePath string, metadata map[string]string, enableMultimodel *bool, customFileName string, channel string,
processConfig *KnowledgeProcessOverrides,
) (*Knowledge, error) {
// Open the local file
file, err := os.Open(filePath)
@@ -159,6 +174,16 @@ func (c *Client) CreateKnowledgeFromFile(ctx context.Context,
}
}
if processConfig != nil {
processConfigBytes, err := json.Marshal(processConfig)
if err != nil {
return nil, fmt.Errorf("failed to serialize process_config: %w", err)
}
if err := writer.WriteField("process_config", string(processConfigBytes)); err != nil {
return nil, fmt.Errorf("failed to write process_config field: %w", err)
}
}
// Close the multipart writer
err = writer.Close()
if err != nil {
@@ -209,6 +234,8 @@ type CreateKnowledgeFromURLRequest struct {
TagID string `json:"tag_id,omitempty"`
// Channel identifies the ingestion channel (e.g. "web", "browser_extension", "api")
Channel string `json:"channel,omitempty"`
// ProcessConfig is optional per-upload parse config overrides (KnowledgeProcessOverrides).
ProcessConfig *KnowledgeProcessOverrides `json:"process_config,omitempty"`
}
// CreateKnowledgeFromURL creates a knowledge entry from a URL.