mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-03 20:13:03 +00:00
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var queryCmd = &cobra.Command{
|
|
Use: "query <text>",
|
|
Short: "Search indexed documentation",
|
|
Long: `Search indexed documentation using semantic similarity.
|
|
|
|
Returns the most relevant document chunks based on vector similarity
|
|
to the query text.
|
|
|
|
Examples:
|
|
devour query "how to authenticate"
|
|
devour query "API rate limiting" --limit 10
|
|
devour query "deployment" --format json`,
|
|
Args: cobra.MinimumNArgs(1),
|
|
RunE: runQuery,
|
|
}
|
|
|
|
var (
|
|
queryLimit int
|
|
queryFormat string
|
|
queryThreshold float64
|
|
)
|
|
|
|
func init() {
|
|
queryCmd.Flags().IntVarP(&queryLimit, "limit", "l", 5, "maximum number of results")
|
|
queryCmd.Flags().StringVarP(&queryFormat, "format", "f", "text", "output format (text, json, markdown)")
|
|
queryCmd.Flags().Float64Var(&queryThreshold, "threshold", 0.7, "similarity threshold (0-1)")
|
|
}
|
|
|
|
func runQuery(cmd *cobra.Command, args []string) error {
|
|
query := args[0]
|
|
if len(args) > 1 {
|
|
query = fmt.Sprintf("%s", args)
|
|
}
|
|
|
|
fmt.Printf("Searching: %q\n", query)
|
|
fmt.Printf(" Limit: %d\n", queryLimit)
|
|
fmt.Printf(" Threshold: %.2f\n", queryThreshold)
|
|
fmt.Println()
|
|
|
|
// TODO: Implement actual query logic
|
|
// 1. Generate embedding for query
|
|
// 2. Search vector database
|
|
// 3. Format and return results
|
|
|
|
// Placeholder results
|
|
fmt.Println("Results:")
|
|
fmt.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
fmt.Println("⚠️ Query functionality not yet implemented")
|
|
fmt.Println(" Index some documents first with 'devour scrape'")
|
|
|
|
return nil
|
|
}
|