Fixes across 25 files addressing 46+ review comments: - pkg/ai/metrics.go: handle error from Close() on writable file handle - pkg/ansible: restore loop vars after loop, restore become settings, fix Upload with become=true and no password (use sudo -n), honour SSH timeout config, use E() helper for contextual errors, quote git refs in checkout commands - pkg/rag: validate chunk config, guard negative-to-uint64 conversion, use E() helper for errors, add context timeout to Ollama HTTP calls - pkg/deploy/python: fix exec.ExitError type assertion (was os.PathError), handle os.UserHomeDir() error - pkg/build/buildcmd: use cmd.Context() instead of context.Background() for proper Ctrl+C cancellation - install.bat: add curl timeouts, CRLF line endings, use --connect-timeout for archive downloads - install.sh: use absolute path for version check in CI mode - tools/rag: fix broken ingest.py function def, escape HTML in query.py, pin qdrant-client version, add markdown code block languages - internal/cmd/rag: add chunk size validation, env override handling Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
84 lines
2.9 KiB
Go
84 lines
2.9 KiB
Go
package rag
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/host-uk/core/pkg/i18n"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Shared flags
|
|
var (
|
|
qdrantHost string
|
|
qdrantPort int
|
|
ollamaHost string
|
|
ollamaPort int
|
|
model string
|
|
verbose bool
|
|
)
|
|
|
|
var ragCmd = &cobra.Command{
|
|
Use: "rag",
|
|
Short: i18n.T("cmd.rag.short"),
|
|
Long: i18n.T("cmd.rag.long"),
|
|
}
|
|
|
|
func initFlags() {
|
|
// Qdrant connection flags (persistent) - defaults to localhost for local development
|
|
qHost := "localhost"
|
|
if v := os.Getenv("QDRANT_HOST"); v != "" {
|
|
qHost = v
|
|
}
|
|
ragCmd.PersistentFlags().StringVar(&qdrantHost, "qdrant-host", qHost, i18n.T("cmd.rag.flag.qdrant_host"))
|
|
|
|
qPort := 6334
|
|
if v := os.Getenv("QDRANT_PORT"); v != "" {
|
|
if p, err := strconv.Atoi(v); err == nil {
|
|
qPort = p
|
|
}
|
|
}
|
|
ragCmd.PersistentFlags().IntVar(&qdrantPort, "qdrant-port", qPort, i18n.T("cmd.rag.flag.qdrant_port"))
|
|
|
|
// Ollama connection flags (persistent) - defaults to localhost for local development
|
|
oHost := "localhost"
|
|
if v := os.Getenv("OLLAMA_HOST"); v != "" {
|
|
oHost = v
|
|
}
|
|
ragCmd.PersistentFlags().StringVar(&ollamaHost, "ollama-host", oHost, i18n.T("cmd.rag.flag.ollama_host"))
|
|
|
|
oPort := 11434
|
|
if v := os.Getenv("OLLAMA_PORT"); v != "" {
|
|
if p, err := strconv.Atoi(v); err == nil {
|
|
oPort = p
|
|
}
|
|
}
|
|
ragCmd.PersistentFlags().IntVar(&ollamaPort, "ollama-port", oPort, i18n.T("cmd.rag.flag.ollama_port"))
|
|
|
|
m := "nomic-embed-text"
|
|
if v := os.Getenv("EMBEDDING_MODEL"); v != "" {
|
|
m = v
|
|
}
|
|
ragCmd.PersistentFlags().StringVar(&model, "model", m, i18n.T("cmd.rag.flag.model"))
|
|
|
|
// Verbose flag (persistent)
|
|
ragCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, i18n.T("common.flag.verbose"))
|
|
|
|
// Ingest command flags
|
|
ingestCmd.Flags().StringVar(&collection, "collection", "hostuk-docs", i18n.T("cmd.rag.ingest.flag.collection"))
|
|
ingestCmd.Flags().BoolVar(&recreate, "recreate", false, i18n.T("cmd.rag.ingest.flag.recreate"))
|
|
ingestCmd.Flags().IntVar(&chunkSize, "chunk-size", 500, i18n.T("cmd.rag.ingest.flag.chunk_size"))
|
|
ingestCmd.Flags().IntVar(&chunkOverlap, "chunk-overlap", 50, i18n.T("cmd.rag.ingest.flag.chunk_overlap"))
|
|
|
|
// Query command flags
|
|
queryCmd.Flags().StringVar(&queryCollection, "collection", "hostuk-docs", i18n.T("cmd.rag.query.flag.collection"))
|
|
queryCmd.Flags().IntVar(&limit, "top", 5, i18n.T("cmd.rag.query.flag.top"))
|
|
queryCmd.Flags().Float32Var(&threshold, "threshold", 0.5, i18n.T("cmd.rag.query.flag.threshold"))
|
|
queryCmd.Flags().StringVar(&category, "category", "", i18n.T("cmd.rag.query.flag.category"))
|
|
queryCmd.Flags().StringVar(&format, "format", "text", i18n.T("cmd.rag.query.flag.format"))
|
|
|
|
// Collections command flags
|
|
collectionsCmd.Flags().BoolVar(&listCollections, "list", false, i18n.T("cmd.rag.collections.flag.list"))
|
|
collectionsCmd.Flags().BoolVar(&showStats, "stats", false, i18n.T("cmd.rag.collections.flag.stats"))
|
|
collectionsCmd.Flags().StringVar(&deleteCollection, "delete", "", i18n.T("cmd.rag.collections.flag.delete"))
|
|
}
|