Skip to content

Commit

Permalink
add schema with prompt class, specifically no vectorizer module
Browse files Browse the repository at this point in the history
  • Loading branch information
ili16 committed Jan 9, 2024
1 parent 8d49ea0 commit fbbe042
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
)

func main() {

// create Weaviate schema
weaviate.CreateSchema()

router := gin.Default()

router.GET("/weaviate/schema", func(c *gin.Context) {
Expand Down
44 changes: 44 additions & 0 deletions weaviate/weaviate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package weaviate
import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/auth"
"github.com/weaviate/weaviate/entities/models"
)

func RetrieveSchema() ([]byte, error) {
Expand Down Expand Up @@ -35,3 +37,45 @@ func RetrieveSchema() ([]byte, error) {

return jsonSchema, nil
}

func CreateSchema() {

cfg := weaviate.Config{
Host: os.Getenv("WEAVIATE_HOST"), // Replace with your endpoint
Scheme: "http",
AuthConfig: auth.ApiKey{Value: os.Getenv("WEAVIATE_KEY")},
}

client, err := weaviate.NewClient(cfg)
if err != nil {
panic(err)
}

className := "Prompt"

exists, err := client.Schema().ClassExistenceChecker().WithClassName(className).Do(context.Background())

if !exists {
classObj := &models.Class{
Class: "Prompt",
Description: "Prompts generated by users",
Vectorizer: "none",
Properties: []*models.Property{
{
DataType: []string{"string"},
Description: "content of the prompt",
Name: "prompt",
},
},
}

err = client.Schema().ClassCreator().WithClass(classObj).Do(context.Background())
if err != nil {
panic(err)
}
fmt.Println("created class")
} else {
fmt.Println("class already exists")
}

}

0 comments on commit fbbe042

Please sign in to comment.