Add instruction fields to knowledge base configuration
This commit is contained in:
@@ -178,6 +178,10 @@ type ChunkingConfig struct {
|
||||
// Languages hints the heuristic patterns. Empty = auto-detect from content.
|
||||
// Examples: ["de"], ["en", "zh"].
|
||||
Languages []string `yaml:"languages,omitempty" json:"languages,omitempty"`
|
||||
// TableMetadataInstructions contains optional business guidance used when
|
||||
// generating searchable summaries for CSV/Excel tables. The system-owned
|
||||
// output contract remains fixed; these instructions only add domain context.
|
||||
TableMetadataInstructions string `yaml:"table_metadata_instructions,omitempty" json:"table_metadata_instructions,omitempty"`
|
||||
}
|
||||
|
||||
// ResolveParserEngine returns the engine name for the given file type
|
||||
@@ -387,6 +391,12 @@ func (c *ImageProcessingConfig) Scan(value interface{}) error {
|
||||
type VLMConfig struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
ModelID string `yaml:"model_id" json:"model_id"`
|
||||
// DescriptionLanguage controls the language used for generated image
|
||||
// captions. Empty means follow the document/request language.
|
||||
DescriptionLanguage string `yaml:"description_language,omitempty" json:"description_language,omitempty"`
|
||||
// CustomInstructions adds KB-specific image interpretation guidance without
|
||||
// replacing the system-owned OCR and Markdown output contract.
|
||||
CustomInstructions string `yaml:"custom_instructions,omitempty" json:"custom_instructions,omitempty"`
|
||||
|
||||
// 兼容老版本
|
||||
// Model Name
|
||||
@@ -421,6 +431,9 @@ type QuestionGenerationConfig struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
// Number of questions to generate per chunk (default: 3, max: 10)
|
||||
QuestionCount int `yaml:"question_count" json:"question_count"`
|
||||
// CustomInstructions describes the intended audience or question style.
|
||||
// It is appended to the stable system question-generation template.
|
||||
CustomInstructions string `yaml:"custom_instructions,omitempty" json:"custom_instructions,omitempty"`
|
||||
}
|
||||
|
||||
// Value implements the driver.Valuer interface
|
||||
@@ -493,6 +506,9 @@ type ExtractConfig struct {
|
||||
Tags []string `yaml:"tags" json:"tags,omitempty"`
|
||||
Nodes []*GraphNode `yaml:"nodes" json:"nodes,omitempty"`
|
||||
Relations []*GraphRelation `yaml:"relations" json:"relations,omitempty"`
|
||||
// CustomInstructions adds domain-specific extraction guidance while the
|
||||
// system keeps ownership of the structured graph output protocol.
|
||||
CustomInstructions string `yaml:"custom_instructions,omitempty" json:"custom_instructions,omitempty"`
|
||||
}
|
||||
|
||||
// Value implements the driver.Valuer interface, used to convert ExtractConfig to database value
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// MaxCustomPromptInstructionsLength bounds user-authored business guidance.
|
||||
// These fields are intentionally much smaller than full prompt templates.
|
||||
const MaxCustomPromptInstructionsLength = 4000
|
||||
|
||||
// AppendCustomPromptInstructions appends user-authored business guidance to a
|
||||
// system-owned prompt. Stable output, safety and citation rules always win.
|
||||
func AppendCustomPromptInstructions(prompt, instructions, label string) string {
|
||||
instructions = strings.TrimSpace(instructions)
|
||||
if instructions == "" {
|
||||
return prompt
|
||||
}
|
||||
if label == "" {
|
||||
label = "custom"
|
||||
}
|
||||
return fmt.Sprintf("%s\n\n<%s_business_instructions>\n%s\n</%s_business_instructions>\n"+
|
||||
"Apply these business instructions only when they do not conflict with the system-owned output format, citation, safety, or factuality rules.",
|
||||
strings.TrimSpace(prompt), label, instructions, label)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppendCustomPromptInstructions(t *testing.T) {
|
||||
t.Run("empty preserves prompt", func(t *testing.T) {
|
||||
if got := AppendCustomPromptInstructions("base", " ", "wiki"); got != "base" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("appends bounded business guidance after base", func(t *testing.T) {
|
||||
got := AppendCustomPromptInstructions("base", " Focus on contracts. ", "wiki")
|
||||
if !strings.HasPrefix(got, "base\n\n<wiki_business_instructions>") {
|
||||
t.Fatalf("unexpected prefix: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "Focus on contracts.") || !strings.Contains(got, "do not conflict") {
|
||||
t.Fatalf("missing guidance or precedence rule: %q", got)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -347,6 +347,12 @@ type WikiConfig struct {
|
||||
// ExtractionGranularity controls how many candidate slugs Pass 0 extracts
|
||||
// per document. Empty / unknown value is treated as WikiExtractionStandard.
|
||||
ExtractionGranularity WikiExtractionGranularity `yaml:"extraction_granularity" json:"extraction_granularity,omitempty"`
|
||||
// ContentInstructions controls tone, structure and emphasis for generated
|
||||
// summary/entity/index prose. Citation and merge rules remain system-owned.
|
||||
ContentInstructions string `yaml:"content_instructions,omitempty" json:"content_instructions,omitempty"`
|
||||
// ExtractionInstructions tells candidate extraction which domain concepts
|
||||
// to emphasize without replacing the stable JSON/citation protocol.
|
||||
ExtractionInstructions string `yaml:"extraction_instructions,omitempty" json:"extraction_instructions,omitempty"`
|
||||
|
||||
// Wiki ingest concurrency is two-level:
|
||||
// 1. batch-level: multiple batches per KB run concurrently in the wiki
|
||||
@@ -465,7 +471,6 @@ type WikiPageListResponse struct {
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
|
||||
// WikiGraphMode enumerates the graph query modes exposed to the API.
|
||||
const (
|
||||
// WikiGraphModeOverview returns the top-N most-connected pages as an
|
||||
|
||||
Reference in New Issue
Block a user