Skip to content

Commit 1910d5f

Browse files
committed
Add VAMANA vector type to redisearch
1 parent 9c1655e commit 1910d5f

File tree

2 files changed

+700
-4
lines changed

2 files changed

+700
-4
lines changed

search_commands.go

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ type FieldSchema struct {
8080
}
8181

8282
type FTVectorArgs struct {
83-
FlatOptions *FTFlatOptions
84-
HNSWOptions *FTHNSWOptions
83+
FlatOptions *FTFlatOptions
84+
HNSWOptions *FTHNSWOptions
85+
VamanaOptions *FTVamanaOptions
8586
}
8687

8788
type FTFlatOptions struct {
@@ -103,6 +104,19 @@ type FTHNSWOptions struct {
103104
Epsilon float64
104105
}
105106

107+
type FTVamanaOptions struct {
108+
Type string
109+
Dim int
110+
DistanceMetric string
111+
Compression string
112+
ConstructionWindowSize int
113+
GraphMaxDegree int
114+
SearchWindowSize int
115+
Epsilon float64
116+
TrainingThreshold int
117+
ReduceDim int
118+
}
119+
106120
type FTDropIndexOptions struct {
107121
DeleteDocs bool
108122
}
@@ -985,8 +999,19 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
985999
if schema.FieldType != SearchFieldTypeVector {
9861000
panic("FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs")
9871001
}
988-
if schema.VectorArgs.FlatOptions != nil && schema.VectorArgs.HNSWOptions != nil {
989-
panic("FT.CREATE: SCHEMA VectorArgs FlatOptions and HNSWOptions are mutually exclusive")
1002+
// Check mutual exclusivity of vector options
1003+
optionCount := 0
1004+
if schema.VectorArgs.FlatOptions != nil {
1005+
optionCount++
1006+
}
1007+
if schema.VectorArgs.HNSWOptions != nil {
1008+
optionCount++
1009+
}
1010+
if schema.VectorArgs.VamanaOptions != nil {
1011+
optionCount++
1012+
}
1013+
if optionCount != 1 {
1014+
panic("FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOptions, HNSWOptions, or VamanaOptions")
9901015
}
9911016
if schema.VectorArgs.FlatOptions != nil {
9921017
args = append(args, "FLAT")
@@ -1035,6 +1060,40 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
10351060
args = append(args, len(hnswArgs))
10361061
args = append(args, hnswArgs...)
10371062
}
1063+
if schema.VectorArgs.VamanaOptions != nil {
1064+
args = append(args, "VAMANA")
1065+
if schema.VectorArgs.VamanaOptions.Type == "" || schema.VectorArgs.VamanaOptions.Dim == 0 || schema.VectorArgs.VamanaOptions.DistanceMetric == "" {
1066+
panic("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR VAMANA")
1067+
}
1068+
vamanaArgs := []interface{}{
1069+
"TYPE", schema.VectorArgs.VamanaOptions.Type,
1070+
"DIM", schema.VectorArgs.VamanaOptions.Dim,
1071+
"DISTANCE_METRIC", schema.VectorArgs.VamanaOptions.DistanceMetric,
1072+
}
1073+
if schema.VectorArgs.VamanaOptions.Compression != "" {
1074+
vamanaArgs = append(vamanaArgs, "COMPRESSION", schema.VectorArgs.VamanaOptions.Compression)
1075+
}
1076+
if schema.VectorArgs.VamanaOptions.ConstructionWindowSize > 0 {
1077+
vamanaArgs = append(vamanaArgs, "CONSTRUCTION_WINDOW_SIZE", schema.VectorArgs.VamanaOptions.ConstructionWindowSize)
1078+
}
1079+
if schema.VectorArgs.VamanaOptions.GraphMaxDegree > 0 {
1080+
vamanaArgs = append(vamanaArgs, "GRAPH_MAX_DEGREE", schema.VectorArgs.VamanaOptions.GraphMaxDegree)
1081+
}
1082+
if schema.VectorArgs.VamanaOptions.SearchWindowSize > 0 {
1083+
vamanaArgs = append(vamanaArgs, "SEARCH_WINDOW_SIZE", schema.VectorArgs.VamanaOptions.SearchWindowSize)
1084+
}
1085+
if schema.VectorArgs.VamanaOptions.Epsilon > 0 {
1086+
vamanaArgs = append(vamanaArgs, "EPSILON", schema.VectorArgs.VamanaOptions.Epsilon)
1087+
}
1088+
if schema.VectorArgs.VamanaOptions.TrainingThreshold > 0 {
1089+
vamanaArgs = append(vamanaArgs, "TRAINING_THRESHOLD", schema.VectorArgs.VamanaOptions.TrainingThreshold)
1090+
}
1091+
if schema.VectorArgs.VamanaOptions.ReduceDim > 0 {
1092+
vamanaArgs = append(vamanaArgs, "REDUCE", schema.VectorArgs.VamanaOptions.ReduceDim)
1093+
}
1094+
args = append(args, len(vamanaArgs))
1095+
args = append(args, vamanaArgs...)
1096+
}
10381097
}
10391098
if schema.GeoShapeFieldType != "" {
10401099
if schema.FieldType != SearchFieldTypeGeoShape {

0 commit comments

Comments
 (0)