Collections a part of the tree answers from when a request names none

On an organization, team, project or key, the narrowest winning: llmgw ctl
kb default, POST /api/v1/kb/defaults, and the console's Knowledge screen. A
request's own X-Llmgw-Knowledge overrides it and none turns it off. A default
never refuses a request: a collection the caller cannot read is left out, and
a failed search answers without passages. Removing a collection takes it out
of every default.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-08 15:52:43 +02:00
1 parent 54ba04c52a
commit 0093cc3d45
16 files changed
+552 -12

No files matched your search

+44 -1
View File
@@ -57,7 +57,18 @@ func newKBCmd(client func() *ctlClient, asJSON *bool) *cobra.Command {
fmt.Fprintf(w, "%s/%s\t%s\t%s (%d)\t%d\t%d\t%s\n", or(c.OrgName, c.Org), c.Name, or(c.OwnerName, c.Owner),
c.EmbedModel, c.Dims, c.Documents, c.Chunks, strings.Join(grants, ", "))
}
return w.Flush()
if err := w.Flush(); err != nil {
return err
}
if len(v.Defaults) > 0 {
fmt.Fprintln(out, "\nAnswered from by default, when a request names no collection:")
w = tab()
for _, d := range v.Defaults {
fmt.Fprintf(w, " %s\t%s\n", or(d.Name, d.Target), strings.Join(d.Collections, ", "))
}
return w.Flush()
}
return nil
},
})
@@ -169,6 +180,38 @@ func newKBCmd(client func() *ctlClient, asJSON *bool) *cobra.Command {
},
})
var clear bool
def := &cobra.Command{
Use: "default TARGET [COLLECTION...]",
Short: "Answer a part of the tree's chat requests from collections, when they name none",
Long: "Requests from TARGET and everything below it are then answered from these\n" +
"collections without naming them (X-Llmgw-Knowledge). The narrowest default\n" +
"wins: a key's over its project's, a project's over its team's. A request's own\n" +
"header overrides it, and X-Llmgw-Knowledge: none turns it off. A collection a\n" +
"caller may not read is left out for them, and a search that fails answers\n" +
"without passages rather than refusing. In force within 30 seconds.",
Example: " llmgw ctl kb default team:Acme/hr Acme/policies Acme/forms\n" +
" llmgw ctl kb default team:Acme/hr --clear",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if clear != (len(args) == 1) {
return fmt.Errorf("name collections, or --clear")
}
body, _ := json.Marshal(adminapi.KBDefaultRequest{Target: args[0], Collections: args[1:]})
if err := client().do(cmd.Context(), "POST", "/api/v1/kb/defaults", json.RawMessage(body), nil); err != nil {
return err
}
if clear {
fmt.Fprintf(cmd.OutOrStdout(), "%s answers from no collection by default\n", args[0])
} else {
fmt.Fprintf(cmd.OutOrStdout(), "%s answers from %s by default\n", args[0], strings.Join(args[1:], ", "))
}
return nil
},
}
def.Flags().BoolVar(&clear, "clear", false, "no default any more")
c.AddCommand(def)
var k int
search := &cobra.Command{
Use: "search COLLECTION QUERY...",
+25
View File
@@ -75,6 +75,14 @@ func (m consoleModel) kbPanel(pw int) (string, string, string) {
fmt.Sprintf("%s (%d)", c.EmbedModel, c.Dims), fmt.Sprint(c.Documents), fmt.Sprint(c.Chunks), dash(strings.Join(grants, ", "))})
}
b.WriteString(table([]string{"COLLECTION", "OWNER", "MODEL", "DOCUMENTS", "CHUNKS", "GRANTED TO"}, rows, m.row, pw, m.inPanel))
if len(k.view.Defaults) > 0 {
b.WriteString("\n\n " + sTitle.Render("BY DEFAULT") + " " + sDim.Render("when a request names no collection") + "\n")
var drows [][]string
for _, d := range k.view.Defaults {
drows = append(drows, []string{or(d.Name, d.Target), strings.Join(d.Collections, ", ")})
}
b.WriteString(table([]string{"FOR", "ANSWERED FROM"}, drows, -1, pw, false))
}
b.WriteString("\n\n " + sDim.Render("On a person's machine: llmgw-kb sync COLLECTION FOLDER"))
return "Knowledge", b.String(), keys
}
@@ -153,6 +161,23 @@ func (m consoleModel) kbMenu(c adminapi.KBCollectionView) *menuDialog {
}})
}
items = append(items,
menuItem{"Answer from it by default…", func(m *consoleModel) tea.Cmd {
m.openForm(&formDialog{title: "Answer from " + name + " by default",
note: "Chat requests from there that name no collection are answered from this one.\n" +
"Replaces that part's default; llmgw ctl kb default sets several.",
fields: []formField{
choiceF("for", []string{"project", "team", "org", "key"}, "team"),
textF("which", "", "ORG/TEAM/PROJECT, ORG/TEAM, ORG, or the ID"),
},
submit: func(m *consoleModel, v []string) (tea.Cmd, error) {
if strings.TrimSpace(v[1]) == "" {
return nil, fmt.Errorf("which %s?", v[0])
}
req := adminapi.KBDefaultRequest{Target: v[0] + ":" + strings.TrimSpace(v[1]), Collections: []string{c.ID}}
return m.call("Default "+c.Name, http.MethodPost, "/api/v1/kb/defaults", req, nil), nil
}})
return nil
}},
menuItem{"Try a search…", func(m *consoleModel) tea.Cmd {
m.openForm(&formDialog{title: "Search " + name,
note: "As an administrator: no tenancy applies. Shows what a question would find.",