common

package
v2.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultIntFieldName         = "int64"
	DefaultInt8FieldName        = "int8"
	DefaultInt16FieldName       = "int16"
	DefaultInt32FieldName       = "int32"
	DefaultBoolFieldName        = "bool"
	DefaultFloatFieldName       = "float"
	DefaultDoubleFieldName      = "double"
	DefaultVarcharFieldName     = "varchar"
	DefaultJSONFieldName        = "json"
	DefaultArrayFieldName       = "array"
	DefaultFloatVecFieldName    = "floatVec"
	DefaultBinaryVecFieldName   = "binaryVec"
	DefaultFloat16VecFieldName  = "fp16Vec"
	DefaultBFloat16VecFieldName = "bf16Vec"
	DefaultSparseVecFieldName   = "sparseVec"
	DefaultDynamicNumberField   = "dynamicNumber"
	DefaultDynamicStringField   = "dynamicString"
	DefaultDynamicBoolField     = "dynamicBool"
	DefaultDynamicListField     = "dynamicList"
	DefaultBoolArrayField       = "boolArray"
	DefaultInt8ArrayField       = "int8Array"
	DefaultInt16ArrayField      = "int16Array"
	DefaultInt32ArrayField      = "int32Array"
	DefaultInt64ArrayField      = "int64Array"
	DefaultFloatArrayField      = "floatArray"
	DefaultDoubleArrayField     = "doubleArray"
	DefaultVarcharArrayField    = "varcharArray"
	RowCount                    = "row_count"
	DefaultTimeout              = 120
	DefaultDim                  = int64(128)
	DefaultShards               = int32(2)
	DefaultNb                   = 3000
	DefaultNq                   = 5
	//DefaultNq    = 1
	DefaultTopK  = 10
	TestCapacity = 100 // default array field capacity
	TestMaxLen   = 100 // default varchar field max length
)

const default value for test

View Source
const (
	MaxPartitionNum         = 1024
	DefaultDynamicFieldName = "$meta"
	QueryCountFieldName     = "count(*)"
	DefaultPartition        = "_default"
	DefaultIndexName        = "_default_idx_102"
	DefaultIndexNameBinary  = "_default_idx_100"
	DefaultRgName           = "__default_resource_group"
	DefaultDb               = "default"
	DefaultConsistencyLevel = entity.ClBounded
	MaxDim                  = 32768
	MaxLength               = int64(65535)
	MaxCollectionNameLen    = 255
	DefaultRgCapacity       = 1000000
	RetentionDuration       = 40   // common.retentionDuration
	MaxCapacity             = 4096 // max array capacity
	DefaultPartitionNum     = 16   // default num_partitions
	MaxTopK                 = 16384
	MaxVectorFieldNum       = 4
	DefaultBatchSize        = 1000
)

const default value from milvus

Variables

View Source
var IndexStateValue = map[string]int32{
	"IndexStateNone": 0,
	"Unissued":       1,
	"InProgress":     2,
	"Finished":       3,
	"Failed":         4,
	"Retry":          5,
}
View Source
var InvalidExpressions = []InvalidExprStruct{

	{Expr: "id in [0]", ErrNil: true, ErrMsg: "fieldName(id) not found"},
	{Expr: "int64 in not [0]", ErrNil: false, ErrMsg: "cannot parse expression"},
	{Expr: "int64 > 10 AND int64 < 100", ErrNil: false, ErrMsg: "cannot parse expression"},
	{Expr: "int64 < 10 OR int64 > 100", ErrNil: false, ErrMsg: "cannot parse expression"},
	{Expr: "int64 < floatVec", ErrNil: false, ErrMsg: "not supported"},
	{Expr: "floatVec in [0]", ErrNil: false, ErrMsg: "cannot be casted to FloatVector"},
	{Expr: fmt.Sprintf("%s == 1", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s like 'a%%' ", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s like `a%%` ", DefaultJSONFieldName), ErrNil: false, ErrMsg: "cannot parse expression"},
	{Expr: fmt.Sprintf("%s > 1", DefaultDynamicFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s[\"dynamicList\"] == [2, 3]", DefaultDynamicFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s['a'] == [2, 3]", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s['number'] == [2, 3]", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("%s[0] == [2, 3]", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("json_contains (%s['number'], 2)", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("json_contains (%s['list'], [2])", DefaultJSONFieldName), ErrNil: true, ErrMsg: ""},
	{Expr: fmt.Sprintf("json_contains_all (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "contains_all operation element must be an array"},
	{Expr: fmt.Sprintf("JSON_CONTAINS_ANY (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "contains_any operation element must be an array"},
	{Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"},
	{Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"},
	{Expr: fmt.Sprintf("%s[-1] > %d", DefaultInt8ArrayField, TestCapacity), ErrNil: false, ErrMsg: "cannot parse expression"},
	{Expr: fmt.Sprintf(fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName)), ErrNil: false, ErrMsg: "invalid expression"},
}
View Source
var SupportBinIvfFlatMetricType = []entity.MetricType{
	entity.JACCARD,
	entity.HAMMING,
}
View Source
var SupportFloatMetricType = []entity.MetricType{
	entity.L2,
	entity.IP,
	entity.COSINE,
}

--- index utils ---

Functions

func CheckCollection

func CheckCollection(t *testing.T, actualCollection *entity.Collection, expCollName string, expShardNum int32,
	expSchema *entity.Schema, expConsistencyLevel entity.ConsistencyLevel)

CheckCollection check collection

func CheckContainsCollection

func CheckContainsCollection(t *testing.T, collections []*entity.Collection, collName string)

CheckContainsCollection check collections contains collName

func CheckContainsDb added in v2.2.5

func CheckContainsDb(t *testing.T, dbs []entity.Database, dbName string)

CheckContainsDb check collections contains collName

func CheckContainsValue added in v2.4.2

func CheckContainsValue(fieldNames []interface{}, fieldName interface{}) bool

Checks whether the list contains the specified value

func CheckErr

func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...string)

CheckErr check err and errMsg

func CheckIndexResult added in v2.2.1

func CheckIndexResult(t *testing.T, actualIndexes []entity.Index, expIndexes ...entity.Index)

CheckIndexResult check index result, index type, metric type, index params

func CheckInsertResult

func CheckInsertResult(t *testing.T, actualIds entity.Column, expIds entity.Column)

CheckInsertResult check insert result, ids len (insert count), ids data (pks, but no auto ids)

func CheckNotContainsCollection added in v2.2.5

func CheckNotContainsCollection(t *testing.T, collections []*entity.Collection, collName string)

CheckNotContainsCollection check collections not contains collName

func CheckNotContainsDb added in v2.2.5

func CheckNotContainsDb(t *testing.T, dbs []entity.Database, dbName string)

CheckNotContainsDb check collections contains collName

func CheckOutputFields

func CheckOutputFields(t *testing.T, actualColumns []entity.Column, expFields []string)

CheckOutputFields check query output fields

func CheckPersistentSegments added in v2.2.1

func CheckPersistentSegments(t *testing.T, actualSegments []*entity.Segment, expNb int64)

CheckPersistentSegments check persistent segments

func CheckQueryIteratorResult added in v2.4.1

func CheckQueryIteratorResult(ctx context.Context, t *testing.T, itr *client.QueryIterator, expLimit int, opts ...CheckIteratorOption)

check queryIterator: result limit, each batch size, output fields

func CheckQueryResult

func CheckQueryResult(t *testing.T, actualColumns []entity.Column, expColumns []entity.Column)

CheckQueryResult check query result, column name, type and field

func CheckResourceGroup added in v2.2.2

func CheckResourceGroup(t *testing.T, actualRg *entity.ResourceGroup, expRg *entity.ResourceGroup)

func CheckSearchResult

func CheckSearchResult(t *testing.T, actualSearchResults []client.SearchResult, expNq int, expTopK int)

CheckSearchResult check search result, check nq, topk, ids, score

func ColumnIndexFunc added in v2.3.3

func ColumnIndexFunc(data []entity.Column, fieldName string) int

ColumnIndexFunc generate column index

func EqualArrayColumn added in v2.4.1

func EqualArrayColumn(t *testing.T, columnA entity.Column, columnB entity.Column)

EqualColumn assert field data is equal of two columns

func EqualColumn

func EqualColumn(t *testing.T, columnA entity.Column, columnB entity.Column)

EqualColumn assert field data is equal of two columns

func EqualFields

func EqualFields(t *testing.T, fieldA *entity.Field, fieldB *entity.Field)

EqualFields equal two fields

func EqualIntSlice added in v2.4.1

func EqualIntSlice(a []int, b []int) bool

func EqualSchema

func EqualSchema(t *testing.T, schemaA entity.Schema, schemaB entity.Schema)

EqualSchema equal two schemas

func GenAllArrayData added in v2.3.3

func GenAllArrayData(start int, nb int, opts ...GenColumnDataOption) []entity.Column

func GenAllArrayFields added in v2.3.3

func GenAllArrayFields() []*entity.Field

func GenAllArrayFieldsWithCapacity added in v2.3.3

func GenAllArrayFieldsWithCapacity(capacity int64) []*entity.Field

GenAllArrayFieldsWithCapacity GenAllArrayFields gen all array fields

func GenAllFields

func GenAllFields() []*entity.Field

GenAllFields gen fields with all scala field types

func GenAllFieldsData added in v2.2.7

func GenAllFieldsData(start int, nb int, dim int64, opts ...GenColumnDataOption) []entity.Column

func GenAllFieldsRows added in v2.2.7

func GenAllFieldsRows(start int, nb int, dim int64, enableDynamicField bool, opts ...GenColumnDataOption) []interface{}

func GenAllFloatIndex added in v2.2.1

func GenAllFloatIndex(metricTypes ...entity.MetricType) []entity.Index

GenAllFloatIndex gen all float vector index

func GenAllVectorsData added in v2.4.0

func GenAllVectorsData(start int, nb int, dim int64, opts ...GenColumnDataOption) []entity.Column

func GenAllVectorsRows added in v2.4.0

func GenAllVectorsRows(start int, nb int, dim int64, enableDynamicField bool) []interface{}

func GenArrayColumnData added in v2.3.3

func GenArrayColumnData(start int, nb int, fieldName string, opts ...GenColumnDataOption) entity.Column

func GenBFloat16Vector added in v2.4.0

func GenBFloat16Vector(dim int64) []byte

func GenBatchSizes added in v2.4.1

func GenBatchSizes(limit int, batch int) []int

func GenBinaryVector

func GenBinaryVector(dim int64) []byte

func GenColumnData added in v2.2.7

func GenColumnData(start int, nb int, fieldType entity.FieldType, fieldName string, opts ...GenColumnDataOption) entity.Column

GenColumnData GenColumnDataOption

func GenDefaultArrayRows added in v2.3.3

func GenDefaultArrayRows(start int, nb int, dim int64, enableDynamicField bool, opts ...GenColumnDataOption) []interface{}

func GenDefaultBinaryData

func GenDefaultBinaryData(start int, nb int, dim int64) (entity.Column, entity.Column, entity.Column)

GenDefaultBinaryData gen default binary collection data

func GenDefaultBinaryFields

func GenDefaultBinaryFields(autoID bool, dim int64) []*entity.Field

GenDefaultBinaryFields gen default binary fields with int64, float, binaryVector field

func GenDefaultBinaryRows added in v2.2.7

func GenDefaultBinaryRows(start int, nb int, dim int64, enableDynamicField bool) []interface{}

func GenDefaultColumnData

func GenDefaultColumnData(start int, nb int, dim int64) (entity.Column, entity.Column, entity.Column)

GenDefaultColumnData gen default column with data

func GenDefaultFields

func GenDefaultFields(autoID bool) []*entity.Field

GenDefaultFields gen default fields with int64, float, floatVector field

func GenDefaultJSONData added in v2.2.7

func GenDefaultJSONData(columnName string, start int, nb int) *entity.ColumnJSONBytes

GenDefaultJSONData gen default column with data

func GenDefaultJSONRows added in v2.2.7

func GenDefaultJSONRows(start int, nb int, dim int64, enableDynamicField bool) []interface{}

func GenDefaultRows added in v2.2.7

func GenDefaultRows(start int, nb int, dim int64, enableDynamicField bool) []interface{}

func GenDefaultSparseRows added in v2.4.0

func GenDefaultSparseRows(start int, nb int, dim int64, maxLenSparse int, enableDynamicField bool) []interface{}

func GenDefaultVarcharData added in v2.2.1

func GenDefaultVarcharData(start int, nb int, dim int64) (entity.Column, entity.Column)

func GenDefaultVarcharFields

func GenDefaultVarcharFields(autoID bool) []*entity.Field

GenDefaultVarcharFields gen default fields with varchar, floatVector field

func GenDefaultVarcharRows added in v2.2.7

func GenDefaultVarcharRows(start int, nb int, dim int64, enableDynamicField bool) []interface{}

func GenDynamicFieldData added in v2.2.7

func GenDynamicFieldData(start int, nb int) []entity.Column

func GenField added in v2.2.7

func GenField(name string, fieldType entity.FieldType, opts ...CreateFieldOption) *entity.Field

func GenFloat16Vector added in v2.4.0

func GenFloat16Vector(dim int64) []byte

func GenFloatVector

func GenFloatVector(dim int64) []float32

func GenLongString

func GenLongString(n int) string

GenLongString gen invalid long string

func GenRandomString

func GenRandomString(n int) string

GenRandomString gen random string

func GenSchema

func GenSchema(name string, autoID bool, fields []*entity.Field, opts ...CreateSchemaOption) *entity.Schema

GenSchema gen schema

func GenSearchVectors

func GenSearchVectors(nq int, dim int64, dataType entity.FieldType) []entity.Vector

GenSearchVectors gen search vectors

func GenSparseVector added in v2.4.0

func GenSparseVector(maxLen int) entity.SparseEmbedding

func GetAllFieldsName added in v2.4.0

func GetAllFieldsName(enableDynamicField bool, onlyScalar bool) []string

return all fields name

func GetInt64FloatVecArrayFieldsName added in v2.4.2

func GetInt64FloatVecArrayFieldsName(enableDynamicField bool) []string

func MergeColumnsToDynamic added in v2.2.7

func MergeColumnsToDynamic(nb int, columns []entity.Column, columnName string) *entity.ColumnJSONBytes

func PrintAllFieldNames added in v2.4.2

func PrintAllFieldNames(collName string, schemas *entity.Schema)

Types

type Array added in v2.3.3

type Array struct {
	BoolArray    []bool    `json:"boolArray" milvus:"name:boolArray"`
	Int8Array    []int8    `json:"int8Array" milvus:"name:int8Array"`
	Int16Array   []int16   `json:"int16Array" milvus:"name:int16Array"`
	Int32Array   []int32   `json:"int32Array" milvus:"name:int32Array"`
	Int64Array   []int64   `json:"int64Array" milvus:"name:int64Array"`
	FloatArray   []float32 `json:"floatArray" milvus:"name:floatArray"`
	DoubleArray  []float64 `json:"doubleArray" milvus:"name:doubleArray"`
	VarcharArray [][]byte  `json:"varcharArray" milvus:"name:varcharArray"`
}

func GenAllArrayRow added in v2.3.3

func GenAllArrayRow(index int, opts ...GenColumnDataOption) Array

type CheckIteratorOption added in v2.4.1

type CheckIteratorOption func(opt *checkIteratorOpt)

func WithExpBatchSize added in v2.4.1

func WithExpBatchSize(expBatchSize []int) CheckIteratorOption

func WithExpOutputFields added in v2.4.1

func WithExpOutputFields(expOutputFields []string) CheckIteratorOption

type CreateFieldOption added in v2.2.7

type CreateFieldOption func(field *entity.Field)

CreateFieldOption is an option that is used to modify entity.Schema

func WithAutoID added in v2.2.7

func WithAutoID(autoID bool) CreateFieldOption

func WithDim added in v2.2.7

func WithDim(dim int64) CreateFieldOption

func WithElementType added in v2.3.3

func WithElementType(eleType entity.FieldType) CreateFieldOption

func WithFieldDescription added in v2.2.7

func WithFieldDescription(desc string) CreateFieldOption

func WithIsPartitionKey added in v2.2.7

func WithIsPartitionKey(isPartitionKey bool) CreateFieldOption

func WithIsPrimaryKey added in v2.2.7

func WithIsPrimaryKey(isPrimaryKey bool) CreateFieldOption

func WithMaxCapacity added in v2.3.3

func WithMaxCapacity(maxCap int64) CreateFieldOption

func WithMaxLength added in v2.2.7

func WithMaxLength(maxLen int64) CreateFieldOption

func WithTypeParams added in v2.2.7

func WithTypeParams(key string, value string) CreateFieldOption

type CreateSchemaOption added in v2.2.7

type CreateSchemaOption func(schema *entity.Schema)

CreateSchemaOption is an option that is used to modify entity.Schema

func WithDescription added in v2.2.7

func WithDescription(desc string) CreateSchemaOption

func WithEnableDynamicField added in v2.2.7

func WithEnableDynamicField(enableDF bool) CreateSchemaOption

type Dynamic added in v2.2.7

type Dynamic struct {
	Number int32   `json:"dynamicNumber" milvus:"name:dynamicNumber"`
	String string  `json:"dynamicString" milvus:"name:dynamicString"`
	Bool   bool    `json:"dynamicBool" milvus:"name:dynamicBool"`
	List   []int64 `json:"dynamicList" milvus:"name:dynamicList"`
}

type GenColumnDataOption added in v2.2.7

type GenColumnDataOption func(opt *genDataOpt)

GenColumnDataOption -- create column data --

func WithArrayCapacity added in v2.3.3

func WithArrayCapacity(capacity int64) GenColumnDataOption

func WithArrayElementType added in v2.3.3

func WithArrayElementType(eleType entity.FieldType) GenColumnDataOption

func WithSparseVectorLen added in v2.4.0

func WithSparseVectorLen(length int) GenColumnDataOption

func WithVectorDim added in v2.2.7

func WithVectorDim(dim int64) GenColumnDataOption

type InvalidExprStruct added in v2.3.2

type InvalidExprStruct struct {
	Expr   string
	ErrNil bool
	ErrMsg string
}

InvalidExprStruct invalid expr

type JSONStruct added in v2.4.0

type JSONStruct struct {
	Number int32   `json:"number" milvus:"name:number"`
	String string  `json:"string" milvus:"name:string"`
	Bool   bool    `json:"bool" milvus:"name:bool"`
	List   []int64 `json:"list" milvus:"name:list"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL