Class: Milvus::Collections

Inherits:
Base
  • Object
show all
Defined in:
lib/milvus/collections.rb

Constant Summary collapse

PATH =
"collections"

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Milvus::Base

Instance Method Details

#create(collection_name:, auto_id:, fields:) ⇒ Hash

Create a Collection

Parameters:

  • collection_name (String)

    The name of the collection to create.

  • auto_id (Boolean)

    Whether to automatically generate IDs for the collection.

  • description (String)

    A description of the collection.

  • fields (Array<Hash>)

    The fields of the collection.

Returns:

  • (Hash)

    Server response



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/milvus/collections.rb', line 55

def create(
  collection_name:,
  auto_id:,
  fields:
)
  response = client.connection.post("#{PATH}/create") do |req|
    req.body = {
      collectionName: collection_name,
      schema: {
        autoId: auto_id,
        fields: fields,
        name: collection_name # This duplicated field is kept for historical reasons.
      }
    }
  end
  response.body.empty? ? true : response.body
end

#describe(collection_name:) ⇒ Hash

Describes the details of a collection.

Parameters:

  • collection_name (String)

    The name of the collection to describe.

Returns:

  • (Hash)

    Server response



77
78
79
80
81
82
83
84
# File 'lib/milvus/collections.rb', line 77

def describe(collection_name:)
  response = client.connection.post("#{PATH}/describe") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body
end

#drop(collection_name:) ⇒ Hash

This operation drops the current collection and all data within the collection.

Parameters:

  • collection_name (String)

    The name of the collection to drop.

Returns:

  • (Hash)

    Server response



100
101
102
103
104
105
106
107
# File 'lib/milvus/collections.rb', line 100

def drop(collection_name:)
  response = client.connection.post("#{PATH}/drop") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body.empty? ? true : response.body
end

#get_load_state(collection_name:) ⇒ Hash

This operation returns the load status of a specific collection.

Parameters:

  • collection_name (String)

    The name of the collection to get the load status of.

Returns:

  • (Hash)

    Server response



126
127
128
129
130
131
132
133
# File 'lib/milvus/collections.rb', line 126

def get_load_state(collection_name:)
  response = client.connection.post("#{PATH}/get_load_state") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body
end

#get_stats(collection_name:) ⇒ Hash

This operation gets the number of entities in a collection.

Parameters:

  • collection_name (String)

    The name of the collection to get the count of.

Returns:

  • (Hash)

    Server response



39
40
41
42
43
44
45
46
# File 'lib/milvus/collections.rb', line 39

def get_stats(collection_name:)
  response = client.connection.post("#{PATH}/get_stats") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body
end

#has(collection_name:) ⇒ Hash

This operation checks whether a collection exists.

Parameters:

  • collection_name (String)

    The name of the collection to check.

Returns:

  • (Hash)

    Server response



11
12
13
14
15
16
17
18
# File 'lib/milvus/collections.rb', line 11

def has(collection_name:)
  response = client.connection.post("#{PATH}/has") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body
end

#listHash

This operation lists all collections in the specified database.

Returns:

  • (Hash)

    Server response



89
90
91
92
93
94
# File 'lib/milvus/collections.rb', line 89

def list
  response = client.connection.post("#{PATH}/list") do |req|
    req.body = {}
  end
  response.body
end

#load(collection_name:) ⇒ Hash

Load the collection to memory before a search or a query

Parameters:

  • collection_name (String)

    The name of the collection to load.

Returns:

  • (Hash)

    Server response



113
114
115
116
117
118
119
120
# File 'lib/milvus/collections.rb', line 113

def load(collection_name:)
  response = client.connection.post("#{PATH}/load") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body.empty? ? true : response.body
end

#release(collection_name:) ⇒ Hash

Release a collection from memory after a search or a query to reduce memory usage

Parameters:

  • collection_name (String)

    The name of the collection to release.

Returns:

  • (Hash)

    Server response



139
140
141
142
143
144
145
146
# File 'lib/milvus/collections.rb', line 139

def release(collection_name:)
  response = client.connection.post("#{PATH}/release") do |req|
    req.body = {
      collectionName: collection_name
    }
  end
  response.body.empty? ? true : response.body
end

#rename(collection_name:, new_collection_name:) ⇒ Hash

This operation renames an existing collection and optionally moves the collection to a new database.

Parameters:

  • collection_name (String)

    The name of the collection to rename.

  • new_collection_name (String)

    The new name of the collection.

Returns:

  • (Hash)

    Server response



25
26
27
28
29
30
31
32
33
# File 'lib/milvus/collections.rb', line 25

def rename(collection_name:, new_collection_name:)
  response = client.connection.post("#{PATH}/rename") do |req|
    req.body = {
      collectionName: collection_name,
      newCollectionName: new_collection_name
    }
  end
  response.body.empty? ? true : response.body
end