-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_search.go
54 lines (41 loc) · 1.05 KB
/
cmd_search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"github.com/hashicorp/go-retryablehttp"
"github.com/shopwarelabs/copilot-extension/config"
"github.com/shopwarelabs/copilot-extension/copilot"
"github.com/spf13/cobra"
)
var cmdSearch = &cobra.Command{
Use: "search",
Short: "Search for documents",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.New()
if err != nil {
return err
}
collection, err := config.GetCollection()
if err != nil {
return err
}
embeddings, err := copilot.Embeddings(cmd.Context(), retryablehttp.NewClient(), cfg.LocalGitHubIntegrationID, cfg.LocalGitHubToken, &copilot.EmbeddingsRequest{
Model: copilot.ModelEmbeddings,
Input: []string{args[0]},
})
if err != nil {
return err
}
result, err := collection.QueryEmbedding(cmd.Context(), embeddings.Data[0].Embedding, 20, nil, nil)
if err != nil {
return err
}
for _, r := range result {
fmt.Printf("%f - %s\n", r.Similarity, r.ID)
}
return nil
},
}
func init() {
rootCmd.AddCommand(cmdSearch)
}