d54a7a5834
Roadmap 3-1. Verb-noun shape borrowed from gh search (gh search repos / code / commits / issues / prs verified against the gh manual). Subcommands: - `search chunks "<q>" --kb X` — hybrid retrieval (RAG search). - `search kb "<q>"` — case-insensitive substring match across KB names and descriptions; sorted by name length (shortest hits first). - `search docs "<q>" --kb X` — pages through ListKnowledge filtering by title / file_name; stops once --limit matches are found. - `search sessions "<q>"` — pages through GetSessionsByTenant filtering by title / description. kb / docs / sessions are client-side filters because the server has no fuzzy search endpoint for any of them. ListKnowledgeBases returns the full tenant catalog in one call; the doc/session walkers chunk at 200 per request and stop early on limit. The parent `search` command is a pure dispatcher — there is no bare- positional form (no `weknora search "<q>"`). Cleanups surfaced by the post-commit reviewer round: - UX consistency: search docs's displayDocName ordered Title → FileName → "-", while doc list's displayName uses FileName → Title → ID. Same Knowledge rendered differently across commands. Aligned search docs on doc list's existing FileName-first convention. - cmdutil.ResolveKBFlag(ctx, lister, raw) — extracted the `IsKBID ? raw : ResolveKBNameToID` block duplicated across chunks and docs. - text.ContainsFold(needle, fields...) — replaces inline `strings.Contains(strings.ToLower(field), needle)` patterns. 37 unit tests across chunks/kb/docs/sessions plus the parent registration smoke-test. Roadmap: 3-1.
40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
// Package search implements the `weknora search` command tree:
|
|
// chunks / kb / docs / sessions. Verb-noun shape borrowed from
|
|
// gh search (gh search repos / code / commits / issues / prs).
|
|
package search
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/Tencent/WeKnora/cli/internal/agent"
|
|
"github.com/Tencent/WeKnora/cli/internal/cmdutil"
|
|
)
|
|
|
|
// NewCmdSearch builds the `weknora search` parent. Pure dispatcher to the
|
|
// four subcommands; no positional/legacy form.
|
|
func NewCmdSearch(f *cmdutil.Factory) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "search",
|
|
Short: "Search across chunks, knowledge bases, documents, or sessions",
|
|
Long: `Verb-noun search tree (gh search idiom):
|
|
|
|
search chunks "<q>" --kb X hybrid retrieval (RAG search)
|
|
search kb "<q>" find KBs by name / description
|
|
search docs "<q>" --kb X find documents inside a KB
|
|
search sessions "<q>" find chat sessions by title / description`,
|
|
Example: ` weknora search chunks "what is RAG?" --kb engineering
|
|
weknora search kb "marketing"
|
|
weknora search docs "Q3 forecast" --kb finance
|
|
weknora search sessions "onboarding"`,
|
|
Args: cobra.NoArgs,
|
|
Run: func(c *cobra.Command, _ []string) { _ = c.Help() },
|
|
}
|
|
agent.SetAgentHelp(cmd, "Search parent. Use `search chunks/kb/docs/sessions <q>` — there is no bare-positional form.")
|
|
|
|
cmd.AddCommand(NewCmdChunks(f))
|
|
cmd.AddCommand(NewCmdKB(f))
|
|
cmd.AddCommand(NewCmdDocs(f))
|
|
cmd.AddCommand(NewCmdSessions(f))
|
|
return cmd
|
|
}
|