From 8f26de912f049ee0145720fa7f728d195933a4c7 Mon Sep 17 00:00:00 2001 From: wayblink Date: Wed, 1 Nov 2023 17:26:21 +0800 Subject: [PATCH] Add fieldName in index Signed-off-by: wayblink --- client/collection.go | 2 +- client/index.go | 3 +- entity/genidx/genidx.go | 54 +- entity/index.go | 18 +- entity/index_test.go | 2 +- entity/indexes_gen.go | 576 ++++++++-------- entity/indexes_gen_test.go | 350 +++++----- entity/indexes_search_param_gen.go | 87 ++- entity/indexes_search_param_gen_test.go | 263 ++++--- indexes_gen.go | 865 ++++++++++++++++++++++++ indexes_gen_test.go | 629 +++++++++++++++++ indexes_search_param_gen.go | 424 ++++++++++++ indexes_search_param_gen_test.go | 499 ++++++++++++++ test/testcases/highlevel_test.go | 4 +- test/testcases/index_test.go | 20 +- 15 files changed, 3126 insertions(+), 670 deletions(-) create mode 100755 indexes_gen.go create mode 100755 indexes_gen_test.go create mode 100755 indexes_search_param_gen.go create mode 100755 indexes_search_param_gen_test.go diff --git a/client/collection.go b/client/collection.go index f954f32d..2b496024 100644 --- a/client/collection.go +++ b/client/collection.go @@ -112,7 +112,7 @@ func (c *GrpcClient) NewCollection(ctx context.Context, collName string, dimensi return err } - idx := entity.NewGenericIndex("", "", map[string]string{ + idx := entity.NewGenericIndex("", "", "", map[string]string{ "metric_type": string(opt.MetricsType), }) diff --git a/client/index.go b/client/index.go index 6b717136..9ba48937 100644 --- a/client/index.go +++ b/client/index.go @@ -149,8 +149,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 b99dad7d..94acae18 100644 --- a/entity/genidx/genidx.go +++ b/entity/genidx/genidx.go @@ -1,6 +1,3 @@ -//go:build ignore -// +build ignore - // Copyright (C) 2019-2021 Zilliz. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance @@ -55,6 +52,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 @@ -223,6 +225,7 @@ func TestIndex{{.IdxName}}SearchParam(t *testing.T) { type idxDef struct { IdxName string IdxType entity.IndexType + FieldName string VectorSupport int8 ConstructParams []idxParam SearchParams []idxParam @@ -329,6 +332,7 @@ func main() { { IdxName: "Flat", IdxType: entity.Flat, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{}, ValidExamples: []string{ @@ -344,6 +348,7 @@ func main() { { IdxName: "BinFlat", IdxType: entity.BinFlat, + FieldName: "vec_field", VectorSupport: int8(binaryVectorSupport), ConstructParams: []idxParam{ { @@ -374,8 +379,9 @@ func main() { }, // IVF_FLAT { - IdxName: "IvfFlat", - IdxType: entity.IvfFlat, + IdxName: "IvfFlat", + IdxType: entity.IvfFlat, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -407,6 +413,7 @@ func main() { { IdxName: "BinIvfFlat", IdxType: entity.BinIvfFlat, + FieldName: "vec_field", VectorSupport: int8(binaryVectorSupport), ConstructParams: []idxParam{ { @@ -437,8 +444,9 @@ func main() { }, // IVF_SQ8 { - IdxName: "IvfSQ8", - IdxType: entity.IvfSQ8, + IdxName: "IvfSQ8", + IdxType: entity.IvfSQ8, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -468,8 +476,9 @@ func main() { }, // IVF_PQ { - IdxName: "IvfPQ", - IdxType: entity.IvfPQ, + IdxName: "IvfPQ", + IdxType: entity.IvfPQ, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -509,8 +518,9 @@ func main() { }, // HNSW { - IdxName: "HNSW", - IdxType: entity.HNSW, + IdxName: "HNSW", + IdxType: entity.HNSW, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "M", @@ -546,8 +556,9 @@ func main() { }, // IVF_HNSW { - IdxName: "IvfHNSW", - IdxType: entity.IvfHNSW, + IdxName: "IvfHNSW", + IdxType: entity.IvfHNSW, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -596,6 +607,7 @@ func main() { { IdxName: "DISKANN", IdxType: entity.DISKANN, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{ { @@ -618,6 +630,7 @@ func main() { { IdxName: "AUTOINDEX", IdxType: entity.AUTOINDEX, + FieldName: "vec_field", ConstructParams: []idxParam{}, SearchParams: []idxParam{ { @@ -639,8 +652,9 @@ func main() { }, }, { - IdxName: "GPUIvfFlat", - IdxType: entity.GPUIvfFlat, + IdxName: "GPUIvfFlat", + IdxType: entity.GPUIvfFlat, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -669,8 +683,9 @@ func main() { }, }, { - IdxName: "GPUIvfPQ", - IdxType: entity.GPUIvfPQ, + IdxName: "GPUIvfPQ", + IdxType: entity.GPUIvfPQ, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", @@ -709,8 +724,9 @@ func main() { }, }, { - IdxName: "SCANN", - IdxType: entity.SCANN, + IdxName: "SCANN", + IdxType: entity.IvfFlat, + FieldName: "vec_field", ConstructParams: []idxParam{ { Name: "nlist", diff --git a/entity/index.go b/entity/index.go index 570aa075..17a23cf2 100644 --- a/entity/index.go +++ b/entity/index.go @@ -67,6 +67,7 @@ type Index interface { Name() string IndexType() IndexType Params() map[string]string + FieldName() string } // SearchParam interface for index related search param @@ -104,8 +105,9 @@ func newBaseSearchParams() baseSearchParams { } type baseIndex struct { - it IndexType - name string + it IndexType + name string + fieldName string } // Name implements Index @@ -118,6 +120,11 @@ func (b baseIndex) IndexType() IndexType { return b.it } +// FieldName implements Index +func (b baseIndex) FieldName() string { + return b.fieldName +} + // GenericIndex index struct for general usage // no constraint for index is applied type GenericIndex struct { @@ -138,11 +145,12 @@ func (gi GenericIndex) Params() map[string]string { } // 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/index_test.go b/entity/index_test.go index ba1c7766..3bcf0178 100644 --- a/entity/index_test.go +++ b/entity/index_test.go @@ -23,7 +23,7 @@ import ( func TestGenericIndex(t *testing.T) { rand.Seed(time.Now().UnixNano()) name := fmt.Sprintf("generic_index_%d", rand.Int()) - gi := NewGenericIndex(name, IvfFlat, map[string]string{ + gi := NewGenericIndex(name, IvfFlat, "field", map[string]string{ tMetricType: string(IP), }) assert.Equal(t, name, gi.Name()) diff --git a/entity/indexes_gen.go b/entity/indexes_gen.go index e4b84fe5..62d79629 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 +// This file is generated by go generate 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 has to be in range [1, 65536]") } - - 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 has to be in range [1, 65536]") } - - 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 has to be in range [1, 65536]") } - - 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 has to be in range [1, 65536]") } - - 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 has to be in range [1, 65536]") } - - - + if nbits < 1 { return nil, errors.New("nbits has to be in range [1, 16]") } if nbits > 16 { return nil, errors.New("nbits has to be in range [1, 16]") } - - 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 has to be in range [4, 64]") } - + if efConstruction < 8 { return nil, errors.New("efConstruction has to be in range [8, 512]") } if efConstruction > 512 { return nil, errors.New("efConstruction has to be in range [8, 512]") } - - 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,33 +508,32 @@ func NewIndexIvfHNSW(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist has to be in range [1, 65536]") } - + if M < 4 { return nil, errors.New("M has to be in range [4, 64]") } if M > 64 { return nil, errors.New("M has to be in range [4, 64]") } - + if efConstruction < 8 { return nil, errors.New("efConstruction has to be in range [8, 512]") } if efConstruction > 512 { return nil, errors.New("efConstruction has to be in range [8, 512]") } - - 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 = &IndexDISKANN{} // IndexDISKANN idx type for DISKANN @@ -514,41 +542,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 @@ -557,79 +589,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 = &IndexGPUIvfFlat{} // IndexGPUIvfFlat idx type for GPU_IVF_FLAT type IndexGPUIvfFlat struct { //auto generated fields - nlist int + nlist int metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexGPUIvfFlat) Name() string { +func (i *IndexGPUIvfFlat) Name() string { return "GPUIvfFlat" } // IndexType returns IndexType, implementing Index interface -func(i *IndexGPUIvfFlat) IndexType() IndexType { +func (i *IndexGPUIvfFlat) IndexType() IndexType { return IndexType("GPU_IVF_FLAT") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexGPUIvfFlat) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexGPUIvfFlat) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexGPUIvfFlat) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexGPUIvfFlat) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), +func (i *IndexGPUIvfFlat) 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), } } // NewIndexGPUIvfFlat create index with construction parameters -func NewIndexGPUIvfFlat(metricType MetricType, +func NewIndexGPUIvfFlat(metricType MetricType, nlist int, ) (*IndexGPUIvfFlat, error) { // auto generate parameters validation code, if any @@ -639,57 +680,61 @@ func NewIndexGPUIvfFlat(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist has to be in range [1, 65536]") } - - return &IndexGPUIvfFlat{ - //auto generated setting - nlist: nlist, - metricType: metricType, + + return &IndexGPUIvfFlat{ + //auto generated setting + nlist: nlist, + metricType: metricType, }, nil } - var _ Index = &IndexGPUIvfPQ{} // IndexGPUIvfPQ idx type for GPU_IVF_PQ type IndexGPUIvfPQ 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 *IndexGPUIvfPQ) Name() string { +func (i *IndexGPUIvfPQ) Name() string { return "GPUIvfPQ" } // IndexType returns IndexType, implementing Index interface -func(i *IndexGPUIvfPQ) IndexType() IndexType { +func (i *IndexGPUIvfPQ) IndexType() IndexType { return IndexType("GPU_IVF_PQ") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexGPUIvfPQ) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexGPUIvfPQ) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexGPUIvfPQ) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexGPUIvfPQ) 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 *IndexGPUIvfPQ) 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), } } // NewIndexGPUIvfPQ create index with construction parameters -func NewIndexGPUIvfPQ(metricType MetricType, +func NewIndexGPUIvfPQ(metricType MetricType, nlist int, m int, @@ -703,68 +748,70 @@ func NewIndexGPUIvfPQ(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist has to be in range [1, 65536]") } - - - + if nbits < 1 { return nil, errors.New("nbits has to be in range [1, 64]") } if nbits > 64 { return nil, errors.New("nbits has to be in range [1, 64]") } - - return &IndexGPUIvfPQ{ - //auto generated setting - nlist: nlist, - //auto generated setting - m: m, - //auto generated setting - nbits: nbits, - metricType: metricType, + + return &IndexGPUIvfPQ{ + //auto generated setting + nlist: nlist, + //auto generated setting + m: m, + //auto generated setting + nbits: nbits, + metricType: metricType, }, nil } - var _ Index = &IndexSCANN{} // IndexSCANN idx type for SCANN type IndexSCANN struct { //auto generated fields - nlist int + nlist int with_raw_data bool - metricType MetricType + metricType MetricType } // Name returns index type name, implementing Index interface -func(i *IndexSCANN) Name() string { +func (i *IndexSCANN) Name() string { return "SCANN" } // IndexType returns IndexType, implementing Index interface -func(i *IndexSCANN) IndexType() IndexType { +func (i *IndexSCANN) IndexType() IndexType { return IndexType("SCANN") } +// FieldName returns FieldName, implementing Index interface +func (i *IndexSCANN) FieldName() string { + return "vec_field" +} + // SupportBinary returns whether index type support binary vector -func(i *IndexSCANN) SupportBinary() bool { - return 0 & 2 > 0 +func (i *IndexSCANN) SupportBinary() bool { + return 0&2 > 0 } // Params returns index construction params, implementing Index interface -func(i *IndexSCANN) Params() map[string]string { - params := map[string]string {//auto generated mapping - "nlist": fmt.Sprintf("%v",i.nlist), - "with_raw_data": fmt.Sprintf("%v",i.with_raw_data), +func (i *IndexSCANN) Params() map[string]string { + params := map[string]string{ //auto generated mapping + "nlist": fmt.Sprintf("%v", i.nlist), + "with_raw_data": fmt.Sprintf("%v", i.with_raw_data), } 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), } } // NewIndexSCANN create index with construction parameters -func NewIndexSCANN(metricType MetricType, +func NewIndexSCANN(metricType MetricType, nlist int, with_raw_data bool, @@ -776,7 +823,7 @@ func NewIndexSCANN(metricType MetricType, if nlist > 65536 { return nil, errors.New("nlist has to be in range [1, 65536]") } - + validRange := []bool{false, true} with_raw_dataOk := false for _, v := range validRange { @@ -788,13 +835,12 @@ func NewIndexSCANN(metricType MetricType, if !with_raw_dataOk { return nil, errors.New("with_raw_data not valid") } - - return &IndexSCANN{ - //auto generated setting - nlist: nlist, - //auto generated setting - with_raw_data: with_raw_data, - metricType: metricType, + + return &IndexSCANN{ + //auto generated setting + nlist: nlist, + //auto generated setting + with_raw_data: with_raw_data, + metricType: metricType, }, nil } - diff --git a/entity/indexes_gen_test.go b/entity/indexes_gen_test.go index e7fce9fc..a052bc1f 100755 --- a/entity/indexes_gen_test.go +++ b/entity/indexes_gen_test.go @@ -9,43 +9,37 @@ import ( "github.com/stretchr/testify/assert" ) - -func TestIndexFlat(t *testing.T){ - +func TestIndexFlat(t *testing.T) { mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - - - idx0, err := NewIndexFlat(mt, - ) + t.Run("valid usage case", func(t *testing.T) { + + idx0, err := NewIndexFlat(mt) assert.Nil(t, err) assert.NotNil(t, idx0) assert.Equal(t, "Flat", idx0.Name()) assert.EqualValues(t, "FLAT", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + }) } -func TestIndexBinFlat(t *testing.T){ - +func TestIndexBinFlat(t *testing.T) { + var nlist int mt := HAMMING - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 10 - idx0, err := NewIndexBinFlat(mt, + idx0, err := NewIndexBinFlat(mt, nlist, ) assert.Nil(t, err) @@ -54,39 +48,38 @@ func TestIndexBinFlat(t *testing.T){ assert.EqualValues(t, "BIN_FLAT", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.True(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexBinFlat(mt, + idx0, err := NewIndexBinFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexBinFlat(mt, + idx1, err := NewIndexBinFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } -func TestIndexIvfFlat(t *testing.T){ - +func TestIndexIvfFlat(t *testing.T) { + var nlist int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 10 - idx0, err := NewIndexIvfFlat(mt, + idx0, err := NewIndexIvfFlat(mt, nlist, ) assert.Nil(t, err) @@ -95,39 +88,38 @@ func TestIndexIvfFlat(t *testing.T){ assert.EqualValues(t, "IVF_FLAT", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexIvfFlat(mt, + idx0, err := NewIndexIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexIvfFlat(mt, + idx1, err := NewIndexIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } -func TestIndexBinIvfFlat(t *testing.T){ - +func TestIndexBinIvfFlat(t *testing.T) { + var nlist int mt := HAMMING - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 10 - idx0, err := NewIndexBinIvfFlat(mt, + idx0, err := NewIndexBinIvfFlat(mt, nlist, ) assert.Nil(t, err) @@ -136,39 +128,38 @@ func TestIndexBinIvfFlat(t *testing.T){ assert.EqualValues(t, "BIN_IVF_FLAT", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.True(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexBinIvfFlat(mt, + idx0, err := NewIndexBinIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexBinIvfFlat(mt, + idx1, err := NewIndexBinIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } -func TestIndexIvfSQ8(t *testing.T){ - +func TestIndexIvfSQ8(t *testing.T) { + var nlist int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 10 - idx0, err := NewIndexIvfSQ8(mt, + idx0, err := NewIndexIvfSQ8(mt, nlist, ) assert.Nil(t, err) @@ -177,41 +168,40 @@ func TestIndexIvfSQ8(t *testing.T){ assert.EqualValues(t, "IVF_SQ8", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexIvfSQ8(mt, + idx0, err := NewIndexIvfSQ8(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexIvfSQ8(mt, + idx1, err := NewIndexIvfSQ8(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } -func TestIndexIvfPQ(t *testing.T){ - +func TestIndexIvfPQ(t *testing.T) { + var nlist int var m int var nbits int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist, m, nbits = 10, 8, 8 - idx0, err := NewIndexIvfPQ(mt, + idx0, err := NewIndexIvfPQ(mt, nlist, m, nbits, @@ -222,62 +212,61 @@ func TestIndexIvfPQ(t *testing.T){ assert.EqualValues(t, "IVF_PQ", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist, m, nbits = 0, 8, 8 - idx0, err := NewIndexIvfPQ(mt, + idx0, err := NewIndexIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist, m, nbits = 65537, 8, 8 - idx1, err := NewIndexIvfPQ(mt, + idx1, err := NewIndexIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + nlist, m, nbits = 10, 8, 0 - idx2, err := NewIndexIvfPQ(mt, + idx2, err := NewIndexIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx2) - + nlist, m, nbits = 10, 8, 17 - idx3, err := NewIndexIvfPQ(mt, + idx3, err := NewIndexIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx3) - + }) } -func TestIndexHNSW(t *testing.T){ - +func TestIndexHNSW(t *testing.T) { + var M int var efConstruction int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + M, efConstruction = 16, 40 - idx0, err := NewIndexHNSW(mt, + idx0, err := NewIndexHNSW(mt, M, efConstruction, ) @@ -287,59 +276,58 @@ func TestIndexHNSW(t *testing.T){ assert.EqualValues(t, "HNSW", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + M, efConstruction = 3, 40 - idx0, err := NewIndexHNSW(mt, + idx0, err := NewIndexHNSW(mt, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + M, efConstruction = 65, 40 - idx1, err := NewIndexHNSW(mt, + idx1, err := NewIndexHNSW(mt, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + M, efConstruction = 16, 7 - idx2, err := NewIndexHNSW(mt, + idx2, err := NewIndexHNSW(mt, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx2) - + M, efConstruction = 16, 513 - idx3, err := NewIndexHNSW(mt, + idx3, err := NewIndexHNSW(mt, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx3) - + }) } -func TestIndexIvfHNSW(t *testing.T){ - +func TestIndexIvfHNSW(t *testing.T) { + var nlist int var M int var efConstruction int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist, M, efConstruction = 10, 16, 40 - idx0, err := NewIndexIvfHNSW(mt, + idx0, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, @@ -350,129 +338,120 @@ func TestIndexIvfHNSW(t *testing.T){ assert.EqualValues(t, "IVF_HNSW", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist, M, efConstruction = 0, 16, 40 - idx0, err := NewIndexIvfHNSW(mt, + idx0, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist, M, efConstruction = 65537, 16, 40 - idx1, err := NewIndexIvfHNSW(mt, + idx1, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + nlist, M, efConstruction = 10, 3, 40 - idx2, err := NewIndexIvfHNSW(mt, + idx2, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx2) - + nlist, M, efConstruction = 10, 65, 40 - idx3, err := NewIndexIvfHNSW(mt, + idx3, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx3) - + nlist, M, efConstruction = 10, 16, 7 - idx4, err := NewIndexIvfHNSW(mt, + idx4, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx4) - + nlist, M, efConstruction = 10, 16, 513 - idx5, err := NewIndexIvfHNSW(mt, + idx5, err := NewIndexIvfHNSW(mt, nlist, M, efConstruction, ) assert.NotNil(t, err) assert.Nil(t, idx5) - + }) } -func TestIndexDISKANN(t *testing.T){ - +func TestIndexDISKANN(t *testing.T) { mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - - - idx0, err := NewIndexDISKANN(mt, - ) + t.Run("valid usage case", func(t *testing.T) { + + idx0, err := NewIndexDISKANN(mt) assert.Nil(t, err) assert.NotNil(t, idx0) assert.Equal(t, "DISKANN", idx0.Name()) assert.EqualValues(t, "DISKANN", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + }) } -func TestIndexAUTOINDEX(t *testing.T){ - +func TestIndexAUTOINDEX(t *testing.T) { mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - - - idx0, err := NewIndexAUTOINDEX(mt, - ) + t.Run("valid usage case", func(t *testing.T) { + + idx0, err := NewIndexAUTOINDEX(mt) assert.Nil(t, err) assert.NotNil(t, idx0) assert.Equal(t, "AUTOINDEX", idx0.Name()) assert.EqualValues(t, "AUTOINDEX", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + }) } -func TestIndexGPUIvfFlat(t *testing.T){ - +func TestIndexGPUIvfFlat(t *testing.T) { + var nlist int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 10 - idx0, err := NewIndexGPUIvfFlat(mt, + idx0, err := NewIndexGPUIvfFlat(mt, nlist, ) assert.Nil(t, err) @@ -481,41 +460,40 @@ func TestIndexGPUIvfFlat(t *testing.T){ assert.EqualValues(t, "GPU_IVF_FLAT", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexGPUIvfFlat(mt, + idx0, err := NewIndexGPUIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexGPUIvfFlat(mt, + idx1, err := NewIndexGPUIvfFlat(mt, nlist, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } -func TestIndexGPUIvfPQ(t *testing.T){ - +func TestIndexGPUIvfPQ(t *testing.T) { + var nlist int var m int var nbits int mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist, m, nbits = 10, 8, 8 - idx0, err := NewIndexGPUIvfPQ(mt, + idx0, err := NewIndexGPUIvfPQ(mt, nlist, m, nbits, @@ -526,62 +504,61 @@ func TestIndexGPUIvfPQ(t *testing.T){ assert.EqualValues(t, "GPU_IVF_PQ", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist, m, nbits = 0, 8, 8 - idx0, err := NewIndexGPUIvfPQ(mt, + idx0, err := NewIndexGPUIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist, m, nbits = 65537, 8, 8 - idx1, err := NewIndexGPUIvfPQ(mt, + idx1, err := NewIndexGPUIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + nlist, m, nbits = 10, 8, 0 - idx2, err := NewIndexGPUIvfPQ(mt, + idx2, err := NewIndexGPUIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx2) - + nlist, m, nbits = 10, 8, 65 - idx3, err := NewIndexGPUIvfPQ(mt, + idx3, err := NewIndexGPUIvfPQ(mt, nlist, m, nbits, ) assert.NotNil(t, err) assert.Nil(t, idx3) - + }) } -func TestIndexSCANN(t *testing.T){ - +func TestIndexSCANN(t *testing.T) { + var nlist int var with_raw_data bool mt := L2 - - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nlist = 100 - idx0, err := NewIndexSCANN(mt, + idx0, err := NewIndexSCANN(mt, nlist, with_raw_data, ) @@ -591,9 +568,9 @@ func TestIndexSCANN(t *testing.T){ assert.EqualValues(t, "SCANN", idx0.IndexType()) assert.NotNil(t, idx0.Params()) assert.False(t, idx0.SupportBinary()) - + with_raw_data = true - idx1, err := NewIndexSCANN(mt, + idx1, err := NewIndexSCANN(mt, nlist, with_raw_data, ) @@ -603,27 +580,26 @@ func TestIndexSCANN(t *testing.T){ assert.EqualValues(t, "SCANN", idx1.IndexType()) assert.NotNil(t, idx1.Params()) assert.False(t, idx1.SupportBinary()) - + }) - t.Run("invalid usage case", func(t *testing.T){ - + t.Run("invalid usage case", func(t *testing.T) { + nlist = 0 - idx0, err := NewIndexSCANN(mt, + idx0, err := NewIndexSCANN(mt, nlist, with_raw_data, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nlist = 65537 - idx1, err := NewIndexSCANN(mt, + idx1, err := NewIndexSCANN(mt, nlist, with_raw_data, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) } - diff --git a/entity/indexes_search_param_gen.go b/entity/indexes_search_param_gen.go index 1a8b6b23..d12bdc1b 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 +// This file is generated by go generate package entity @@ -7,13 +7,11 @@ import ( "errors" ) - var _ SearchParam = &IndexFlatSearchParam{} // IndexFlatSearchParam search param struct for index type FLAT type IndexFlatSearchParam struct { //auto generated fields baseSearchParams - } // NewIndexFlatSearchParam create index search param @@ -22,7 +20,7 @@ func NewIndexFlatSearchParam() (*IndexFlatSearchParam, error) { sp := &IndexFlatSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting return sp, nil @@ -33,7 +31,7 @@ var _ SearchParam = &IndexBinFlatSearchParam{} // IndexBinFlatSearchParam search param struct for index type BIN_FLAT type IndexBinFlatSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -48,11 +46,11 @@ func NewIndexBinFlatSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexBinFlatSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -64,7 +62,7 @@ var _ SearchParam = &IndexIvfFlatSearchParam{} // IndexIvfFlatSearchParam search param struct for index type IVF_FLAT type IndexIvfFlatSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -79,11 +77,11 @@ func NewIndexIvfFlatSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexIvfFlatSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -95,7 +93,7 @@ var _ SearchParam = &IndexBinIvfFlatSearchParam{} // IndexBinIvfFlatSearchParam search param struct for index type BIN_IVF_FLAT type IndexBinIvfFlatSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -110,11 +108,11 @@ func NewIndexBinIvfFlatSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexBinIvfFlatSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -126,7 +124,7 @@ var _ SearchParam = &IndexIvfSQ8SearchParam{} // IndexIvfSQ8SearchParam search param struct for index type IVF_SQ8 type IndexIvfSQ8SearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -141,11 +139,11 @@ func NewIndexIvfSQ8SearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexIvfSQ8SearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -157,7 +155,7 @@ var _ SearchParam = &IndexIvfPQSearchParam{} // IndexIvfPQSearchParam search param struct for index type IVF_PQ type IndexIvfPQSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -172,11 +170,11 @@ func NewIndexIvfPQSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexIvfPQSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -188,7 +186,7 @@ var _ SearchParam = &IndexHNSWSearchParam{} // IndexHNSWSearchParam search param struct for index type HNSW type IndexHNSWSearchParam struct { //auto generated fields baseSearchParams - + ef int } @@ -203,11 +201,11 @@ func NewIndexHNSWSearchParam( if ef > 32768 { return nil, errors.New("ef has to be in range [1, 32768]") } - + sp := &IndexHNSWSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["ef"] = ef @@ -219,9 +217,9 @@ var _ SearchParam = &IndexIvfHNSWSearchParam{} // IndexIvfHNSWSearchParam search param struct for index type IVF_HNSW type IndexIvfHNSWSearchParam struct { //auto generated fields baseSearchParams - + nprobe int - ef int + ef int } // NewIndexIvfHNSWSearchParam create index search param @@ -237,18 +235,18 @@ func NewIndexIvfHNSWSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + if ef < 1 { return nil, errors.New("ef has to be in range [1, 32768]") } if ef > 32768 { return nil, errors.New("ef has to be in range [1, 32768]") } - + sp := &IndexIvfHNSWSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe sp.params["ef"] = ef @@ -261,7 +259,7 @@ var _ SearchParam = &IndexDISKANNSearchParam{} // IndexDISKANNSearchParam search param struct for index type DISKANN type IndexDISKANNSearchParam struct { //auto generated fields baseSearchParams - + search_list int } @@ -276,11 +274,11 @@ func NewIndexDISKANNSearchParam( if search_list > 65535 { return nil, errors.New("search_list has to be in range [1, 65535]") } - + sp := &IndexDISKANNSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["search_list"] = search_list @@ -292,7 +290,7 @@ var _ SearchParam = &IndexAUTOINDEXSearchParam{} // IndexAUTOINDEXSearchParam search param struct for index type AUTOINDEX type IndexAUTOINDEXSearchParam struct { //auto generated fields baseSearchParams - + level int } @@ -307,11 +305,11 @@ func NewIndexAUTOINDEXSearchParam( if level > 3 { return nil, errors.New("level has to be in range [1, 3]") } - + sp := &IndexAUTOINDEXSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["level"] = level @@ -323,7 +321,7 @@ var _ SearchParam = &IndexGPUIvfFlatSearchParam{} // IndexGPUIvfFlatSearchParam search param struct for index type GPU_IVF_FLAT type IndexGPUIvfFlatSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -338,11 +336,11 @@ func NewIndexGPUIvfFlatSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexGPUIvfFlatSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -354,7 +352,7 @@ var _ SearchParam = &IndexGPUIvfPQSearchParam{} // IndexGPUIvfPQSearchParam search param struct for index type GPU_IVF_PQ type IndexGPUIvfPQSearchParam struct { //auto generated fields baseSearchParams - + nprobe int } @@ -369,11 +367,11 @@ func NewIndexGPUIvfPQSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + sp := &IndexGPUIvfPQSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe @@ -385,8 +383,8 @@ var _ SearchParam = &IndexSCANNSearchParam{} // IndexSCANNSearchParam search param struct for index type SCANN type IndexSCANNSearchParam struct { //auto generated fields baseSearchParams - - nprobe int + + nprobe int reorder_k int } @@ -403,22 +401,21 @@ func NewIndexSCANNSearchParam( if nprobe > 65536 { return nil, errors.New("nprobe has to be in range [1, 65536]") } - + if reorder_k < 1 { return nil, errors.New("reorder_k has to be in range [1, 9223372036854775807]") } if reorder_k > 9223372036854775807 { return nil, errors.New("reorder_k has to be in range [1, 9223372036854775807]") } - + sp := &IndexSCANNSearchParam{ baseSearchParams: newBaseSearchParams(), } - + //auto generated setting sp.params["nprobe"] = nprobe sp.params["reorder_k"] = reorder_k return sp, nil } - diff --git a/entity/indexes_search_param_gen_test.go b/entity/indexes_search_param_gen_test.go index 67b9d599..3544d223 100755 --- a/entity/indexes_search_param_gen_test.go +++ b/entity/indexes_search_param_gen_test.go @@ -9,29 +9,25 @@ import ( "github.com/stretchr/testify/assert" ) - func TestIndexFlatSearchParam(t *testing.T) { - - t.Run("valid usage case", func(t *testing.T){ - - - idx0, err := NewIndexFlatSearchParam( - ) + t.Run("valid usage case", func(t *testing.T) { + + idx0, err := NewIndexFlatSearchParam() assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - + } func TestIndexBinFlatSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexBinFlatSearchParam( nprobe, @@ -39,35 +35,35 @@ func TestIndexBinFlatSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexBinFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexBinFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexIvfFlatSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexIvfFlatSearchParam( nprobe, @@ -75,35 +71,35 @@ func TestIndexIvfFlatSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexBinIvfFlatSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexBinIvfFlatSearchParam( nprobe, @@ -111,35 +107,35 @@ func TestIndexBinIvfFlatSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexBinIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexBinIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexIvfSQ8SearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexIvfSQ8SearchParam( nprobe, @@ -147,35 +143,35 @@ func TestIndexIvfSQ8SearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexIvfSQ8SearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexIvfSQ8SearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexIvfPQSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexIvfPQSearchParam( nprobe, @@ -183,35 +179,35 @@ func TestIndexIvfPQSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexIvfPQSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexIvfPQSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexHNSWSearchParam(t *testing.T) { - + var ef int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + ef = 16 idx0, err := NewIndexHNSWSearchParam( ef, @@ -219,36 +215,36 @@ func TestIndexHNSWSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + ef = 0 idx0, err := NewIndexHNSWSearchParam( ef, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + ef = 32769 idx1, err := NewIndexHNSWSearchParam( ef, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexIvfHNSWSearchParam(t *testing.T) { - + var nprobe int var ef int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe, ef = 10, 16 idx0, err := NewIndexIvfHNSWSearchParam( nprobe, @@ -257,11 +253,11 @@ func TestIndexIvfHNSWSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe, ef = 0, 16 idx0, err := NewIndexIvfHNSWSearchParam( nprobe, @@ -269,7 +265,7 @@ func TestIndexIvfHNSWSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe, ef = 65537, 16 idx1, err := NewIndexIvfHNSWSearchParam( nprobe, @@ -277,7 +273,7 @@ func TestIndexIvfHNSWSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx1) - + nprobe, ef = 10, 0 idx2, err := NewIndexIvfHNSWSearchParam( nprobe, @@ -285,7 +281,7 @@ func TestIndexIvfHNSWSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx2) - + nprobe, ef = 10, 32769 idx3, err := NewIndexIvfHNSWSearchParam( nprobe, @@ -293,17 +289,17 @@ func TestIndexIvfHNSWSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx3) - + }) - + } func TestIndexDISKANNSearchParam(t *testing.T) { - + var search_list int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + search_list = 30 idx0, err := NewIndexDISKANNSearchParam( search_list, @@ -311,35 +307,35 @@ func TestIndexDISKANNSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + search_list = 0 idx0, err := NewIndexDISKANNSearchParam( search_list, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + search_list = 65537 idx1, err := NewIndexDISKANNSearchParam( search_list, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexAUTOINDEXSearchParam(t *testing.T) { - + var level int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + level = 1 idx0, err := NewIndexAUTOINDEXSearchParam( level, @@ -347,42 +343,42 @@ func TestIndexAUTOINDEXSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + level = 0 idx0, err := NewIndexAUTOINDEXSearchParam( level, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + level = 10 idx1, err := NewIndexAUTOINDEXSearchParam( level, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + level = -1 idx2, err := NewIndexAUTOINDEXSearchParam( level, ) assert.NotNil(t, err) assert.Nil(t, idx2) - + }) - + } func TestIndexGPUIvfFlatSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexGPUIvfFlatSearchParam( nprobe, @@ -390,35 +386,35 @@ func TestIndexGPUIvfFlatSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexGPUIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexGPUIvfFlatSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexGPUIvfPQSearchParam(t *testing.T) { - + var nprobe int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe = 10 idx0, err := NewIndexGPUIvfPQSearchParam( nprobe, @@ -426,36 +422,36 @@ func TestIndexGPUIvfPQSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe = 0 idx0, err := NewIndexGPUIvfPQSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe = 65537 idx1, err := NewIndexGPUIvfPQSearchParam( nprobe, ) assert.NotNil(t, err) assert.Nil(t, idx1) - + }) - + } func TestIndexSCANNSearchParam(t *testing.T) { - + var nprobe int var reorder_k int - t.Run("valid usage case", func(t *testing.T){ - + t.Run("valid usage case", func(t *testing.T) { + nprobe, reorder_k = 10, 200 idx0, err := NewIndexSCANNSearchParam( nprobe, @@ -464,11 +460,11 @@ func TestIndexSCANNSearchParam(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, idx0) assert.NotNil(t, idx0.Params()) - + }) - - t.Run("invalid usage case", func(t *testing.T){ - + + t.Run("invalid usage case", func(t *testing.T) { + nprobe, reorder_k = 0, 200 idx0, err := NewIndexSCANNSearchParam( nprobe, @@ -476,7 +472,7 @@ func TestIndexSCANNSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx0) - + nprobe, reorder_k = 65537, 200 idx1, err := NewIndexSCANNSearchParam( nprobe, @@ -484,7 +480,7 @@ func TestIndexSCANNSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx1) - + nprobe, reorder_k = 10, -1 idx2, err := NewIndexSCANNSearchParam( nprobe, @@ -492,8 +488,7 @@ func TestIndexSCANNSearchParam(t *testing.T) { ) assert.NotNil(t, err) assert.Nil(t, idx2) - + }) - -} +} diff --git a/indexes_gen.go b/indexes_gen.go new file mode 100755 index 00000000..5235b348 --- /dev/null +++ b/indexes_gen.go @@ -0,0 +1,865 @@ +// Code generated by go generate; DO NOT EDIT +// This file is generated by go generate + +package entity + +import ( + "errors" + "encoding/json" + "fmt" +) + + + +var _ Index = &IndexFlat{} + +// IndexFlat idx type for FLAT +type IndexFlat struct { //auto generated fields + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexFlat) Name() string { + return "Flat" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// Params returns index construction params, implementing Index interface +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()), + "metric_type": string(i.metricType), + } +} + +// NewIndexFlat create index with construction parameters +func NewIndexFlat(metricType MetricType, ) (*IndexFlat, error) { + // auto generate parameters validation code, if any + return &IndexFlat{ + metricType: metricType, + }, nil +} + + +var _ Index = &IndexBinFlat{} + +// IndexBinFlat idx type for BIN_FLAT +type IndexBinFlat struct { //auto generated fields + nlist int + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexBinFlat) Name() string { + return "BinFlat" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, +) (*IndexBinFlat, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + 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 + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexIvfFlat) Name() string { + return "IvfFlat" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, +) (*IndexIvfFlat, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + 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 + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexBinIvfFlat) Name() string { + return "BinIvfFlat" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, +) (*IndexBinIvfFlat, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + 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 + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexIvfSQ8) Name() string { + return "IvfSQ8" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, +) (*IndexIvfSQ8, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + 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 + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexIvfPQ) Name() string { + return "IvfPQ" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, + + m int, + + nbits int, +) (*IndexIvfPQ, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + + + if nbits < 1 { + return nil, errors.New("nbits has to be in range [1, 16]") + } + if nbits > 16 { + return nil, errors.New("nbits has to be in range [1, 16]") + } + + 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 + efConstruction int + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexHNSW) Name() string { + return "HNSW" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + M int, + + efConstruction int, +) (*IndexHNSW, error) { + // auto generate parameters validation code, if any + if M < 4 { + return nil, errors.New("M has to be in range [4, 64]") + } + if M > 64 { + return nil, errors.New("M has to be in range [4, 64]") + } + + if efConstruction < 8 { + return nil, errors.New("efConstruction has to be in range [8, 512]") + } + if efConstruction > 512 { + return nil, errors.New("efConstruction has to be in range [8, 512]") + } + + 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 + efConstruction int + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexIvfHNSW) Name() string { + return "IvfHNSW" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// 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), + } + bs, _ := json.Marshal(params) + 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, + nlist int, + + M int, + + efConstruction int, +) (*IndexIvfHNSW, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + if M < 4 { + return nil, errors.New("M has to be in range [4, 64]") + } + if M > 64 { + return nil, errors.New("M has to be in range [4, 64]") + } + + if efConstruction < 8 { + return nil, errors.New("efConstruction has to be in range [8, 512]") + } + if efConstruction > 512 { + return nil, errors.New("efConstruction has to be in range [8, 512]") + } + + return &IndexIvfHNSW{ + //auto generated setting + nlist: nlist, + //auto generated setting + M: M, + //auto generated setting + efConstruction: efConstruction, + metricType: metricType, + }, nil +} + + +var _ Index = &IndexDISKANN{} + +// IndexDISKANN idx type for DISKANN +type IndexDISKANN struct { //auto generated fields + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexDISKANN) Name() string { + return "DISKANN" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// Params returns index construction params, implementing Index interface +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()), + "metric_type": string(i.metricType), + } +} + +// NewIndexDISKANN create index with construction parameters +func NewIndexDISKANN(metricType MetricType, ) (*IndexDISKANN, error) { + // auto generate parameters validation code, if any + return &IndexDISKANN{ + metricType: metricType, + }, nil +} + + +var _ Index = &IndexAUTOINDEX{} + +// IndexAUTOINDEX idx type for AUTOINDEX +type IndexAUTOINDEX struct { //auto generated fields + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexAUTOINDEX) Name() string { + return "AUTOINDEX" +} + +// IndexType returns IndexType, implementing Index interface +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 +} + +// Params returns index construction params, implementing Index interface +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()), + "metric_type": string(i.metricType), + } +} + +// NewIndexAUTOINDEX create index with construction parameters +func NewIndexAUTOINDEX(metricType MetricType, ) (*IndexAUTOINDEX, error) { + // auto generate parameters validation code, if any + return &IndexAUTOINDEX{ + metricType: metricType, + }, nil +} + + +var _ Index = &IndexGPUIvfFlat{} + +// IndexGPUIvfFlat idx type for GPU_IVF_FLAT +type IndexGPUIvfFlat struct { //auto generated fields + nlist int + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexGPUIvfFlat) Name() string { + return "GPUIvfFlat" +} + +// IndexType returns IndexType, implementing Index interface +func(i *IndexGPUIvfFlat) IndexType() IndexType { + return IndexType("GPU_IVF_FLAT") +} + +// FieldName returns FieldName, implementing Index interface +func(i *IndexGPUIvfFlat) FieldName() string { + return "vec_field" +} + +// SupportBinary returns whether index type support binary vector +func(i *IndexGPUIvfFlat) SupportBinary() bool { + return 0 & 2 > 0 +} + +// Params returns index construction params, implementing Index interface +func(i *IndexGPUIvfFlat) 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()), + "metric_type": string(i.metricType), + } +} + +// NewIndexGPUIvfFlat create index with construction parameters +func NewIndexGPUIvfFlat(metricType MetricType, + nlist int, +) (*IndexGPUIvfFlat, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + return &IndexGPUIvfFlat{ + //auto generated setting + nlist: nlist, + metricType: metricType, + }, nil +} + + +var _ Index = &IndexGPUIvfPQ{} + +// IndexGPUIvfPQ idx type for GPU_IVF_PQ +type IndexGPUIvfPQ struct { //auto generated fields + nlist int + m int + nbits int + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexGPUIvfPQ) Name() string { + return "GPUIvfPQ" +} + +// IndexType returns IndexType, implementing Index interface +func(i *IndexGPUIvfPQ) IndexType() IndexType { + return IndexType("GPU_IVF_PQ") +} + +// FieldName returns FieldName, implementing Index interface +func(i *IndexGPUIvfPQ) FieldName() string { + return "vec_field" +} + +// SupportBinary returns whether index type support binary vector +func(i *IndexGPUIvfPQ) SupportBinary() bool { + return 0 & 2 > 0 +} + +// Params returns index construction params, implementing Index interface +func(i *IndexGPUIvfPQ) 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()), + "metric_type": string(i.metricType), + } +} + +// NewIndexGPUIvfPQ create index with construction parameters +func NewIndexGPUIvfPQ(metricType MetricType, + nlist int, + + m int, + + nbits int, +) (*IndexGPUIvfPQ, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + + + if nbits < 1 { + return nil, errors.New("nbits has to be in range [1, 64]") + } + if nbits > 64 { + return nil, errors.New("nbits has to be in range [1, 64]") + } + + return &IndexGPUIvfPQ{ + //auto generated setting + nlist: nlist, + //auto generated setting + m: m, + //auto generated setting + nbits: nbits, + metricType: metricType, + }, nil +} + + +var _ Index = &IndexSCANN{} + +// IndexSCANN idx type for IVF_FLAT +type IndexSCANN struct { //auto generated fields + nlist int + with_raw_data bool + metricType MetricType +} + +// Name returns index type name, implementing Index interface +func(i *IndexSCANN) Name() string { + return "SCANN" +} + +// IndexType returns IndexType, implementing Index interface +func(i *IndexSCANN) IndexType() IndexType { + return IndexType("IVF_FLAT") +} + +// FieldName returns FieldName, implementing Index interface +func(i *IndexSCANN) FieldName() string { + return "vec_field" +} + +// SupportBinary returns whether index type support binary vector +func(i *IndexSCANN) SupportBinary() bool { + return 0 & 2 > 0 +} + +// Params returns index construction params, implementing Index interface +func(i *IndexSCANN) Params() map[string]string { + params := map[string]string {//auto generated mapping + "nlist": fmt.Sprintf("%v",i.nlist), + "with_raw_data": fmt.Sprintf("%v",i.with_raw_data), + } + bs, _ := json.Marshal(params) + return map[string]string { + "params": string(bs), + "index_type": string(i.IndexType()), + "metric_type": string(i.metricType), + } +} + +// NewIndexSCANN create index with construction parameters +func NewIndexSCANN(metricType MetricType, + nlist int, + + with_raw_data bool, +) (*IndexSCANN, error) { + // auto generate parameters validation code, if any + if nlist < 1 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + if nlist > 65536 { + return nil, errors.New("nlist has to be in range [1, 65536]") + } + + validRange := []bool{false, true} + with_raw_dataOk := false + for _, v := range validRange { + if v == with_raw_data { + with_raw_dataOk = true + break + } + } + if !with_raw_dataOk { + return nil, errors.New("with_raw_data not valid") + } + + return &IndexSCANN{ + //auto generated setting + nlist: nlist, + //auto generated setting + with_raw_data: with_raw_data, + metricType: metricType, + }, nil +} + diff --git a/indexes_gen_test.go b/indexes_gen_test.go new file mode 100755 index 00000000..cec8afb7 --- /dev/null +++ b/indexes_gen_test.go @@ -0,0 +1,629 @@ +// Code generated by go generate; DO NOT EDIT +// This file is generated by go generate + +package entity + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + + +func TestIndexFlat(t *testing.T){ + + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + + idx0, err := NewIndexFlat(mt, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "Flat", idx0.Name()) + assert.EqualValues(t, "FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + }) +} + +func TestIndexBinFlat(t *testing.T){ + + var nlist int + + mt := HAMMING + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 10 + idx0, err := NewIndexBinFlat(mt, + nlist, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "BinFlat", idx0.Name()) + assert.EqualValues(t, "BIN_FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.True(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexBinFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexBinFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + +func TestIndexIvfFlat(t *testing.T){ + + var nlist int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 10 + idx0, err := NewIndexIvfFlat(mt, + nlist, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "IvfFlat", idx0.Name()) + assert.EqualValues(t, "IVF_FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + +func TestIndexBinIvfFlat(t *testing.T){ + + var nlist int + + mt := HAMMING + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 10 + idx0, err := NewIndexBinIvfFlat(mt, + nlist, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "BinIvfFlat", idx0.Name()) + assert.EqualValues(t, "BIN_IVF_FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.True(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexBinIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexBinIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + +func TestIndexIvfSQ8(t *testing.T){ + + var nlist int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 10 + idx0, err := NewIndexIvfSQ8(mt, + nlist, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "IvfSQ8", idx0.Name()) + assert.EqualValues(t, "IVF_SQ8", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexIvfSQ8(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexIvfSQ8(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + +func TestIndexIvfPQ(t *testing.T){ + + var nlist int + var m int + var nbits int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist, m, nbits = 10, 8, 8 + idx0, err := NewIndexIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "IvfPQ", idx0.Name()) + assert.EqualValues(t, "IVF_PQ", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist, m, nbits = 0, 8, 8 + idx0, err := NewIndexIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist, m, nbits = 65537, 8, 8 + idx1, err := NewIndexIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + nlist, m, nbits = 10, 8, 0 + idx2, err := NewIndexIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + nlist, m, nbits = 10, 8, 17 + idx3, err := NewIndexIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx3) + + }) +} + +func TestIndexHNSW(t *testing.T){ + + var M int + var efConstruction int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + M, efConstruction = 16, 40 + idx0, err := NewIndexHNSW(mt, + M, + efConstruction, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "HNSW", idx0.Name()) + assert.EqualValues(t, "HNSW", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + M, efConstruction = 3, 40 + idx0, err := NewIndexHNSW(mt, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + M, efConstruction = 65, 40 + idx1, err := NewIndexHNSW(mt, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + M, efConstruction = 16, 7 + idx2, err := NewIndexHNSW(mt, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + M, efConstruction = 16, 513 + idx3, err := NewIndexHNSW(mt, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx3) + + }) +} + +func TestIndexIvfHNSW(t *testing.T){ + + var nlist int + var M int + var efConstruction int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist, M, efConstruction = 10, 16, 40 + idx0, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "IvfHNSW", idx0.Name()) + assert.EqualValues(t, "IVF_HNSW", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist, M, efConstruction = 0, 16, 40 + idx0, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist, M, efConstruction = 65537, 16, 40 + idx1, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + nlist, M, efConstruction = 10, 3, 40 + idx2, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + nlist, M, efConstruction = 10, 65, 40 + idx3, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx3) + + nlist, M, efConstruction = 10, 16, 7 + idx4, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx4) + + nlist, M, efConstruction = 10, 16, 513 + idx5, err := NewIndexIvfHNSW(mt, + nlist, + M, + efConstruction, + ) + assert.NotNil(t, err) + assert.Nil(t, idx5) + + }) +} + +func TestIndexDISKANN(t *testing.T){ + + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + + idx0, err := NewIndexDISKANN(mt, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "DISKANN", idx0.Name()) + assert.EqualValues(t, "DISKANN", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + }) +} + +func TestIndexAUTOINDEX(t *testing.T){ + + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + + idx0, err := NewIndexAUTOINDEX(mt, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "AUTOINDEX", idx0.Name()) + assert.EqualValues(t, "AUTOINDEX", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + }) +} + +func TestIndexGPUIvfFlat(t *testing.T){ + + var nlist int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 10 + idx0, err := NewIndexGPUIvfFlat(mt, + nlist, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "GPUIvfFlat", idx0.Name()) + assert.EqualValues(t, "GPU_IVF_FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexGPUIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexGPUIvfFlat(mt, + nlist, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + +func TestIndexGPUIvfPQ(t *testing.T){ + + var nlist int + var m int + var nbits int + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist, m, nbits = 10, 8, 8 + idx0, err := NewIndexGPUIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "GPUIvfPQ", idx0.Name()) + assert.EqualValues(t, "GPU_IVF_PQ", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist, m, nbits = 0, 8, 8 + idx0, err := NewIndexGPUIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist, m, nbits = 65537, 8, 8 + idx1, err := NewIndexGPUIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + nlist, m, nbits = 10, 8, 0 + idx2, err := NewIndexGPUIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + nlist, m, nbits = 10, 8, 65 + idx3, err := NewIndexGPUIvfPQ(mt, + nlist, + m, + nbits, + ) + assert.NotNil(t, err) + assert.Nil(t, idx3) + + }) +} + +func TestIndexSCANN(t *testing.T){ + + var nlist int + var with_raw_data bool + + mt := L2 + + + t.Run("valid usage case", func(t *testing.T){ + + nlist = 100 + idx0, err := NewIndexSCANN(mt, + nlist, + with_raw_data, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.Equal(t, "SCANN", idx0.Name()) + assert.EqualValues(t, "IVF_FLAT", idx0.IndexType()) + assert.NotNil(t, idx0.Params()) + assert.False(t, idx0.SupportBinary()) + + with_raw_data = true + idx1, err := NewIndexSCANN(mt, + nlist, + with_raw_data, + ) + assert.Nil(t, err) + assert.NotNil(t, idx1) + assert.Equal(t, "SCANN", idx1.Name()) + assert.EqualValues(t, "IVF_FLAT", idx1.IndexType()) + assert.NotNil(t, idx1.Params()) + assert.False(t, idx1.SupportBinary()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nlist = 0 + idx0, err := NewIndexSCANN(mt, + nlist, + with_raw_data, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nlist = 65537 + idx1, err := NewIndexSCANN(mt, + nlist, + with_raw_data, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) +} + diff --git a/indexes_search_param_gen.go b/indexes_search_param_gen.go new file mode 100755 index 00000000..a5a8148c --- /dev/null +++ b/indexes_search_param_gen.go @@ -0,0 +1,424 @@ +// Code generated by go generate; DO NOT EDIT +// This file is generated by go generate + +package entity + +import ( + "errors" +) + + +var _ SearchParam = &IndexFlatSearchParam{} + +// IndexFlatSearchParam search param struct for index type FLAT +type IndexFlatSearchParam struct { //auto generated fields + baseSearchParams + +} + +// NewIndexFlatSearchParam create index search param +func NewIndexFlatSearchParam() (*IndexFlatSearchParam, error) { + // auto generate parameters validation code, if any + sp := &IndexFlatSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + + return sp, nil +} + +var _ SearchParam = &IndexBinFlatSearchParam{} + +// IndexBinFlatSearchParam search param struct for index type BIN_FLAT +type IndexBinFlatSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexBinFlatSearchParam create index search param +func NewIndexBinFlatSearchParam( + nprobe int, +) (*IndexBinFlatSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexBinFlatSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexIvfFlatSearchParam{} + +// IndexIvfFlatSearchParam search param struct for index type IVF_FLAT +type IndexIvfFlatSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexIvfFlatSearchParam create index search param +func NewIndexIvfFlatSearchParam( + nprobe int, +) (*IndexIvfFlatSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexIvfFlatSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexBinIvfFlatSearchParam{} + +// IndexBinIvfFlatSearchParam search param struct for index type BIN_IVF_FLAT +type IndexBinIvfFlatSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexBinIvfFlatSearchParam create index search param +func NewIndexBinIvfFlatSearchParam( + nprobe int, +) (*IndexBinIvfFlatSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexBinIvfFlatSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexIvfSQ8SearchParam{} + +// IndexIvfSQ8SearchParam search param struct for index type IVF_SQ8 +type IndexIvfSQ8SearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexIvfSQ8SearchParam create index search param +func NewIndexIvfSQ8SearchParam( + nprobe int, +) (*IndexIvfSQ8SearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexIvfSQ8SearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexIvfPQSearchParam{} + +// IndexIvfPQSearchParam search param struct for index type IVF_PQ +type IndexIvfPQSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexIvfPQSearchParam create index search param +func NewIndexIvfPQSearchParam( + nprobe int, +) (*IndexIvfPQSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexIvfPQSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexHNSWSearchParam{} + +// IndexHNSWSearchParam search param struct for index type HNSW +type IndexHNSWSearchParam struct { //auto generated fields + baseSearchParams + + ef int +} + +// NewIndexHNSWSearchParam create index search param +func NewIndexHNSWSearchParam( + ef int, +) (*IndexHNSWSearchParam, error) { + // auto generate parameters validation code, if any + if ef < 1 { + return nil, errors.New("ef has to be in range [1, 32768]") + } + if ef > 32768 { + return nil, errors.New("ef has to be in range [1, 32768]") + } + + sp := &IndexHNSWSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["ef"] = ef + + return sp, nil +} + +var _ SearchParam = &IndexIvfHNSWSearchParam{} + +// IndexIvfHNSWSearchParam search param struct for index type IVF_HNSW +type IndexIvfHNSWSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int + ef int +} + +// NewIndexIvfHNSWSearchParam create index search param +func NewIndexIvfHNSWSearchParam( + nprobe int, + + ef int, +) (*IndexIvfHNSWSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + if ef < 1 { + return nil, errors.New("ef has to be in range [1, 32768]") + } + if ef > 32768 { + return nil, errors.New("ef has to be in range [1, 32768]") + } + + sp := &IndexIvfHNSWSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + sp.params["ef"] = ef + + return sp, nil +} + +var _ SearchParam = &IndexDISKANNSearchParam{} + +// IndexDISKANNSearchParam search param struct for index type DISKANN +type IndexDISKANNSearchParam struct { //auto generated fields + baseSearchParams + + search_list int +} + +// NewIndexDISKANNSearchParam create index search param +func NewIndexDISKANNSearchParam( + search_list int, +) (*IndexDISKANNSearchParam, error) { + // auto generate parameters validation code, if any + if search_list < 1 { + return nil, errors.New("search_list has to be in range [1, 65535]") + } + if search_list > 65535 { + return nil, errors.New("search_list has to be in range [1, 65535]") + } + + sp := &IndexDISKANNSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["search_list"] = search_list + + return sp, nil +} + +var _ SearchParam = &IndexAUTOINDEXSearchParam{} + +// IndexAUTOINDEXSearchParam search param struct for index type AUTOINDEX +type IndexAUTOINDEXSearchParam struct { //auto generated fields + baseSearchParams + + level int +} + +// NewIndexAUTOINDEXSearchParam create index search param +func NewIndexAUTOINDEXSearchParam( + level int, +) (*IndexAUTOINDEXSearchParam, error) { + // auto generate parameters validation code, if any + if level < 1 { + return nil, errors.New("level has to be in range [1, 3]") + } + if level > 3 { + return nil, errors.New("level has to be in range [1, 3]") + } + + sp := &IndexAUTOINDEXSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["level"] = level + + return sp, nil +} + +var _ SearchParam = &IndexGPUIvfFlatSearchParam{} + +// IndexGPUIvfFlatSearchParam search param struct for index type GPU_IVF_FLAT +type IndexGPUIvfFlatSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexGPUIvfFlatSearchParam create index search param +func NewIndexGPUIvfFlatSearchParam( + nprobe int, +) (*IndexGPUIvfFlatSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexGPUIvfFlatSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexGPUIvfPQSearchParam{} + +// IndexGPUIvfPQSearchParam search param struct for index type GPU_IVF_PQ +type IndexGPUIvfPQSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int +} + +// NewIndexGPUIvfPQSearchParam create index search param +func NewIndexGPUIvfPQSearchParam( + nprobe int, +) (*IndexGPUIvfPQSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + sp := &IndexGPUIvfPQSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + + return sp, nil +} + +var _ SearchParam = &IndexSCANNSearchParam{} + +// IndexSCANNSearchParam search param struct for index type IVF_FLAT +type IndexSCANNSearchParam struct { //auto generated fields + baseSearchParams + + nprobe int + reorder_k int +} + +// NewIndexSCANNSearchParam create index search param +func NewIndexSCANNSearchParam( + nprobe int, + + reorder_k int, +) (*IndexSCANNSearchParam, error) { + // auto generate parameters validation code, if any + if nprobe < 1 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + if nprobe > 65536 { + return nil, errors.New("nprobe has to be in range [1, 65536]") + } + + if reorder_k < 1 { + return nil, errors.New("reorder_k has to be in range [1, 9223372036854775807]") + } + if reorder_k > 9223372036854775807 { + return nil, errors.New("reorder_k has to be in range [1, 9223372036854775807]") + } + + sp := &IndexSCANNSearchParam{ + baseSearchParams: newBaseSearchParams(), + } + + //auto generated setting + sp.params["nprobe"] = nprobe + sp.params["reorder_k"] = reorder_k + + return sp, nil +} + diff --git a/indexes_search_param_gen_test.go b/indexes_search_param_gen_test.go new file mode 100755 index 00000000..67b9d599 --- /dev/null +++ b/indexes_search_param_gen_test.go @@ -0,0 +1,499 @@ +// Code generated by go generate; DO NOT EDIT +// This file is generated by go generate + +package entity + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + + +func TestIndexFlatSearchParam(t *testing.T) { + + + t.Run("valid usage case", func(t *testing.T){ + + + idx0, err := NewIndexFlatSearchParam( + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + +} + +func TestIndexBinFlatSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexBinFlatSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexBinFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexBinFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexIvfFlatSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexIvfFlatSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexBinIvfFlatSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexBinIvfFlatSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexBinIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexBinIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexIvfSQ8SearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexIvfSQ8SearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexIvfSQ8SearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexIvfSQ8SearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexIvfPQSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexIvfPQSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexIvfPQSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexIvfPQSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexHNSWSearchParam(t *testing.T) { + + var ef int + + t.Run("valid usage case", func(t *testing.T){ + + ef = 16 + idx0, err := NewIndexHNSWSearchParam( + ef, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + ef = 0 + idx0, err := NewIndexHNSWSearchParam( + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + ef = 32769 + idx1, err := NewIndexHNSWSearchParam( + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexIvfHNSWSearchParam(t *testing.T) { + + var nprobe int + var ef int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe, ef = 10, 16 + idx0, err := NewIndexIvfHNSWSearchParam( + nprobe, + ef, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe, ef = 0, 16 + idx0, err := NewIndexIvfHNSWSearchParam( + nprobe, + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe, ef = 65537, 16 + idx1, err := NewIndexIvfHNSWSearchParam( + nprobe, + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + nprobe, ef = 10, 0 + idx2, err := NewIndexIvfHNSWSearchParam( + nprobe, + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + nprobe, ef = 10, 32769 + idx3, err := NewIndexIvfHNSWSearchParam( + nprobe, + ef, + ) + assert.NotNil(t, err) + assert.Nil(t, idx3) + + }) + +} + +func TestIndexDISKANNSearchParam(t *testing.T) { + + var search_list int + + t.Run("valid usage case", func(t *testing.T){ + + search_list = 30 + idx0, err := NewIndexDISKANNSearchParam( + search_list, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + search_list = 0 + idx0, err := NewIndexDISKANNSearchParam( + search_list, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + search_list = 65537 + idx1, err := NewIndexDISKANNSearchParam( + search_list, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexAUTOINDEXSearchParam(t *testing.T) { + + var level int + + t.Run("valid usage case", func(t *testing.T){ + + level = 1 + idx0, err := NewIndexAUTOINDEXSearchParam( + level, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + level = 0 + idx0, err := NewIndexAUTOINDEXSearchParam( + level, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + level = 10 + idx1, err := NewIndexAUTOINDEXSearchParam( + level, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + level = -1 + idx2, err := NewIndexAUTOINDEXSearchParam( + level, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + }) + +} + +func TestIndexGPUIvfFlatSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexGPUIvfFlatSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexGPUIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexGPUIvfFlatSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexGPUIvfPQSearchParam(t *testing.T) { + + var nprobe int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe = 10 + idx0, err := NewIndexGPUIvfPQSearchParam( + nprobe, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe = 0 + idx0, err := NewIndexGPUIvfPQSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe = 65537 + idx1, err := NewIndexGPUIvfPQSearchParam( + nprobe, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + }) + +} + +func TestIndexSCANNSearchParam(t *testing.T) { + + var nprobe int + var reorder_k int + + t.Run("valid usage case", func(t *testing.T){ + + nprobe, reorder_k = 10, 200 + idx0, err := NewIndexSCANNSearchParam( + nprobe, + reorder_k, + ) + assert.Nil(t, err) + assert.NotNil(t, idx0) + assert.NotNil(t, idx0.Params()) + + }) + + t.Run("invalid usage case", func(t *testing.T){ + + nprobe, reorder_k = 0, 200 + idx0, err := NewIndexSCANNSearchParam( + nprobe, + reorder_k, + ) + assert.NotNil(t, err) + assert.Nil(t, idx0) + + nprobe, reorder_k = 65537, 200 + idx1, err := NewIndexSCANNSearchParam( + nprobe, + reorder_k, + ) + assert.NotNil(t, err) + assert.Nil(t, idx1) + + nprobe, reorder_k = 10, -1 + idx2, err := NewIndexSCANNSearchParam( + nprobe, + reorder_k, + ) + assert.NotNil(t, err) + assert.Nil(t, idx2) + + }) + +} + diff --git a/test/testcases/highlevel_test.go b/test/testcases/highlevel_test.go index 4f1a7eaa..aaf85605 100644 --- a/test/testcases/highlevel_test.go +++ b/test/testcases/highlevel_test.go @@ -44,7 +44,7 @@ func TestNewCollection(t *testing.T) { "index_type": string(entity.AUTOINDEX), } // TODO why the index name is _default_idx_101 default is _default_idx_102 ? - expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, DefaultVectorFieldName, expParams) common.CheckIndexResult(t, indexes, expIndex) // check collection is loaded @@ -121,7 +121,7 @@ func TestNewCollectionCustomize(t *testing.T) { "metric_type": string(entity.L2), "index_type": string(entity.AUTOINDEX), } - expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex("_default_idx_101", entity.AUTOINDEX, DefaultVectorFieldName, expParams) common.CheckIndexResult(t, indexes, expIndex) // check collection is loaded diff --git a/test/testcases/index_test.go b/test/testcases/index_test.go index a66c8b52..79087796 100644 --- a/test/testcases/index_test.go +++ b/test/testcases/index_test.go @@ -32,7 +32,7 @@ func TestCreateIndex(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } } @@ -50,7 +50,7 @@ func TestCreateIndexString(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultVarcharFieldName) - expIndex := entity.NewGenericIndex("scalar_index", "", idx.Params()) + expIndex := entity.NewGenericIndex("scalar_index", "", common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } @@ -108,7 +108,7 @@ func TestCreateIndexIp(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } } @@ -135,7 +135,7 @@ func TestCreateIndexBinaryFlat(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultBinaryVecFieldName) - expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } } @@ -162,7 +162,7 @@ func TestCreateIndexBinaryIvfFlat(t *testing.T) { // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultBinaryVecFieldName) - expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex("my_index", idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } } @@ -209,7 +209,7 @@ func TestCreateIndexWithoutName(t *testing.T) { // describe index return index with default name indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) } @@ -223,7 +223,7 @@ func TestCreateIndexWithoutIndexTypeParams(t *testing.T) { collName, _ := createCollectionWithDataIndex(ctx, t, mc, false, false) // create index - idx := entity.NewGenericIndex("", "", nil) + idx := entity.NewGenericIndex("", "", common.DefaultFloatVecFieldName, nil) err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false) common.CheckErr(t, err, true) @@ -233,7 +233,7 @@ func TestCreateIndexWithoutIndexTypeParams(t *testing.T) { "metric_type": string(entity.IP), "index_type": string(entity.AUTOINDEX), } - expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.AUTOINDEX, expParams) + expIndex := entity.NewGenericIndex(common.DefaultIndexName, entity.AUTOINDEX, common.DefaultFloatVecFieldName, expParams) common.CheckIndexResult(t, indexes, expIndex) } @@ -248,13 +248,13 @@ func TestCreateIndexGeneric(t *testing.T) { // create index IvfFlatParams := map[string]string{"nlist": "128", "metric_type": "L2"} - idx := entity.NewGenericIndex("my_index", entity.IvfFlat, IvfFlatParams) + idx := entity.NewGenericIndex("my_index", entity.IvfFlat, common.DefaultFloatVecFieldName, IvfFlatParams) err := mc.CreateIndex(ctx, collName, common.DefaultFloatVecFieldName, idx, false) common.CheckErr(t, err, true) // describe index indexes, _ := mc.DescribeIndex(ctx, collName, common.DefaultFloatVecFieldName) - expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), idx.Params()) + expIndex := entity.NewGenericIndex(common.DefaultIndexName, idx.IndexType(), common.DefaultFloatVecFieldName, idx.Params()) common.CheckIndexResult(t, indexes, expIndex) }