@@ -749,25 +749,9 @@ func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerless
749749 return nil , fmt .Errorf ("fields Name, Cloud, and Region must be included in CreateServerlessIndexRequest" )
750750 }
751751
752- // default to "dense" if VectorType is not specified
753- vectorType := in .VectorType
754-
755- // validate VectorType options
756- if in .VectorType != nil {
757- switch * in .VectorType {
758- case "sparse" :
759- if in .Dimension != nil {
760- return nil , fmt .Errorf ("Dimension should not be specified when VectorType is 'sparse'" )
761- } else if in .Metric != nil && * in .Metric != Dotproduct {
762- return nil , fmt .Errorf ("Metric should be 'dotproduct' when VectorType is 'sparse'" )
763- }
764- case "dense" :
765- if in .Dimension == nil {
766- return nil , fmt .Errorf ("Dimension should be specified when VectorType is 'dense'" )
767- }
768- default :
769- return nil , fmt .Errorf ("unsupported VectorType: %s" , * in .VectorType )
770- }
752+ vectorType , err := validateVectorType (in .VectorType , in .Dimension , in .Metric )
753+ if err != nil {
754+ return nil , err
771755 }
772756
773757 var deletionProtection * db_control.DeletionProtection
@@ -800,7 +784,7 @@ func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerless
800784 Dimension : in .Dimension ,
801785 Metric : (* string )(in .Metric ),
802786 DeletionProtection : deletionProtection ,
803- VectorType : vectorType ,
787+ VectorType : & vectorType ,
804788 Tags : tags ,
805789 }
806790
@@ -1030,6 +1014,8 @@ func (c *Client) CreateIndexForModel(ctx context.Context, in *CreateIndexForMode
10301014// - Environment: (Required) The environment identifier for the BYOC index.
10311015// - Metric: (Optional) The metric used to measure the [similarity] between vectors ('euclidean', 'cosine', or 'dotproduct').
10321016// - Dimension: (Optional) The [dimensionality] of the vectors to be inserted in the [Index].
1017+ // - VectorType: (Optional) The index vector type. You can use `dense` or `sparse`. If `dense`, the vector dimension must be specified.
1018+ // If `sparse`, the vector dimension should not be specified, and the Metric must be set to `dotproduct`. Defaults to `dense`.
10331019// - DeletionProtection: (Optional) Determines whether [deletion protection] is "enabled" or "disabled" for the index.
10341020// When "enabled", the index cannot be deleted. Defaults to "disabled".
10351021// - Tags: (Optional) A map of tags to associate with the Index.
@@ -1072,7 +1058,8 @@ func (c *Client) CreateIndexForModel(ctx context.Context, in *CreateIndexForMode
10721058type CreateBYOCIndexRequest struct {
10731059 Name string
10741060 Environment string
1075- Dimension int32
1061+ Dimension * int32
1062+ VectorType * string
10761063 Metric * IndexMetric
10771064 DeletionProtection * DeletionProtection
10781065 Tags * IndexTags
@@ -1138,16 +1125,22 @@ func (c *Client) CreateBYOCIndex(ctx context.Context, in *CreateBYOCIndexRequest
11381125 },
11391126 }
11401127
1128+ vectorType , err := validateVectorType (in .VectorType , in .Dimension , in .Metric )
1129+ if err != nil {
1130+ return nil , err
1131+ }
1132+
11411133 req := db_control.CreateIndexRequest {
11421134 Name : in .Name ,
1143- Dimension : & in .Dimension ,
1135+ VectorType : & vectorType ,
1136+ Dimension : in .Dimension ,
11441137 Metric : (* string )(in .Metric ),
11451138 DeletionProtection : (* db_control .DeletionProtection )(& deletionProtection ),
11461139 Tags : tags ,
11471140 }
11481141
11491142 // Apply BYOC spec to the request
1150- err : = req .Spec .FromIndexSpec2 (byocSpec )
1143+ err = req .Spec .FromIndexSpec2 (byocSpec )
11511144 if err != nil {
11521145 return nil , err
11531146 }
@@ -3003,6 +2996,30 @@ func mergeIndexTags(existingTags *IndexTags, newTags IndexTags) *IndexTags {
30032996 return & merged
30042997}
30052998
2999+ func validateVectorType (vectorType * string , dimension * int32 , metric * IndexMetric ) (string , error ) {
3000+ // Default to dense if vectorType is not specified
3001+ out := "dense"
3002+
3003+ if vectorType != nil {
3004+ switch * vectorType {
3005+ case "sparse" :
3006+ if dimension != nil {
3007+ return "" , fmt .Errorf ("Dimension should not be specified when VectorType is 'sparse'" )
3008+ } else if metric != nil && * metric != Dotproduct {
3009+ return "" , fmt .Errorf ("Metric should be 'dotproduct' when VectorType is 'sparse'" )
3010+ }
3011+ case "dense" :
3012+ if dimension == nil {
3013+ return "" , fmt .Errorf ("Dimension should be specified when VectorType is 'dense'" )
3014+ }
3015+ default :
3016+ return "" , fmt .Errorf ("unsupported VectorType: %s" , * vectorType )
3017+ }
3018+ out = * vectorType
3019+ }
3020+ return out , nil
3021+ }
3022+
30063023func ensureURLScheme (inputURL string ) (string , error ) {
30073024 parsedURL , err := url .Parse (inputURL )
30083025 if err != nil {
0 commit comments