Skip to content

Commit

Permalink
Add fieldName in index
Browse files Browse the repository at this point in the history
Signed-off-by: wayblink <[email protected]>
  • Loading branch information
wayblink committed Sep 15, 2023
1 parent 849300d commit 1197006
Show file tree
Hide file tree
Showing 11 changed files with 702 additions and 660 deletions.
2 changes: 1 addition & 1 deletion client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand Down
3 changes: 2 additions & 1 deletion client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,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)
Expand Down
51 changes: 35 additions & 16 deletions entity/genidx/genidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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
Expand Down Expand Up @@ -223,6 +228,7 @@ func TestIndex{{.IdxName}}SearchParam(t *testing.T) {
type idxDef struct {
IdxName string
IdxType entity.IndexType
FieldName string
VectorSupport int8
ConstructParams []idxParam
SearchParams []idxParam
Expand Down Expand Up @@ -329,6 +335,7 @@ func main() {
{
IdxName: "Flat",
IdxType: entity.Flat,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{},
ValidExamples: []string{
Expand All @@ -344,6 +351,7 @@ func main() {
{
IdxName: "BinFlat",
IdxType: entity.BinFlat,
FieldName: "vec_field",
VectorSupport: int8(binaryVectorSupport),
ConstructParams: []idxParam{
{
Expand Down Expand Up @@ -374,8 +382,9 @@ func main() {
},
// IVF_FLAT
{
IdxName: "IvfFlat",
IdxType: entity.IvfFlat,
IdxName: "IvfFlat",
IdxType: entity.IvfFlat,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -407,6 +416,7 @@ func main() {
{
IdxName: "BinIvfFlat",
IdxType: entity.BinIvfFlat,
FieldName: "vec_field",
VectorSupport: int8(binaryVectorSupport),
ConstructParams: []idxParam{
{
Expand Down Expand Up @@ -437,8 +447,9 @@ func main() {
},
// IVF_SQ8
{
IdxName: "IvfSQ8",
IdxType: entity.IvfSQ8,
IdxName: "IvfSQ8",
IdxType: entity.IvfSQ8,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -468,8 +479,9 @@ func main() {
},
// IVF_PQ
{
IdxName: "IvfPQ",
IdxType: entity.IvfPQ,
IdxName: "IvfPQ",
IdxType: entity.IvfPQ,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -509,8 +521,9 @@ func main() {
},
// HNSW
{
IdxName: "HNSW",
IdxType: entity.HNSW,
IdxName: "HNSW",
IdxType: entity.HNSW,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "M",
Expand Down Expand Up @@ -546,8 +559,9 @@ func main() {
},
// IVF_HNSW
{
IdxName: "IvfHNSW",
IdxType: entity.IvfHNSW,
IdxName: "IvfHNSW",
IdxType: entity.IvfHNSW,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -596,6 +610,7 @@ func main() {
{
IdxName: "DISKANN",
IdxType: entity.DISKANN,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{
{
Expand All @@ -618,6 +633,7 @@ func main() {
{
IdxName: "AUTOINDEX",
IdxType: entity.AUTOINDEX,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{
{
Expand All @@ -639,8 +655,9 @@ func main() {
},
},
{
IdxName: "GPUIvfFlat",
IdxType: entity.GPUIvfFlat,
IdxName: "GPUIvfFlat",
IdxType: entity.GPUIvfFlat,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -669,8 +686,9 @@ func main() {
},
},
{
IdxName: "GPUIvfPQ",
IdxType: entity.GPUIvfPQ,
IdxName: "GPUIvfPQ",
IdxType: entity.GPUIvfPQ,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -709,8 +727,9 @@ func main() {
},
},
{
IdxName: "SCANN",
IdxType: entity.IvfFlat,
IdxName: "SCANN",
IdxType: entity.IvfFlat,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down
18 changes: 13 additions & 5 deletions entity/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Index interface {
Name() string
IndexType() IndexType
Params() map[string]string
FieldName() string
}

// SearchParam interface for index related search param
Expand Down Expand Up @@ -104,8 +105,9 @@ func newBaseSearchParams() baseSearchParams {
}

type baseIndex struct {
it IndexType
name string
it IndexType
name string
fieldName string
}

// Name implements Index
Expand All @@ -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 {
Expand All @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion entity/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading

0 comments on commit 1197006

Please sign in to comment.