Skip to content

Commit

Permalink
added validation
Browse files Browse the repository at this point in the history
  • Loading branch information
metonymic-smokey committed Jan 9, 2024
1 parent facfcf9 commit 5bd23bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mapping/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type FieldMapping struct {
// See: index.DefaultSimilarityMetric & index.SupportedSimilarityMetrics
Similarity string `json:"similarity,omitempty"`

VectorIndexType string `json:"vectorIndexType,omitempty"`
VectorIndexType string `json:"vector_index_type,omitempty"`
}

// NewTextFieldMapping returns a default field mapping for text
Expand Down Expand Up @@ -468,7 +468,11 @@ func (fm *FieldMapping) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
// add condition here too!
case "vector_index_type":
err := json.Unmarshal(v, &fm.VectorIndexType)
if err != nil {
return err
}
default:
invalidKeys = append(invalidKeys, k)
}
Expand Down
10 changes: 10 additions & 0 deletions mapping/mapping_vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func validateVectorFieldAlias(field *FieldMapping, parentName string,
field.Similarity = index.DefaultSimilarityMetric
}

if field.VectorIndexType == "" {
field.VectorIndexType = index.DefaultIndexType
}

// following fields are not applicable for vector
// thus, we set them to default values
field.IncludeInAll = false
Expand Down Expand Up @@ -202,6 +206,12 @@ func validateVectorFieldAlias(field *FieldMapping, parentName string,
reflect.ValueOf(index.SupportedSimilarityMetrics).MapKeys())
}

if _, ok := index.SupportedIndexTunables[field.VectorIndexType]; !ok {
return fmt.Errorf("field: '%s', invalid index optimisation "+
"tunable: '%s', valid values are: %+v", field.Name, field.VectorIndexType,
reflect.ValueOf(index.SupportedIndexTunables).MapKeys())
}

if fieldAliasCtx != nil { // writing to a nil map is unsafe
fieldAliasCtx[field.Name] = field
}
Expand Down

0 comments on commit 5bd23bc

Please sign in to comment.