From 46ef44a74d0c82ce9ea756d9618940b2ad8f8bdd Mon Sep 17 00:00:00 2001 From: wayblink Date: Thu, 25 May 2023 12:18:55 +0800 Subject: [PATCH] Support scalar index field --- client/data.go | 4 +- client/index.go | 27 +- entity/genidx/genidx.go | 47 ++- entity/index.go | 19 +- entity/indexes_gen.go | 511 ++++++++++++++---------- entity/indexes_gen_test.go | 17 +- entity/indexes_search_param_gen.go | 21 +- entity/indexes_search_param_gen_test.go | 11 +- 8 files changed, 421 insertions(+), 236 deletions(-) diff --git a/client/data.go b/client/data.go index dac5c612..2193d7b8 100644 --- a/client/data.go +++ b/client/data.go @@ -372,10 +372,10 @@ func (c *GrpcClient) CalcDistance(ctx context.Context, collName string, partitio return nil, err } } - if err := c.checkCollField(ctx, collName, opLeft.Name()); err != nil { + if err := c.checkCollVecField(ctx, collName, opLeft.Name()); err != nil { return nil, err } - if err := c.checkCollField(ctx, collName, opRight.Name()); err != nil { + if err := c.checkCollVecField(ctx, collName, opRight.Name()); err != nil { return nil, err } diff --git a/client/index.go b/client/index.go index 9c8fd4c5..83215a4c 100644 --- a/client/index.go +++ b/client/index.go @@ -21,7 +21,7 @@ import ( "github.com/milvus-io/milvus-sdk-go/v2/entity" ) -func (c *GrpcClient) checkCollField(ctx context.Context, collName string, fieldName string) error { +func (c *GrpcClient) checkCollVecField(ctx context.Context, collName string, fieldName string) error { if err := c.checkCollectionExists(ctx, collName); err != nil { return err } @@ -45,6 +45,28 @@ func (c *GrpcClient) checkCollField(ctx context.Context, collName string, fieldN return nil } +// check if the collection and field exist +func (c *GrpcClient) checkCollField(ctx context.Context, collName string, fieldName string) error { + if err := c.checkCollectionExists(ctx, collName); err != nil { + return err + } + coll, err := c.DescribeCollection(ctx, collName) + if err != nil { + return err + } + var f *entity.Field + for _, field := range coll.Schema.Fields { + if field.Name == fieldName { + f = field + break + } + } + if f == nil { + return fmt.Errorf("field %s of collection %s does not exist", fieldName, collName) + } + return nil +} + type indexDef struct { name string fieldName string @@ -146,8 +168,9 @@ func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldNa params := entity.KvPairsMap(info.Params) it := params["index_type"] // TODO change to const idx := entity.NewGenericIndex( - info.IndexName, + info.GetIndexName(), entity.IndexType(it), + info.GetFieldName(), params, ) indexes = append(indexes, idx) diff --git a/entity/genidx/genidx.go b/entity/genidx/genidx.go index 95e81615..3a6548b2 100644 --- a/entity/genidx/genidx.go +++ b/entity/genidx/genidx.go @@ -56,6 +56,11 @@ func(i *Index{{.IdxName}}) IndexType() IndexType { return IndexType("{{.IdxType}}") } +// FieldName returns FieldName, implementing Index interface +func(i *Index{{.IdxName}}) FieldName() string { + return "{{.FieldName}}" +} + // SupportBinary returns whether index type support binary vector func(i *Index{{.IdxName}}) SupportBinary() bool { return {{.VectorSupport}} & 2 > 0 @@ -225,6 +230,7 @@ func TestIndex{{.IdxName}}SearchParam(t *testing.T) { type idxDef struct { IdxName string IdxType entity.IndexType + FieldName string VectorSupport int8 ConstructParams []idxParam SearchParams []idxParam @@ -333,6 +339,7 @@ func main() { { IdxName: "Flat", IdxType: entity.Flat, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{}, ValidExamples: []string{ @@ -348,6 +355,7 @@ func main() { { IdxName: "BinFlat", IdxType: entity.BinFlat, + FieldName: "vec_field", VectorSupport: int8(binaryVectorSupport), ConstructParams: []idxParam{ { @@ -378,8 +386,9 @@ func main() { }, // IVF_FLAT { - IdxName: "IvfFlat", - IdxType: entity.IvfFlat, + IdxName: "IvfFlat", + IdxType: entity.IvfFlat, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -411,6 +420,7 @@ func main() { { IdxName: "BinIvfFlat", IdxType: entity.BinIvfFlat, + FieldName: "vec_field", VectorSupport: int8(binaryVectorSupport), ConstructParams: []idxParam{ { @@ -441,8 +451,9 @@ func main() { }, // IVF_SQ8 { - IdxName: "IvfSQ8", - IdxType: entity.IvfSQ8, + IdxName: "IvfSQ8", + IdxType: entity.IvfSQ8, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -472,8 +483,9 @@ func main() { }, // IVF_PQ { - IdxName: "IvfPQ", - IdxType: entity.IvfPQ, + IdxName: "IvfPQ", + IdxType: entity.IvfPQ, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -513,8 +525,9 @@ func main() { }, // HNSW { - IdxName: "HNSW", - IdxType: entity.HNSW, + IdxName: "HNSW", + IdxType: entity.HNSW, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "M", @@ -550,8 +563,9 @@ func main() { }, // IVF_HNSW { - IdxName: "IvfHNSW", - IdxType: entity.IvfHNSW, + IdxName: "IvfHNSW", + IdxType: entity.IvfHNSW, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -599,8 +613,9 @@ func main() { }, // ANNOY { - IdxName: "ANNOY", - IdxType: entity.ANNOY, + IdxName: "ANNOY", + IdxType: entity.ANNOY, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "n_trees", @@ -628,6 +643,7 @@ func main() { { IdxName: "DISKANN", IdxType: entity.DISKANN, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{ { @@ -650,6 +666,7 @@ func main() { { IdxName: "AUTOINDEX", IdxType: entity.AUTOINDEX, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{ { @@ -670,6 +687,12 @@ func main() { "level = -1", }, }, + { + IdxName: "TRIE", + IdxType: entity.TRIE, + FieldName: "varchar_field", + ConstructParams: []idxParam{}, + }, }, } diff --git a/entity/index.go b/entity/index.go index f9da9a6f..3ac3b9c1 100644 --- a/entity/index.go +++ b/entity/index.go @@ -37,6 +37,7 @@ const ( ANNOY IndexType = "ANNOY" AUTOINDEX IndexType = "AUTOINDEX" DISKANN IndexType = "DISKANN" + TRIE IndexType = "TRIE" ) // Metric Constants @@ -61,6 +62,7 @@ type Index interface { Name() string IndexType() IndexType Params() map[string]string + FieldName() string } // SearchParam interface for index related search param @@ -70,8 +72,9 @@ type SearchParam interface { } type baseIndex struct { - it IndexType - name string + it IndexType + name string + fieldName string } // Name implements Index @@ -102,12 +105,18 @@ func (gi GenericIndex) Params() map[string]string { return m } +// FieldName implements Index +func (b baseIndex) FieldName() string { + return b.fieldName +} + // NewGenericIndex create generic index instance -func NewGenericIndex(name string, it IndexType, params map[string]string) Index { +func NewGenericIndex(name string, it IndexType, fieldName string, params map[string]string) Index { return GenericIndex{ baseIndex: baseIndex{ - it: it, - name: name, + it: it, + name: name, + fieldName: fieldName, }, params: params, } diff --git a/entity/indexes_gen.go b/entity/indexes_gen.go index 99279312..7d196a04 100755 --- a/entity/indexes_gen.go +++ b/entity/indexes_gen.go @@ -1,16 +1,14 @@ // Code generated by go generate; DO NOT EDIT -// This file is generated by go generate at 2022-11-23 18:16:28.725402023 +0800 CST m=+0.004536238 +// This file is generated by go generate at 2023-05-25 12:16:04.596245 +0800 CST m=+0.010820043 package entity import ( - "errors" "encoding/json" + "errors" "fmt" ) - - var _ Index = &IndexFlat{} // IndexFlat idx type for FLAT @@ -19,79 +17,88 @@ type IndexFlat struct { //auto generated fields } // Name returns index type name, implementing Index interface -func(i *IndexFlat) Name() string { +func (i *IndexFlat) Name() string { return "Flat" } // IndexType returns IndexType, implementing Index interface -func(i *IndexFlat) IndexType() IndexType { +func (i *IndexFlat) IndexType() IndexType { return IndexType("FLAT") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexFlat) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexFlat) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexFlat) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexFlat) Params() map[string]string { - params := map[string]string {//auto generated mapping +func (i *IndexFlat) Params() map[string]string { + params := map[string]string{ //auto generated mapping } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexFlat create index with construction parameters -func NewIndexFlat(metricType MetricType, ) (*IndexFlat, error) { +func NewIndexFlat(metricType MetricType) (*IndexFlat, error) { // auto generate parameters validation code, if any - return &IndexFlat{ - metricType: metricType, + return &IndexFlat{ + metricType: metricType, }, nil } - var _ Index = &IndexBinFlat{} // IndexBinFlat idx type for BIN_FLAT type IndexBinFlat struct { //auto generated fields - nlist int + nlist int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexBinFlat) Name() string { +func (i *IndexBinFlat) Name() string { return "BinFlat" } // IndexType returns IndexType, implementing Index interface -func(i *IndexBinFlat) IndexType() IndexType { +func (i *IndexBinFlat) IndexType() IndexType { return IndexType("BIN_FLAT") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexBinFlat) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexBinFlat) SupportBinary() bool { - return 2 & 2 > 0 +func (i *IndexBinFlat) SupportBinary() bool { + return 2&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexBinFlat) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), +func (i *IndexBinFlat) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexBinFlat create index with construction parameters -func NewIndexBinFlat(metricType MetricType, +func NewIndexBinFlat(metricType MetricType, nlist int, ) (*IndexBinFlat, error) { // auto generate parameters validation code, if any @@ -101,53 +108,57 @@ func NewIndexBinFlat(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - - return &IndexBinFlat{ - //auto generated setting - nlist: nlist, - metricType: metricType, + + return &IndexBinFlat{ + //auto generated setting + nlist: nlist, + metricType: metricType, }, nil } - var _ Index = &IndexIvfFlat{} // IndexIvfFlat idx type for IVF_FLAT type IndexIvfFlat struct { //auto generated fields - nlist int + nlist int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexIvfFlat) Name() string { +func (i *IndexIvfFlat) Name() string { return "IvfFlat" } // IndexType returns IndexType, implementing Index interface -func(i *IndexIvfFlat) IndexType() IndexType { +func (i *IndexIvfFlat) IndexType() IndexType { return IndexType("IVF_FLAT") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexIvfFlat) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexIvfFlat) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexIvfFlat) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexIvfFlat) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), +func (i *IndexIvfFlat) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexIvfFlat create index with construction parameters -func NewIndexIvfFlat(metricType MetricType, +func NewIndexIvfFlat(metricType MetricType, nlist int, ) (*IndexIvfFlat, error) { // auto generate parameters validation code, if any @@ -157,53 +168,57 @@ func NewIndexIvfFlat(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - - return &IndexIvfFlat{ - //auto generated setting - nlist: nlist, - metricType: metricType, + + return &IndexIvfFlat{ + //auto generated setting + nlist: nlist, + metricType: metricType, }, nil } - var _ Index = &IndexBinIvfFlat{} // IndexBinIvfFlat idx type for BIN_IVF_FLAT type IndexBinIvfFlat struct { //auto generated fields - nlist int + nlist int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexBinIvfFlat) Name() string { +func (i *IndexBinIvfFlat) Name() string { return "BinIvfFlat" } // IndexType returns IndexType, implementing Index interface -func(i *IndexBinIvfFlat) IndexType() IndexType { +func (i *IndexBinIvfFlat) IndexType() IndexType { return IndexType("BIN_IVF_FLAT") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexBinIvfFlat) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexBinIvfFlat) SupportBinary() bool { - return 2 & 2 > 0 +func (i *IndexBinIvfFlat) SupportBinary() bool { + return 2&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexBinIvfFlat) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), +func (i *IndexBinIvfFlat) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexBinIvfFlat create index with construction parameters -func NewIndexBinIvfFlat(metricType MetricType, +func NewIndexBinIvfFlat(metricType MetricType, nlist int, ) (*IndexBinIvfFlat, error) { // auto generate parameters validation code, if any @@ -213,53 +228,57 @@ func NewIndexBinIvfFlat(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - - return &IndexBinIvfFlat{ - //auto generated setting - nlist: nlist, - metricType: metricType, + + return &IndexBinIvfFlat{ + //auto generated setting + nlist: nlist, + metricType: metricType, }, nil } - var _ Index = &IndexIvfSQ8{} // IndexIvfSQ8 idx type for IVF_SQ8 type IndexIvfSQ8 struct { //auto generated fields - nlist int + nlist int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexIvfSQ8) Name() string { +func (i *IndexIvfSQ8) Name() string { return "IvfSQ8" } // IndexType returns IndexType, implementing Index interface -func(i *IndexIvfSQ8) IndexType() IndexType { +func (i *IndexIvfSQ8) IndexType() IndexType { return IndexType("IVF_SQ8") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexIvfSQ8) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexIvfSQ8) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexIvfSQ8) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexIvfSQ8) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), +func (i *IndexIvfSQ8) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexIvfSQ8 create index with construction parameters -func NewIndexIvfSQ8(metricType MetricType, +func NewIndexIvfSQ8(metricType MetricType, nlist int, ) (*IndexIvfSQ8, error) { // auto generate parameters validation code, if any @@ -269,57 +288,61 @@ func NewIndexIvfSQ8(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - - return &IndexIvfSQ8{ - //auto generated setting - nlist: nlist, - metricType: metricType, + + return &IndexIvfSQ8{ + //auto generated setting + nlist: nlist, + metricType: metricType, }, nil } - var _ Index = &IndexIvfPQ{} // IndexIvfPQ idx type for IVF_PQ type IndexIvfPQ struct { //auto generated fields - nlist int - m int - nbits int + nlist int + m int + nbits int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexIvfPQ) Name() string { +func (i *IndexIvfPQ) Name() string { return "IvfPQ" } // IndexType returns IndexType, implementing Index interface -func(i *IndexIvfPQ) IndexType() IndexType { +func (i *IndexIvfPQ) IndexType() IndexType { return IndexType("IVF_PQ") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexIvfPQ) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexIvfPQ) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexIvfPQ) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexIvfPQ) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), - "m": fmt.Sprintf("%v",i.m), - "nbits": fmt.Sprintf("%v",i.nbits), +func (i *IndexIvfPQ) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), + "m": fmt.Sprintf("%v", i.m), + "nbits": fmt.Sprintf("%v", i.nbits), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexIvfPQ create index with construction parameters -func NewIndexIvfPQ(metricType MetricType, +func NewIndexIvfPQ(metricType MetricType, nlist int, m int, @@ -333,68 +356,70 @@ func NewIndexIvfPQ(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - - - + if nbits < 1 { return nil, errors.New("nbits not valid") } if nbits > 16 { return nil, errors.New("nbits not valid") } - - return &IndexIvfPQ{ - //auto generated setting - nlist: nlist, - //auto generated setting - m: m, - //auto generated setting - nbits: nbits, - metricType: metricType, + + return &IndexIvfPQ{ + //auto generated setting + nlist: nlist, + //auto generated setting + m: m, + //auto generated setting + nbits: nbits, + metricType: metricType, }, nil } - var _ Index = &IndexHNSW{} // IndexHNSW idx type for HNSW type IndexHNSW struct { //auto generated fields - M int + M int efConstruction int - metricType MetricType + metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexHNSW) Name() string { +func (i *IndexHNSW) Name() string { return "HNSW" } // IndexType returns IndexType, implementing Index interface -func(i *IndexHNSW) IndexType() IndexType { +func (i *IndexHNSW) IndexType() IndexType { return IndexType("HNSW") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexHNSW) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexHNSW) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexHNSW) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexHNSW) Params() map[string]string { - params := map[string]string {//auto generated mapping - "M": fmt.Sprintf("%v",i.M), - "efConstruction": fmt.Sprintf("%v",i.efConstruction), +func (i *IndexHNSW) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "M": fmt.Sprintf("%v", i.M), + "efConstruction": fmt.Sprintf("%v", i.efConstruction), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexHNSW create index with construction parameters -func NewIndexHNSW(metricType MetricType, +func NewIndexHNSW(metricType MetricType, M int, efConstruction int, @@ -406,66 +431,70 @@ func NewIndexHNSW(metricType MetricType, if M > 64 { return nil, errors.New("M not valid") } - + if efConstruction < 8 { return nil, errors.New("efConstruction not valid") } if efConstruction > 512 { return nil, errors.New("efConstruction not valid") } - - return &IndexHNSW{ - //auto generated setting - M: M, - //auto generated setting - efConstruction: efConstruction, - metricType: metricType, + + return &IndexHNSW{ + //auto generated setting + M: M, + //auto generated setting + efConstruction: efConstruction, + metricType: metricType, }, nil } - var _ Index = &IndexIvfHNSW{} // IndexIvfHNSW idx type for IVF_HNSW type IndexIvfHNSW struct { //auto generated fields - nlist int - M int + nlist int + M int efConstruction int - metricType MetricType + metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexIvfHNSW) Name() string { +func (i *IndexIvfHNSW) Name() string { return "IvfHNSW" } // IndexType returns IndexType, implementing Index interface -func(i *IndexIvfHNSW) IndexType() IndexType { +func (i *IndexIvfHNSW) IndexType() IndexType { return IndexType("IVF_HNSW") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexIvfHNSW) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexIvfHNSW) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexIvfHNSW) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexIvfHNSW) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), - "M": fmt.Sprintf("%v",i.M), - "efConstruction": fmt.Sprintf("%v",i.efConstruction), +func (i *IndexIvfHNSW) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), + "M": fmt.Sprintf("%v", i.M), + "efConstruction": fmt.Sprintf("%v", i.efConstruction), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexIvfHNSW create index with construction parameters -func NewIndexIvfHNSW(metricType MetricType, +func NewIndexIvfHNSW(metricType MetricType, nlist int, M int, @@ -479,71 +508,75 @@ func NewIndexIvfHNSW(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist not valid") } - + if M < 4 { return nil, errors.New("M not valid") } if M > 64 { return nil, errors.New("M not valid") } - + if efConstruction < 8 { return nil, errors.New("efConstruction not valid") } if efConstruction > 512 { return nil, errors.New("efConstruction not valid") } - - return &IndexIvfHNSW{ - //auto generated setting - nlist: nlist, - //auto generated setting - M: M, - //auto generated setting - efConstruction: efConstruction, - metricType: metricType, + + return &IndexIvfHNSW{ + //auto generated setting + nlist: nlist, + //auto generated setting + M: M, + //auto generated setting + efConstruction: efConstruction, + metricType: metricType, }, nil } - var _ Index = &IndexANNOY{} // IndexANNOY idx type for ANNOY type IndexANNOY struct { //auto generated fields - n_trees int + n_trees int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexANNOY) Name() string { +func (i *IndexANNOY) Name() string { return "ANNOY" } // IndexType returns IndexType, implementing Index interface -func(i *IndexANNOY) IndexType() IndexType { +func (i *IndexANNOY) IndexType() IndexType { return IndexType("ANNOY") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexANNOY) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexANNOY) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexANNOY) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexANNOY) Params() map[string]string { - params := map[string]string {//auto generated mapping - "n_trees": fmt.Sprintf("%v",i.n_trees), +func (i *IndexANNOY) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "n_trees": fmt.Sprintf("%v", i.n_trees), } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexANNOY create index with construction parameters -func NewIndexANNOY(metricType MetricType, +func NewIndexANNOY(metricType MetricType, n_trees int, ) (*IndexANNOY, error) { // auto generate parameters validation code, if any @@ -553,15 +586,14 @@ func NewIndexANNOY(metricType MetricType, if n_trees > 1024 { return nil, errors.New("n_trees not valid") } - - return &IndexANNOY{ - //auto generated setting - n_trees: n_trees, - metricType: metricType, + + return &IndexANNOY{ + //auto generated setting + n_trees: n_trees, + metricType: metricType, }, nil } - var _ Index = &IndexDISKANN{} // IndexDISKANN idx type for DISKANN @@ -570,41 +602,45 @@ type IndexDISKANN struct { //auto generated fields } // Name returns index type name, implementing Index interface -func(i *IndexDISKANN) Name() string { +func (i *IndexDISKANN) Name() string { return "DISKANN" } // IndexType returns IndexType, implementing Index interface -func(i *IndexDISKANN) IndexType() IndexType { +func (i *IndexDISKANN) IndexType() IndexType { return IndexType("DISKANN") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexDISKANN) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexDISKANN) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexDISKANN) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexDISKANN) Params() map[string]string { - params := map[string]string {//auto generated mapping +func (i *IndexDISKANN) Params() map[string]string { + params := map[string]string{ //auto generated mapping } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexDISKANN create index with construction parameters -func NewIndexDISKANN(metricType MetricType, ) (*IndexDISKANN, error) { +func NewIndexDISKANN(metricType MetricType) (*IndexDISKANN, error) { // auto generate parameters validation code, if any - return &IndexDISKANN{ - metricType: metricType, + return &IndexDISKANN{ + metricType: metricType, }, nil } - var _ Index = &IndexAUTOINDEX{} // IndexAUTOINDEX idx type for AUTOINDEX @@ -613,37 +649,88 @@ type IndexAUTOINDEX struct { //auto generated fields } // Name returns index type name, implementing Index interface -func(i *IndexAUTOINDEX) Name() string { +func (i *IndexAUTOINDEX) Name() string { return "AUTOINDEX" } // IndexType returns IndexType, implementing Index interface -func(i *IndexAUTOINDEX) IndexType() IndexType { +func (i *IndexAUTOINDEX) IndexType() IndexType { return IndexType("AUTOINDEX") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexAUTOINDEX) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexAUTOINDEX) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexAUTOINDEX) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexAUTOINDEX) Params() map[string]string { - params := map[string]string {//auto generated mapping +func (i *IndexAUTOINDEX) Params() map[string]string { + params := map[string]string{ //auto generated mapping } bs, _ := json.Marshal(params) - return map[string]string { - "params": string(bs), - "index_type": string(i.IndexType()), + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), "metric_type": string(i.metricType), } } // NewIndexAUTOINDEX create index with construction parameters -func NewIndexAUTOINDEX(metricType MetricType, ) (*IndexAUTOINDEX, error) { +func NewIndexAUTOINDEX(metricType MetricType) (*IndexAUTOINDEX, error) { // auto generate parameters validation code, if any - return &IndexAUTOINDEX{ - metricType: metricType, + return &IndexAUTOINDEX{ + metricType: metricType, }, nil } +var _ Index = &IndexTRIE{} + +// IndexTRIE idx type for TRIE +type IndexTRIE struct { //auto generated fields + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func (i *IndexTRIE) Name() string { + return "TRIE" +} + +// IndexType returns IndexType, implementing Index interface +func (i *IndexTRIE) IndexType() IndexType { + return IndexType("TRIE") +} + +// FieldName returns FieldName, implementing Index interface +func (i *IndexTRIE) FieldName() string { + return "varchar_field" +} + +// SupportBinary returns whether index type support binary vector +func (i *IndexTRIE) SupportBinary() bool { + return 0&2 > 0 +} + +// Params returns index construction params, implementing Index interface +func (i *IndexTRIE) Params() map[string]string { + params := map[string]string{ //auto generated mapping + } + bs, _ := json.Marshal(params) + return map[string]string{ + "params": string(bs), + "index_type": string(i.IndexType()), + "metric_type": string(i.metricType), + } +} + +// NewIndexTRIE create index with construction parameters +func NewIndexTRIE(metricType MetricType) (*IndexTRIE, error) { + // auto generate parameters validation code, if any + return &IndexTRIE{ + metricType: metricType, + }, nil +} diff --git a/entity/indexes_gen_test.go b/entity/indexes_gen_test.go index 01a6dd38..514c07f3 100755 --- a/entity/indexes_gen_test.go +++ b/entity/indexes_gen_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT -// This file is generated by go generate at 2022-11-23 18:16:28.725402023 +0800 CST m=+0.004536238 +// This file is generated by go generate at 2023-05-25 12:16:04.596245 +0800 CST m=+0.010820043 package entity @@ -503,3 +503,18 @@ func TestIndexAUTOINDEX(t *testing.T){ }) } +func TestIndexTRIE(t *testing.T){ + + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + }) +} + diff --git a/entity/indexes_search_param_gen.go b/entity/indexes_search_param_gen.go index abe34178..8816cda5 100755 --- a/entity/indexes_search_param_gen.go +++ b/entity/indexes_search_param_gen.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT -// This file is generated by go generate at 2022-11-23 18:16:28.725402023 +0800 CST m=+0.004536238 +// This file is generated by go generate at 2023-05-25 12:16:04.596245 +0800 CST m=+0.010820043 package entity @@ -355,3 +355,22 @@ func NewIndexAUTOINDEXSearchParam( }, nil } +var _ SearchParam = &IndexTRIESearchParam{} + +// IndexTRIESearchParam search param struct for index type TRIE +type IndexTRIESearchParam struct { //auto generated fields +} + +// Params returns index construction params, implementing Index interface +func(i *IndexTRIESearchParam) Params() map[string]interface{} { + return map[string]interface{} {//auto generated mapping + } +} + +// NewIndexTRIESearchParam create index search param +func NewIndexTRIESearchParam() (*IndexTRIESearchParam, error) { + // auto generate parameters validation code, if any + return &IndexTRIESearchParam{ + }, nil +} + diff --git a/entity/indexes_search_param_gen_test.go b/entity/indexes_search_param_gen_test.go index dacb0cc6..911519be 100755 --- a/entity/indexes_search_param_gen_test.go +++ b/entity/indexes_search_param_gen_test.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT -// This file is generated by go generate at 2022-11-23 18:16:28.725402023 +0800 CST m=+0.004536238 +// This file is generated by go generate at 2023-05-25 12:16:04.596245 +0800 CST m=+0.010820043 package entity @@ -403,3 +403,12 @@ func TestIndexAUTOINDEXSearchParam(t *testing.T) { } +func TestIndexTRIESearchParam(t *testing.T) { + + + t.Run("valid usage case", func(t *testing.T){ + + }) + +} +