github.com/weaviate/weaviate@v1.24.6/test/helper/sample-schema/books/books.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package books
    13  
    14  import (
    15  	"github.com/go-openapi/strfmt"
    16  	"github.com/weaviate/weaviate/entities/models"
    17  	"github.com/weaviate/weaviate/entities/schema"
    18  	pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1"
    19  	"google.golang.org/protobuf/types/known/structpb"
    20  )
    21  
    22  const defaultClassName = "Books"
    23  
    24  const (
    25  	Dune                  strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e000"
    26  	ProjectHailMary       strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e001"
    27  	TheLordOfTheIceGarden strfmt.UUID = "67b79643-cf8b-4b22-b206-6e63dbb4e002"
    28  )
    29  
    30  func ClassContextionaryVectorizer() *models.Class {
    31  	return class(defaultClassName, "text2vec-contextionary")
    32  }
    33  
    34  func ClassNamedContextionaryVectorizer() *models.Class {
    35  	vc := map[string]models.VectorConfig{
    36  		"all": {
    37  			Vectorizer: map[string]interface{}{
    38  				"text2vec-contextionary": map[string]interface{}{
    39  					"vectorizeClassName": false,
    40  				},
    41  			},
    42  			VectorIndexType: "hnsw",
    43  		},
    44  		"title": {
    45  			Vectorizer: map[string]interface{}{
    46  				"text2vec-contextionary": map[string]interface{}{
    47  					"vectorizeClassName": false,
    48  					"properties":         []string{"title"},
    49  				},
    50  			},
    51  			VectorIndexType: "hnsw",
    52  		},
    53  		"description": {
    54  			Vectorizer: map[string]interface{}{
    55  				"text2vec-contextionary": map[string]interface{}{
    56  					"vectorizeClassName": false,
    57  					"properties":         []string{"description"},
    58  				},
    59  			},
    60  			VectorIndexType: "hnsw",
    61  		},
    62  	}
    63  
    64  	return classNamedVectors(defaultClassName, vc)
    65  }
    66  
    67  func ClassContextionaryVectorizerWithName(className string) *models.Class {
    68  	return class(className, "text2vec-contextionary")
    69  }
    70  
    71  func ClassContextionaryVectorizerWithSumTransformers() *models.Class {
    72  	return class(defaultClassName, "text2vec-contextionary", "sum-transformers")
    73  }
    74  
    75  func ClassContextionaryVectorizerWithQnATransformers() *models.Class {
    76  	return class(defaultClassName, "text2vec-contextionary", "qna-transformers")
    77  }
    78  
    79  func ClassTransformersVectorizer() *models.Class {
    80  	return class(defaultClassName, "text2vec-transformers")
    81  }
    82  
    83  func ClassTransformersVectorizerWithName(className string) *models.Class {
    84  	return class(className, "text2vec-transformers")
    85  }
    86  
    87  func ClassTransformersVectorizerWithQnATransformersWithName(className string) *models.Class {
    88  	return class(className, "text2vec-transformers", "qna-transformers")
    89  }
    90  
    91  func ClassCLIPVectorizer() *models.Class {
    92  	c := class(defaultClassName, "multi2vec-clip")
    93  	c.ModuleConfig.(map[string]interface{})["multi2vec-clip"] = map[string]interface{}{
    94  		"textFields": []string{"title", "tags", "description"},
    95  	}
    96  	return c
    97  }
    98  
    99  func ClassBindVectorizer() *models.Class {
   100  	c := class(defaultClassName, "multi2vec-bind")
   101  	c.ModuleConfig.(map[string]interface{})["multi2vec-bind"] = map[string]interface{}{
   102  		"textFields": []string{"title", "tags", "description"},
   103  	}
   104  	return c
   105  }
   106  
   107  func classNamedVectors(className string, vectorConfig map[string]models.VectorConfig, additionalModules ...string) *models.Class {
   108  	return classBase(className, "", vectorConfig, additionalModules...)
   109  }
   110  
   111  func class(className, vectorizer string, additionalModules ...string) *models.Class {
   112  	return classBase(className, vectorizer, nil, additionalModules...)
   113  }
   114  
   115  func classBase(className, vectorizer string, vectorConfig map[string]models.VectorConfig, additionalModules ...string) *models.Class {
   116  	moduleConfig := map[string]interface{}{}
   117  	propModuleConfig := map[string]interface{}{}
   118  	if vectorizer != "" {
   119  		moduleConfig[vectorizer] = map[string]interface{}{
   120  			"vectorizeClassName": true,
   121  		}
   122  		propModuleConfig[vectorizer] = map[string]interface{}{"skip": false}
   123  	}
   124  	if len(additionalModules) > 0 {
   125  		for _, module := range additionalModules {
   126  			moduleConfig[module] = map[string]interface{}{}
   127  		}
   128  	}
   129  
   130  	return &models.Class{
   131  		Class:        className,
   132  		Vectorizer:   vectorizer,
   133  		ModuleConfig: moduleConfig,
   134  		InvertedIndexConfig: &models.InvertedIndexConfig{
   135  			IndexNullState:      true,
   136  			IndexTimestamps:     true,
   137  			IndexPropertyLength: true,
   138  		},
   139  		VectorConfig: vectorConfig,
   140  		Properties: []*models.Property{
   141  			{
   142  				Name:         "title",
   143  				DataType:     schema.DataTypeText.PropString(),
   144  				Tokenization: models.PropertyTokenizationWhitespace,
   145  				ModuleConfig: propModuleConfig,
   146  			},
   147  			{
   148  				Name:         "tags",
   149  				DataType:     schema.DataTypeTextArray.PropString(),
   150  				Tokenization: models.PropertyTokenizationWhitespace,
   151  				ModuleConfig: propModuleConfig,
   152  			},
   153  			{
   154  				Name:         "description",
   155  				DataType:     schema.DataTypeText.PropString(),
   156  				Tokenization: models.PropertyTokenizationWhitespace,
   157  				ModuleConfig: propModuleConfig,
   158  			},
   159  			{
   160  				Name: "meta", DataType: schema.DataTypeObject.PropString(),
   161  				NestedProperties: []*models.NestedProperty{
   162  					{Name: "isbn", DataType: schema.DataTypeText.PropString()},
   163  					{
   164  						Name: "obj", DataType: schema.DataTypeObject.PropString(),
   165  						NestedProperties: []*models.NestedProperty{{Name: "text", DataType: schema.DataTypeText.PropString()}},
   166  					},
   167  					{
   168  						Name: "objs", DataType: schema.DataTypeObjectArray.PropString(),
   169  						NestedProperties: []*models.NestedProperty{{Name: "text", DataType: schema.DataTypeText.PropString()}},
   170  					},
   171  				},
   172  			},
   173  			{
   174  				Name: "reviews", DataType: schema.DataTypeObjectArray.PropString(),
   175  				NestedProperties: []*models.NestedProperty{{Name: "tags", DataType: schema.DataTypeTextArray.PropString()}},
   176  			},
   177  		},
   178  	}
   179  }
   180  
   181  func Objects() []*models.Object {
   182  	return objects(defaultClassName)
   183  }
   184  
   185  func BatchObjects() []*pb.BatchObject {
   186  	return batchObjects(defaultClassName)
   187  }
   188  
   189  func ObjectsWithName(className string) []*models.Object {
   190  	return objects(className)
   191  }
   192  
   193  func objects(className string) []*models.Object {
   194  	return []*models.Object{
   195  		{
   196  			Class: className,
   197  			ID:    Dune,
   198  			Properties: map[string]interface{}{
   199  				"title":       "Dune",
   200  				"description": "Dune is a 1965 epic science fiction novel by American author Frank Herbert.",
   201  			},
   202  		},
   203  		{
   204  			Class: className,
   205  			ID:    ProjectHailMary,
   206  			Properties: map[string]interface{}{
   207  				"title":       "Project Hail Mary",
   208  				"description": "Project Hail Mary is a 2021 science fiction novel by American novelist Andy Weir.",
   209  			},
   210  		},
   211  		{
   212  			Class: className,
   213  			ID:    TheLordOfTheIceGarden,
   214  			Properties: map[string]interface{}{
   215  				"title":       "The Lord of the Ice Garden",
   216  				"tags":        []string{"three", "three", "three"},
   217  				"description": "The Lord of the Ice Garden (Polish: Pan Lodowego Ogrodu) is a four-volume science fiction and fantasy novel by Polish writer Jaroslaw Grzedowicz.",
   218  			},
   219  		},
   220  	}
   221  }
   222  
   223  func batchObjects(className string) []*pb.BatchObject {
   224  	scifi := "sci-fi"
   225  	return []*pb.BatchObject{
   226  		{
   227  			Collection: className,
   228  			Uuid:       Dune.String(),
   229  			Properties: &pb.BatchObject_Properties{
   230  				NonRefProperties: &structpb.Struct{
   231  					Fields: map[string]*structpb.Value{
   232  						"title":       structpb.NewStringValue("Dune"),
   233  						"description": structpb.NewStringValue("Dune is a 1965 epic science fiction novel by American author Frank Herbert."),
   234  					},
   235  				},
   236  				ObjectProperties: []*pb.ObjectProperties{{
   237  					PropName: "meta",
   238  					Value: &pb.ObjectPropertiesValue{
   239  						NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-0593099322")}},
   240  						ObjectProperties: []*pb.ObjectProperties{{
   241  							PropName: "obj",
   242  							Value: &pb.ObjectPropertiesValue{
   243  								NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
   244  							},
   245  						}},
   246  						ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   247  							PropName: "objs",
   248  							Values: []*pb.ObjectPropertiesValue{{
   249  								NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
   250  							}},
   251  						}},
   252  					},
   253  				}},
   254  				ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   255  					PropName: "reviews",
   256  					Values:   []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi, "epic"}}}}},
   257  				}},
   258  			},
   259  		},
   260  		{
   261  			Collection: className,
   262  			Uuid:       ProjectHailMary.String(),
   263  			Properties: &pb.BatchObject_Properties{
   264  				NonRefProperties: &structpb.Struct{
   265  					Fields: map[string]*structpb.Value{
   266  						"title":       structpb.NewStringValue("Project Hail Mary"),
   267  						"description": structpb.NewStringValue("Project Hail Mary is a 2021 science fiction novel by American novelist Andy Weir."),
   268  					},
   269  				},
   270  				ObjectProperties: []*pb.ObjectProperties{{
   271  					PropName: "meta",
   272  					Value: &pb.ObjectPropertiesValue{
   273  						NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-0593135204")}},
   274  						ObjectProperties: []*pb.ObjectProperties{{
   275  							PropName: "obj",
   276  							Value:    &pb.ObjectPropertiesValue{NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}}},
   277  						}},
   278  						ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   279  							PropName: "objs",
   280  							Values: []*pb.ObjectPropertiesValue{{
   281  								NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
   282  							}},
   283  						}},
   284  					},
   285  				}},
   286  				ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   287  					PropName: "reviews",
   288  					Values:   []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi}}}}},
   289  				}},
   290  			},
   291  		},
   292  		{
   293  			Collection: className,
   294  			Uuid:       TheLordOfTheIceGarden.String(),
   295  			Properties: &pb.BatchObject_Properties{
   296  				NonRefProperties: &structpb.Struct{
   297  					Fields: map[string]*structpb.Value{
   298  						"title":       structpb.NewStringValue("The Lord of the Ice Garden"),
   299  						"description": structpb.NewStringValue("The Lord of the Ice Garden (Polish: Pan Lodowego Ogrodu) is a four-volume science fiction and fantasy novel by Polish writer Jaroslaw Grzedowicz."),
   300  					},
   301  				},
   302  				ObjectProperties: []*pb.ObjectProperties{{
   303  					PropName: "meta",
   304  					Value: &pb.ObjectPropertiesValue{
   305  						NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"isbn": structpb.NewStringValue("978-8374812962")}},
   306  						ObjectProperties: []*pb.ObjectProperties{{
   307  							PropName: "obj",
   308  							Value:    &pb.ObjectPropertiesValue{NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}}},
   309  						}},
   310  						ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   311  							PropName: "objs",
   312  							Values: []*pb.ObjectPropertiesValue{{
   313  								NonRefProperties: &structpb.Struct{Fields: map[string]*structpb.Value{"text": structpb.NewStringValue("some text")}},
   314  							}},
   315  						}},
   316  					},
   317  				}},
   318  				ObjectArrayProperties: []*pb.ObjectArrayProperties{{
   319  					PropName: "reviews",
   320  					Values:   []*pb.ObjectPropertiesValue{{TextArrayProperties: []*pb.TextArrayProperties{{PropName: "tags", Values: []string{scifi, "fantasy"}}}}},
   321  				}},
   322  			},
   323  		},
   324  	}
   325  }