Skip to content

Commit

Permalink
index field name
Browse files Browse the repository at this point in the history
  • Loading branch information
wayblink committed Feb 14, 2023
1 parent 08d3b97 commit 6486d64
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 408 deletions.
3 changes: 2 additions & 1 deletion client/client_grpc_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,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
42 changes: 30 additions & 12 deletions entity/genidx/genidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func(i *Index{{.IdxName}}) IndexType() IndexType {
return IndexType("{{.IdxType}}")
}
// FieldName returns FieldName, implementing Index interface
func(i *Index{{.IdxName}}) FieldName() string {
return "{{.FieldName}}"
}
// SupportBinary returns whether index type support binary vector
func(i *Index{{.IdxName}}) SupportBinary() bool {
return {{.VectorSupport}} & 2 > 0
Expand Down Expand Up @@ -225,6 +230,7 @@ func TestIndex{{.IdxName}}SearchParam(t *testing.T) {
type idxDef struct {
IdxName string
IdxType entity.IndexType
FieldName string
VectorSupport int8
ConstructParams []idxParam
SearchParams []idxParam
Expand Down Expand Up @@ -333,6 +339,7 @@ func main() {
{
IdxName: "Flat",
IdxType: entity.Flat,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{},
ValidExamples: []string{
Expand All @@ -348,6 +355,7 @@ func main() {
{
IdxName: "BinFlat",
IdxType: entity.BinFlat,
FieldName: "vec_field",
VectorSupport: int8(binaryVectorSupport),
ConstructParams: []idxParam{
{
Expand Down Expand Up @@ -378,8 +386,9 @@ func main() {
},
// IVF_FLAT
{
IdxName: "IvfFlat",
IdxType: entity.IvfFlat,
IdxName: "IvfFlat",
IdxType: entity.IvfFlat,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -411,6 +420,7 @@ func main() {
{
IdxName: "BinIvfFlat",
IdxType: entity.BinIvfFlat,
FieldName: "vec_field",
VectorSupport: int8(binaryVectorSupport),
ConstructParams: []idxParam{
{
Expand Down Expand Up @@ -441,8 +451,9 @@ func main() {
},
// IVF_SQ8
{
IdxName: "IvfSQ8",
IdxType: entity.IvfSQ8,
IdxName: "IvfSQ8",
IdxType: entity.IvfSQ8,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -472,8 +483,9 @@ func main() {
},
// IVF_PQ
{
IdxName: "IvfPQ",
IdxType: entity.IvfPQ,
IdxName: "IvfPQ",
IdxType: entity.IvfPQ,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -513,8 +525,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 @@ -550,8 +563,9 @@ func main() {
},
// IVF_HNSW
{
IdxName: "IvfHNSW",
IdxType: entity.IvfHNSW,
IdxName: "IvfHNSW",
IdxType: entity.IvfHNSW,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "nlist",
Expand Down Expand Up @@ -599,8 +613,9 @@ func main() {
},
// ANNOY
{
IdxName: "ANNOY",
IdxType: entity.ANNOY,
IdxName: "ANNOY",
IdxType: entity.ANNOY,
FieldName: "vec_field",
ConstructParams: []idxParam{
{
Name: "n_trees",
Expand Down Expand Up @@ -628,6 +643,7 @@ func main() {
{
IdxName: "DISKANN",
IdxType: entity.DISKANN,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{
{
Expand All @@ -650,6 +666,7 @@ func main() {
{
IdxName: "AUTOINDEX",
IdxType: entity.AUTOINDEX,
FieldName: "vec_field",
ConstructParams: []idxParam{},
SearchParams: []idxParam{
{
Expand All @@ -673,6 +690,7 @@ func main() {
{
IdxName: "TRIE",
IdxType: entity.TRIE,
FieldName: "varchar_field",
ConstructParams: []idxParam{},
},
},
Expand Down
20 changes: 14 additions & 6 deletions entity/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
ANNOY IndexType = "ANNOY"
AUTOINDEX IndexType = "AUTOINDEX"
DISKANN IndexType = "DISKANN"
TRIE IndexType = "TRIE"
TRIE IndexType = "TRIE"
)

// Metric Constants
Expand All @@ -62,6 +62,7 @@ type Index interface {
Name() string
IndexType() IndexType
Params() map[string]string
FieldName() string
}

// SearchParam interface for index related search param
Expand All @@ -71,8 +72,9 @@ type SearchParam interface {
}

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

// Name implements Index
Expand All @@ -85,6 +87,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 @@ -104,11 +111,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
Loading

0 comments on commit 6486d64

Please sign in to comment.