-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
111 lines (85 loc) · 2.37 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"context"
"fmt"
"time"
"github.com/fatih/color"
"github.com/lunarianss/Luna/infrastructure/log"
"github.com/lunarianss/Luna/internal/infrastructure/util"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/auth"
"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
)
type WeaviateConsole struct {
client *weaviate.Client
}
func NewWeaviateClient() (*weaviate.Client, error) {
log.NewStdWithOptions()
cfg := weaviate.Config{
Host: "127.0.0.1:8080",
Scheme: "http",
AuthConfig: auth.ApiKey{Value: "WVF5YThaHlkYwhGUSmCRgsX3tD5ngdN8pkih"},
Timeout: 60 * time.Second,
}
client, err := weaviate.NewClient(cfg)
if err != nil {
return nil, err
}
live, err := client.Misc().LiveChecker().Do(context.Background())
if err != nil {
return nil, err
}
if live {
fmt.Println(color.GreenString("weaviate is live!"))
}
return client, nil
}
func (wc *WeaviateConsole) GetAllCollectionDefined() {
context := context.Background()
schema, err := wc.client.Schema().Getter().
Do(context)
if err != nil {
panic(err)
}
fmt.Sprintln("========= All Collection Start ========")
util.LogCompleteInfo(schema)
fmt.Sprintln("========= All Collection End ========")
}
func (wc *WeaviateConsole) GetCollectionObjects(className string) {
ctx := context.Background()
client, err := NewWeaviateClient()
if err != nil {
panic(err)
}
response, err := client.GraphQL().Get().
WithClassName(className).
WithFields(graphql.Field{Name: "text"}, graphql.Field{Name: "doc_id"}, graphql.Field{Name: "app_id"}, graphql.Field{Name: "annotation_id"}, graphql.Field{Name: "_additional", Fields: []graphql.Field{
{Name: "vector"},
{Name: "id"},
}}).
Do(ctx)
if err != nil {
panic(err)
}
fmt.Printf("========= Collection %s Objects Start ========\n", className)
util.LogCompleteInfo(response)
fmt.Printf("========= Collection %s Objects End ========\n", className)
}
func NewConsole() *WeaviateConsole {
client, err := NewWeaviateClient()
if err != nil {
panic(err)
}
return &WeaviateConsole{
client,
}
}
func main() {
console := NewConsole()
// console.GetAllCollectionDefined()
console.GetCollectionObjects("Vector_index_9a532b60_a004_425e_a952_fa5f33c6cdd1_Node")
var a []string = nil
fmt.Println(len(a))
var c = []string{"你", "好"}
fmt.Println(c[1:])
}