Class: Milvus::Entities

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

Constant Summary collapse

PATH =
"entities"

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

#delete(collection_name:, filter:) ⇒ Hash

This operation deletes entities by their IDs or with a boolean expression.

Parameters:

  • collection_name (String)

    The name of the collection to delete entities from.

  • filter (String)

    The filter to use to delete entities.

Returns:

  • (Hash)

    The response from the server.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/milvus/entities.rb', line 34

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

#get(collection_name:, id:, output_fields: nil) ⇒ Hash

This operation gets specific entities by their IDs

Parameters:

  • collection_name (String)

    The name of the collection to get entities from.

  • id (Array<Integer>)

    The IDs of the entities to get.

  • output_fields (Array<String>) (defaults to: nil)

    The fields to return in the results.

Returns:

  • (Hash)

    The response from the server.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/milvus/entities.rb', line 97

def get(
  collection_name:,
  id:,
  output_fields: nil
)
  response = client.connection.post("#{PATH}/get") do |req|
    req.body = {
      collectionName: collection_name,
      id: id
    }
    req.body[:outputFields] = output_fields if output_fields
  end
  response.body.empty? ? true : response.body
end

#hybrid_search(collection_name:, search:, rerank:, limit: nil, output_fields: []) ⇒ Hash

Executes a hybrid search.

Parameters:

  • collection_name (String)

    The name of the collection to search.

  • data (Array<Hash>)

    The data to search for.

  • rerank (Hash)

    The rerank parameters.

  • limit (Integer) (defaults to: nil)

    The maximum number of results to return.

  • output_fields (Array<String>) (defaults to: [])

    The fields to return in the results.

Returns:

  • (Hash)

    The search results.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/milvus/entities.rb', line 161

def hybrid_search(
  collection_name:,
  search:,
  rerank:,
  limit: nil,
  output_fields: []
)
  response = client.connection.post("#{PATH}/hybrid_search") do |req|
    params = {
      collectionName: collection_name,
      search: search,
      rerank: rerank
    }
    params[:limit] = limit if limit
    params[:outputFields] = output_fields if output_fields.any?
    req.body = params
  end
  response.body.empty? ? true : response.body
end

#insert(collection_name:, data:, partition_name: nil) ⇒ Hash

This operation inserts data into a specific collection.

Parameters:

  • collection_name (String)

    The name of the collection to insert data into.

  • data (Array<Hash>)

    The data to insert.

  • partition_name (String) (defaults to: nil)

    The name of the partition to insert the data into.

Returns:

  • (Hash)

    The response from the server.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/milvus/entities.rb', line 14

def insert(
  collection_name:,
  data:,
  partition_name: nil
)
  response = client.connection.post("#{PATH}/insert") do |req|
    req.body = {
      collectionName: collection_name,
      data: data
    }
    req.body[:partitionName] = partition_name if partition_name
  end
  response.body.empty? ? true : response.body
end

#query(collection_name:, filter:, output_fields: [], limit: nil) ⇒ Object

This operation conducts a filtering on the scalar field with a specified boolean expression.

Parameters:

  • collection_name (String)

    The name of the collection to query.

  • filter (String)

    The filter to use to query the collection.

  • output_fields (Array<String>) (defaults to: [])

    The fields to return in the results.

  • limit (Integer) (defaults to: nil)

    The maximum number of results to return.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/milvus/entities.rb', line 53

def query(
  collection_name:,
  filter:,
  output_fields: [],
  limit: nil
)
  response = client.connection.post("#{PATH}/query") do |req|
    req.body = {
      collectionName: collection_name,
      filter: filter
    }
    req.body[:outputFields] = output_fields if output_fields
    req.body[:limit] = limit if limit
  end
  response.body.empty? ? true : response.body
end

#search(collection_name:, data:, anns_field:, filter: nil, limit: nil, offset: nil, grouping_field: nil, output_fields: [], search_params: {}, partition_names: []) ⇒ Hash

This operation conducts a vector similarity search with an optional scalar filtering expression.

Parameters:

  • collection_name (String)

    The name of the collection to search.

  • data (Array<Array<Float>>)

    The data to search for.

  • anns_field (String)

    The field to search for.

  • limit (Integer) (defaults to: nil)

    The maximum number of results to return.

  • output_fields (Array<String>) (defaults to: [])

    The fields to return in the results.

  • offset (Integer) (defaults to: nil)

    The offset to start from.

  • filter (String) (defaults to: nil)

    The filter to use to search the collection.

Returns:

  • (Hash)

    The search results.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/milvus/entities.rb', line 122

def search(
  collection_name:,
  data:,
  anns_field:,
  filter: nil,
  limit: nil,
  offset: nil,
  grouping_field: nil,
  output_fields: [],
  search_params: {},
  partition_names: []
)
  response = client.connection.post("#{PATH}/search") do |req|
    params = {
      collectionName: collection_name,
      data: data,
      annsField: anns_field
    }
    params[:limit] = limit if limit
    params[:outputFields] = output_fields if output_fields.any?
    params[:offset] = offset if offset
    params[:filter] = filter if filter
    params[:searchParams] = search_params if search_params.any?
    params[:partitionNames] = partition_names if partition_names.any?
    params[:groupingField] = groupingField if grouping_field

    req.body = params
  end
  response.body.empty? ? true : response.body
end

#upsert(collection_name:, data:, partition_name: nil) ⇒ Hash

This operation inserts new records into the database or updates existing ones.

Parameters:

  • collection_name (String)

    The name of the collection to upsert data into.

  • data (Array<Hash>)

    The data to upsert.

  • partition_name (String) (defaults to: nil)

    The name of the partition to upsert the data into.

Returns:

  • (Hash)

    The response from the server.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/milvus/entities.rb', line 76

def upsert(
  collection_name:,
  data:,
  partition_name: nil
)
  response = client.connection.post("#{PATH}/upsert") do |req|
    req.body = {
      collectionName: collection_name,
      data: data
    }
    req.body[:partitionName] = partition_name if partition_name
  end
  response.body.empty? ? true : response.body
end