milvus

package
v0.7.43 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CallsBatchSize          = 500
	DumpBatchSize           = 10000
	MilvusConnectionTimeout = 5 * time.Second
	MilvusConnectionRetries = 40
	MaxSearchRetrievalCount = 16384
)

Global variables

Functions

func CreateCollection

func CreateCollection(schema *entity.Schema) (funcError error)

CreateCollection creates a collection in the Milvus DB.

Parameters:

  • schema: Schema of the collection to be created.

Returns:

  • error: Error if any issue occurs during creating the collection.

func CreateCustomSchema

func CreateCustomSchema(collectionName string, fields []SchemaField, description string) (*entity.Schema, error)

CreateCustomSchema function to generate a Milvus schema based on user input

func CreateIndexes

func CreateIndexes(collectionName string, milvusClient client.Client, guidFieldName string, denseVectorFieldName string, sparseVectorFieldName string) (funcError error)

CreateIndexes creates indexes for the Milvus DB. Firstly, a scalar index is created for the guid field. Secondly, a vector index is created for the embeddings field.

Parameters:

  • collectionName: Name of the collection to create the indexes for.
  • milvusClient: Milvus client.

Returns:

  • error: Error if any issue occurs during creating the indexes.

func Initialize

func Initialize() (milvusClient client.Client, funcError error)

Initialize initializes the Milvus DB. The function first creates a Milvus client, then creates a collection with the specified name, creates indexes on the collection, and loads the collection.

Parameters:

  • collectionName: Name of the collection to be initialized.

Returns:

  • error: Error if any issue occurs during initializing the Milvus DB.

func InsertData

func InsertData(collectionName string, dataToSend []interface{}, objectFieldName string, idFieldName string) (funcError error)

InsertData sends data to the Milvus DB in order to populate the vector database. The function sends the data in batches of const "CallsBatchSize" entries. The data is sent via HTTP POST requests.

Parameters:

  • collectionName: Name of the collection to send the data to.
  • dataToSend: Data to be sent to the Milvus DB.
  • objectFieldName: Name of the field in the data go object to be used as the object field.
  • idFieldName: Name of the field in the milvus schema to be used as the ID field.

Returns:

  • error: Error if any issue occurs during sending the data to the Milvus DB.

func QueryDuplicates added in v0.7.30

func QueryDuplicates(collectionName string, data []interface{}, objectFieldName string, idFieldName string) (duplicatedEntriesId [][]int64, funcError error)

QueryDuplicates queries the Milvus database for the provided data and retrieves the duplicates.

Parameters:

  • collectionName: Name of the collection in the Milvus database.
  • data: Data to send to the Milvus database.
  • objectFieldName: Name of the field in the data go object to be used as the object field.
  • idFieldName: Name of the field in the milvus schema to be used as the ID field.

Returns:

  • removedData: Data that was removed from the Milvus database.
  • error: Error if any issue occurs during querying the Milvus database.

func RemoveDuplicates added in v0.7.30

func RemoveDuplicates(collectionName string, dataIds []int64) (deleteCount int, funcError error)

RemoveDuplicates removes duplicates from the Milvus database.

Parameters:

  • collectionName: Name of the collection in the Milvus database.
  • dataIds: IDs of the data to remove from the Milvus database.

Returns:

  • deleteCount: Number of entries removed from the Milvus database.
  • error: Error if any issue occurs during querying the Milvus database.

Types

type ArrayFilter added in v0.7.27

type ArrayFilter struct {
	NeedAll    bool     `json:"needAll"`
	FilterData []string `json:"filterData"`
}

type AutoIdFlex

type AutoIdFlex int64

type JsonFilter added in v0.7.27

type JsonFilter struct {
	FieldName  string   `json:"fieldName"`
	FieldType  string   `json:"fieldType" description:"Can be either string or array."` // "string" or "array"
	FilterData []string `json:"filterData"`
	NeedAll    bool     `json:"needAll" description:"Only needed if the FieldType is array."` // only needed for array fields
}

type MilvusDeleteData added in v0.7.27

type MilvusDeleteData struct {
	DeleteCount int `json:"deleteCount"`
}

type MilvusDeleteResponse added in v0.7.27

type MilvusDeleteResponse struct {
	Code    int              `json:"code"`
	Data    MilvusDeleteData `json:"data"`
	Message string           `json:"message"`
}

type MilvusInsertData

type MilvusInsertData struct {
	InsertCount int `json:"insertCount"`
}

type MilvusInsertResponse

type MilvusInsertResponse struct {
	Code       int              `json:"code"`
	Message    string           `json:"message"`
	InsertData MilvusInsertData `json:"data"`
}

type MilvusQueryResponse

type MilvusQueryResponse struct {
	Code    int           `json:"code"`
	Message string        `json:"message"`
	Data    []interface{} `json:"data"`
}

func Query added in v0.7.27

func Query(collectionName string, responseLimit int, outputFields []string, filterExpression string) (response MilvusQueryResponse, funcError error)

Query queries the Milvus database.

This function queries the Milvus database with an HTTP POST request.

Parameters:

  • collectionName: Name of the collection to query.
  • responseLimit: Maximum number of responses.
  • outputFields: Fields to return in the response.
  • filterExpression: Filters to apply to the query.

Returns:

  • response: Response from the Milvus database.
  • error: Error if any issue occurs while querying the Milvus database.

type MilvusRequest

type MilvusRequest struct {
	// Common fields
	CollectionName string `json:"collectionName"`

	// Insert request
	Data []interface{} `json:"data,omitempty"`

	// Search and Query request
	OutputFields []string `json:"outputFields,omitempty"`
	Filter       *string  `json:"filter,omitempty"`
	Limit        *int     `json:"limit,omitempty"`
	Offset       *int     `json:"offset,omitempty"`

	// Search request
	DenseVector  []float32        `json:"dense_vector,omitempty"`
	SparseVector map[uint]float32 `json:"sparse_vector,omitempty"`

	// Delete entry request
	AutoIds []AutoIdFlex `json:"id,omitempty"`
}

type MilvusSearchResponse

type MilvusSearchResponse struct {
	Code       int           `json:"code"`
	Message    string        `json:"message"`
	SearchData []interface{} `json:"data"`
}

type SchemaField

type SchemaField struct {
	Name        string
	Type        string
	PrimaryKey  bool
	AutoID      bool
	Dimension   int
	Description string
}

Jump to

Keyboard shortcuts

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