milvus 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4910e3b8c5f02ed0a56dca251ec40f7f8033c3033e45d406faa90b4b56358029
4
+ data.tar.gz: 61460b9e1bc168e4dfec03bddc1f010d1df465ab5b0648eac38843ba666dcb76
5
+ SHA512:
6
+ metadata.gz: 12670da71fd1c578a8e040259218ac93c33fc15c8d5e27bd15fb39bbc168a397dd55a13dcce5387d76aac942131da65d22ff3cbc7a9147d2b5e761e9aef87861
7
+ data.tar.gz: 7e0614244bffe334bba059e59e981de0456f541a103f58df356754d5ff56546954d8c2d19d458b8cbb5ffd15817102bc6491f013823ed5498a94e6ce26c4d3a6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-04-20
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in milvus.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem "standard", "~> 1.27.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ milvus (0.9.0)
5
+ faraday (~> 2.7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.5.0)
14
+ faraday (2.7.4)
15
+ faraday-net_http (>= 2.0, < 3.1)
16
+ ruby2_keywords (>= 0.0.4)
17
+ faraday-net_http (3.0.2)
18
+ json (2.6.3)
19
+ language_server-protocol (3.17.0.3)
20
+ method_source (1.0.0)
21
+ parallel (1.23.0)
22
+ parser (3.2.2.0)
23
+ ast (~> 2.4.1)
24
+ pry (0.14.2)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ pry-byebug (3.10.1)
28
+ byebug (~> 11.0)
29
+ pry (>= 0.13, < 0.15)
30
+ rainbow (3.1.1)
31
+ rake (13.0.6)
32
+ regexp_parser (2.8.0)
33
+ rexml (3.2.5)
34
+ rspec (3.12.0)
35
+ rspec-core (~> 3.12.0)
36
+ rspec-expectations (~> 3.12.0)
37
+ rspec-mocks (~> 3.12.0)
38
+ rspec-core (3.12.1)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-expectations (3.12.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.12.0)
43
+ rspec-mocks (3.12.5)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-support (3.12.0)
47
+ rubocop (1.50.2)
48
+ json (~> 2.3)
49
+ parallel (~> 1.10)
50
+ parser (>= 3.2.0.0)
51
+ rainbow (>= 2.2.2, < 4.0)
52
+ regexp_parser (>= 1.8, < 3.0)
53
+ rexml (>= 3.2.5, < 4.0)
54
+ rubocop-ast (>= 1.28.0, < 2.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 2.4.0, < 3.0)
57
+ rubocop-ast (1.28.0)
58
+ parser (>= 3.2.1.0)
59
+ rubocop-performance (1.16.0)
60
+ rubocop (>= 1.7.0, < 2.0)
61
+ rubocop-ast (>= 0.4.0)
62
+ ruby-progressbar (1.13.0)
63
+ ruby2_keywords (0.0.5)
64
+ standard (1.27.0)
65
+ language_server-protocol (~> 3.17.0.2)
66
+ rubocop (~> 1.50.2)
67
+ rubocop-performance (~> 1.16.0)
68
+ unicode-display_width (2.4.2)
69
+
70
+ PLATFORMS
71
+ x86_64-darwin-19
72
+ x86_64-darwin-22
73
+ x86_64-linux
74
+
75
+ DEPENDENCIES
76
+ milvus!
77
+ pry-byebug (~> 3.10.0)
78
+ rake (~> 13.0)
79
+ rspec (~> 3.0)
80
+ standard (~> 1.27.0)
81
+
82
+ BUNDLED WITH
83
+ 2.4.0
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # Milvus
2
+
3
+ <p>
4
+ <img alt='Milvus logo' src='https://res.cloudinary.com/crunchbase-production/image/upload/c_lpad,f_auto,q_auto:eco,dpr_1/cqpyxcuzl6gwqjjwzamt' height='50' />
5
+ +&nbsp;&nbsp;
6
+ <img alt='Ruby logo' src='https://user-images.githubusercontent.com/541665/230231593-43861278-4550-421d-a543-fd3553aac4f6.png' height='40' />
7
+ </p>
8
+
9
+ Ruby wrapper for the Milvus vector search database API
10
+
11
+ ![Tests status](https://github.com/andreibondarev/milvus/actions/workflows/ci.yml/badge.svg) [![Gem Version](https://badge.fury.io/rb/milvus.svg)](https://badge.fury.io/rb/milvus)
12
+
13
+ ## Installation
14
+
15
+ Install the gem and add to the application's Gemfile by executing:
16
+
17
+ $ bundle add milvus
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by executing:
20
+
21
+ $ gem install milvus
22
+
23
+ ## Usage
24
+
25
+ ### Instantiating API client
26
+
27
+ ```ruby
28
+ require 'milvus'
29
+
30
+ client = Milvus::Client.new(
31
+ url: 'http://localhost:9091'
32
+ )
33
+ ```
34
+
35
+ ### Using the Collections endpoints
36
+
37
+ ```ruby
38
+ # Data types: "boolean", "int8", "int16", "int32", "int64", "float", "double", "string", "varchar", "binary_vector", "float_vector"
39
+
40
+ # Creating a new collection schema
41
+ client.collections.create(
42
+ collection_name: "book",
43
+ description: "Test book search",
44
+ auto_id: false,
45
+ fields: [
46
+ {
47
+ "name": "book_id",
48
+ "description": "book id",
49
+ "is_primary_key": true,
50
+ "autoID": false,
51
+ "data_type": Milvus::DATA_TYPES["int64"]
52
+ },
53
+ {
54
+ "name": "word_count",
55
+ "description": "count of words",
56
+ "is_primary_key": false,
57
+ "data_type": Milvus::DATA_TYPES["int64"]
58
+ },
59
+ {
60
+ "name": "book_intro",
61
+ "description": "embedded vector of book introduction",
62
+ "data_type": Milvus::DATA_TYPES["binary_vector"],
63
+ "is_primary_key": false,
64
+ "type_params": [
65
+ {
66
+ "key": "dim",
67
+ "value": "2"
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ )
73
+ ```
74
+ ```ruby
75
+ # Get the collection info
76
+ client.collections.get(collection_name: "book")
77
+ ```
78
+ ```ruby
79
+ # Delete the collection
80
+ client.collections.delete(collection_name: "book")
81
+ ```
82
+ ```ruby
83
+ # Load the collection to memory before a search or a query
84
+ client.collections.load(collection_name: "book")
85
+ ```
86
+ ```ruby
87
+ # Release a collection from memory after a search or a query to reduce memory usage
88
+ client.collections.release(collection_name: "book")
89
+ ```
90
+
91
+ ### Inserting Data
92
+ ```ruby
93
+ client.entities.insert(
94
+ collection_name: "book",
95
+ num_rows: 5, # Number of rows to be inserted. The number should be the same as the length of each field array.
96
+ fields_data: [
97
+ {
98
+ "field_name": "book_id",
99
+ "type": Milvus::DATA_TYPES["int64"],
100
+ "field": [1,2,3,4,5]
101
+ },
102
+ {
103
+ "field_name": "word_count",
104
+ "type": Milvus::DATA_TYPES["int64"],
105
+ "field": [1000,2000,3000,4000,5000]
106
+ },
107
+ {
108
+ "field_name": "book_intro",
109
+ "type": 101,
110
+ "field": [ [1,1],[2,1],[3,1],[4,1],[5,1] ]
111
+ }
112
+ ]
113
+ )
114
+ ```
115
+ ```ruby
116
+ # Delete the entities with the boolean expression you created
117
+ client.entities.delete(
118
+ collection_name: "book",
119
+ expression: "book_id in [0,1]"
120
+ )
121
+ ```
122
+ ```ruby
123
+ # Compact data manually
124
+ client.entities.compact!(
125
+ collection_id: "book"
126
+ )
127
+ # => {"status"=>{}, "compactionID"=>440928616022809499}
128
+ ```
129
+ ```ruby
130
+ # Check compaction status
131
+ client.entities.compact_status(
132
+ compaction_id: 440928616022809499
133
+ )
134
+ # => {"status"=>{}, "state"=>2}
135
+ ```
136
+
137
+ ### Indices
138
+ ```ruby
139
+ client.indices.create(
140
+ collection_name: "book",
141
+ field_name: "book_intro",
142
+ extra_params: [
143
+ { key: "metric_type", "value": "L2" },
144
+ { key: "index_type", "value": "IVF_FLAT" },
145
+ { key: "params", "value": "{\"nlist\":1024}" }
146
+ ]
147
+ )
148
+ ```
149
+ ```ruby
150
+ collection.indices.create(
151
+ field_name="book_name",
152
+ index_name="scalar_index",
153
+ )
154
+ ```
155
+ ```ruby
156
+ client.indices.delete(
157
+ collection_name: "book",
158
+ field_name: "book_intro"
159
+ )
160
+ ```
161
+
162
+ ### Search & Querying
163
+ ```ruby
164
+ client.search(
165
+ collection_name: "book",
166
+ output_fields: ["book_id"], # optional
167
+ anns_field: "book_intro",
168
+ top_k: "2",
169
+ params: "{\"nprobe\": 10}",
170
+ metric_type: "L2",
171
+ round_decimal: "-1",
172
+ vectors: [ [0.1,0.2] ],
173
+ dsl_type: 1
174
+ )
175
+ ```
176
+ ```ruby
177
+ client.query(
178
+ collection_name: "book",
179
+ output_fields: ["book_id", "book_intro"],
180
+ expr: "book_id in [2,4,6,8]"
181
+ )
182
+ ```
183
+
184
+ ### Partitions
185
+ ```ruby
186
+ client.partitions.create(
187
+ "collection_name": "book",
188
+ "partition_name": "novel"
189
+ )
190
+ ```
191
+ ```ruby
192
+ client.partitions.get(
193
+ "collection_name": "book",
194
+ "partition_name": "novel"
195
+ )
196
+ ```
197
+ ```ruby
198
+ client.partitions.delete(
199
+ "collection_name": "book",
200
+ "partition_name": "novel"
201
+ )
202
+ ```
203
+ ```ruby
204
+ client.partitions.load(
205
+ "collection_name": "book",
206
+ "partition_names": ["novel"],
207
+ "replica_number": 1
208
+ )
209
+ ```
210
+ ```ruby
211
+ client.partitions.release(
212
+ "collection_name": "book",
213
+ "partition_names": ["novel"],
214
+ "replica_number": 1
215
+ )
216
+ ```
217
+
218
+ ### Health
219
+ ```ruby
220
+ # Live determines whether the application is alive. It can be used for Kubernetes liveness probe.
221
+ client.health
222
+ ```
223
+
224
+ ## Development
225
+
226
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
227
+
228
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
229
+
230
+ ## Contributing
231
+
232
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andreibondarev/milvus.
233
+
234
+ ## License
235
+
236
+ `milvus` is licensed under the Apache License, Version 2.0. View a copy of the License file.
237
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Base
5
+ attr_reader :client
6
+
7
+ def initialize(client:)
8
+ @client = client
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Milvus
6
+ class Client
7
+ attr_reader :url, :api_key
8
+
9
+ API_VERSION = "api/v1"
10
+
11
+ def initialize(
12
+ url:,
13
+ api_key: nil
14
+ )
15
+ @url = url
16
+ @api_key = api_key
17
+ end
18
+
19
+ def health
20
+ @health ||= Milvus::Health.new(client: self).get
21
+ end
22
+
23
+ def collections
24
+ @schema ||= Milvus::Collections.new(client: self)
25
+ end
26
+
27
+ def partitions
28
+ @partitions ||= Milvus::Partitions.new(client: self)
29
+ end
30
+
31
+ def entities
32
+ @entities ||= Milvus::Entities.new(client: self)
33
+ end
34
+
35
+ def indices
36
+ @indices ||= Milvus::Indices.new(client: self)
37
+ end
38
+
39
+ def search(...)
40
+ @search ||= Milvus::Search.new(client: self).post(...)
41
+ end
42
+
43
+ def query(...)
44
+ @query ||= Milvus::Query.new(client: self).post(...)
45
+ end
46
+
47
+ def connection
48
+ @connection ||= Faraday.new(url: "#{url}/#{API_VERSION}/") do |faraday|
49
+ if api_key
50
+ faraday.request :authorization, :Bearer, api_key
51
+ end
52
+ faraday.request :json
53
+ faraday.response :json, content_type: /\bjson$/
54
+ faraday.adapter Faraday.default_adapter
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Collections < Base
5
+ PATH = "collection"
6
+
7
+ # Create a Collection
8
+ def create(
9
+ collection_name:,
10
+ auto_id:,
11
+ description:,
12
+ fields:
13
+ )
14
+ response = client.connection.post(PATH) do |req|
15
+ req.body = {
16
+ collection_name: collection_name,
17
+ schema: {
18
+ auto_id: auto_id,
19
+ description: description,
20
+ fields: fields,
21
+ name: collection_name # This duplicated field is kept for historical reasons.
22
+ }
23
+ }.to_json
24
+ end
25
+ response.body.empty? ? true : response.body
26
+ end
27
+
28
+ # Retrieve a Collection
29
+ def get(collection_name:)
30
+ response = client.connection.get(PATH) do |req|
31
+ req.body = {
32
+ collection_name: collection_name
33
+ }.to_json
34
+ end
35
+ response.body
36
+ end
37
+
38
+ # Drop a Collection
39
+ def delete(collection_name:)
40
+ response = client.connection.delete(PATH) do |req|
41
+ req.body = {
42
+ collection_name: collection_name
43
+ }.to_json
44
+ end
45
+ response.body.empty? ? true : response.body
46
+ end
47
+
48
+ # Load the collection to memory before a search or a query
49
+ def load(collection_name:)
50
+ response = client.connection.post("#{PATH}/load") do |req|
51
+ req.body = {
52
+ collection_name: collection_name
53
+ }.to_json
54
+ end
55
+ response.body.empty? ? true : response.body
56
+ end
57
+
58
+ # Release a collection from memory after a search or a query to reduce memory usage
59
+ def release(collection_name:)
60
+ response = client.connection.delete("#{PATH}/load") do |req|
61
+ req.body = {
62
+ collection_name: collection_name
63
+ }.to_json
64
+ end
65
+ response.body.empty? ? true : response.body
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ DATA_TYPES = {
5
+ "boolean" => 1,
6
+ "int8" => 2,
7
+ "int16" => 3,
8
+ "int32" => 4,
9
+ "int64" => 5,
10
+ "float" => 10,
11
+ "double" => 11,
12
+ "string" => 20,
13
+ "varchar" => 21,
14
+ "binary_vector" => 101,
15
+ "float_vector" => 102
16
+ }.freeze
17
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Entities < Base
5
+ PATH = "entities"
6
+
7
+ # Insert the data to the collection.
8
+ def insert(
9
+ collection_name:,
10
+ fields_data:,
11
+ num_rows:,
12
+ partition_name: nil
13
+ )
14
+ response = client.connection.post(PATH) do |req|
15
+ req.body = {
16
+ collection_name: collection_name,
17
+ fields_data: fields_data,
18
+ num_rows: num_rows
19
+ }.to_json
20
+
21
+ req.body["partition_name"] = partition_name if partition_name
22
+ end
23
+ response.body.empty? ? true : response.body
24
+ end
25
+
26
+ # Delete the entities with the boolean expression you created
27
+ def delete(
28
+ collection_name:,
29
+ expression:
30
+ )
31
+ response = client.connection.delete(PATH) do |req|
32
+ req.body = {
33
+ collection_name: collection_name,
34
+ expr: expression
35
+ }.to_json
36
+ end
37
+ response.body.empty? ? true : response.body
38
+ end
39
+
40
+ # Compact data manually
41
+ def compact!(
42
+ collection_id:
43
+ )
44
+ response = client.connection.post("compaction") do |req|
45
+ req.body = {
46
+ collectionID: collection_id
47
+ }.to_json
48
+ end
49
+ response.body.empty? ? true : response.body
50
+ end
51
+
52
+ # Check compaction status
53
+ def compact_status(
54
+ compaction_id:
55
+ )
56
+ response = client.connection.get("compaction/state") do |req|
57
+ req.body = {
58
+ compactionID: compaction_id
59
+ }.to_json
60
+ end
61
+ response.body.empty? ? true : response.body
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Health < Base
5
+ PATH = "health"
6
+
7
+ def get
8
+ response = client.connection.get(PATH.to_s)
9
+ response.body
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Indices < Base
5
+ PATH = "index"
6
+
7
+ def create(
8
+ collection_name:,
9
+ field_name:,
10
+ extra_params:
11
+ )
12
+ response = client.connection.post(PATH) do |req|
13
+ req.body = {
14
+ collection_name: collection_name,
15
+ field_name: field_name,
16
+ extra_params: extra_params
17
+ }.to_json
18
+ end
19
+ response.body.empty? ? true : response.body
20
+ end
21
+
22
+ def delete(
23
+ collection_name:,
24
+ field_name:
25
+ )
26
+ response = client.connection.delete(PATH) do |req|
27
+ req.body = {
28
+ collection_name: collection_name,
29
+ field_name: field_name
30
+ }.to_json
31
+ end
32
+ response.body.empty? ? true : response.body
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Partitions < Base
5
+ PATH = "partition"
6
+
7
+ # Create a partition
8
+ def create(collection_name:, partition_name:)
9
+ response = client.connection.post(PATH) do |req|
10
+ req.body = {
11
+ collection_name: collection_name,
12
+ partition_name: partition_name
13
+ }
14
+ end
15
+ response.body.empty? ? true : response.body
16
+ end
17
+
18
+ # Verify if a partition exists
19
+ def get(collection_name:, partition_name:)
20
+ response = client.connection.get("#{PATH}/existence") do |req|
21
+ req.body = {
22
+ collection_name: collection_name,
23
+ partition_name: partition_name
24
+ }
25
+ end
26
+ response.body.empty? ? true : response.body
27
+ end
28
+
29
+ # Dropping a partition
30
+ def delete(collection_name:, partition_name:)
31
+ response = client.connection.delete(PATH) do |req|
32
+ req.body = {
33
+ collection_name: collection_name,
34
+ partition_name: partition_name
35
+ }
36
+ end
37
+ response.body.empty? ? true : response.body
38
+ end
39
+
40
+ # Load a Partition
41
+ def load(
42
+ collection_name:,
43
+ partition_names:,
44
+ replica_number: nil
45
+ )
46
+ response = client.connection.post("#{PATH}s/load") do |req|
47
+ req.body = {
48
+ collection_name: collection_name,
49
+ partition_names: partition_names
50
+ }
51
+ req.body[:replica_number] = replica_number if replica_number
52
+ end
53
+ response.body.empty? ? true : response.body
54
+ end
55
+
56
+ def release(
57
+ collection_name:,
58
+ partition_names:,
59
+ replica_number: nil
60
+ )
61
+ response = client.connection.delete("#{PATH}s/load") do |req|
62
+ req.body = {
63
+ collection_name: collection_name,
64
+ partition_names: partition_names
65
+ }
66
+ req.body[:replica_number] = replica_number if replica_number
67
+ end
68
+ response.body.empty? ? true : response.body
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Query < Base
5
+ PATH = "query"
6
+
7
+ def post(
8
+ collection_name:,
9
+ output_fields:,
10
+ expr:
11
+ )
12
+ response = client.connection.post(PATH) do |req|
13
+ req.body = {
14
+ collection_name: collection_name,
15
+ expr: expr
16
+ }
17
+ if output_fields
18
+ req.body[:output_fields] = output_fields
19
+ end
20
+ end
21
+ response.body.empty? ? true : response.body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ class Search < Base
5
+ PATH = "search"
6
+
7
+ def post(
8
+ collection_name:,
9
+ anns_field:, top_k:, params:, metric_type:, vectors:, dsl_type:, output_fields: nil,
10
+ round_decimal: nil
11
+ )
12
+ response = client.connection.post(PATH) do |req|
13
+ req.body = {
14
+ collection_name: collection_name,
15
+ search_params: [
16
+ {key: "anns_field", value: anns_field},
17
+ {key: "topk", value: top_k},
18
+ {key: "params", value: params},
19
+ {key: "metric_type", value: metric_type}
20
+ ],
21
+ dsl_type: dsl_type,
22
+ vectors: vectors
23
+ }
24
+ if round_decimal
25
+ req.body[:search_params].push(
26
+ {key: "round_decimal", value: round_decimal}
27
+ )
28
+ end
29
+ if output_fields
30
+ req.body[:output_fields] = output_fields
31
+ end
32
+ end
33
+ response.body.empty? ? true : response.body
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Milvus
4
+ VERSION = "0.9.0"
5
+ end
data/lib/milvus.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "milvus/version"
4
+ require_relative "milvus/constants"
5
+
6
+ module Milvus
7
+ autoload :Base, "milvus/base"
8
+ autoload :Collections, "milvus/collections"
9
+ autoload :Client, "milvus/client"
10
+ autoload :Error, "milvus/error"
11
+ autoload :Entities, "milvus/entities"
12
+ autoload :Health, "milvus/health"
13
+ autoload :Indices, "milvus/indices"
14
+ autoload :Partitions, "milvus/partitions"
15
+ autoload :Search, "milvus/search"
16
+ autoload :Query, "milvus/query"
17
+ end
data/sig/milvus.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Milvus
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: milvus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Bondarev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry-byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.10.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.0
41
+ description: Ruby wrapper for the Milvus vector search database API
42
+ email:
43
+ - andrei.bondarev13@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - CHANGELOG.md
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - lib/milvus.rb
56
+ - lib/milvus/base.rb
57
+ - lib/milvus/client.rb
58
+ - lib/milvus/collections.rb
59
+ - lib/milvus/constants.rb
60
+ - lib/milvus/entities.rb
61
+ - lib/milvus/error.rb
62
+ - lib/milvus/health.rb
63
+ - lib/milvus/indices.rb
64
+ - lib/milvus/partitions.rb
65
+ - lib/milvus/query.rb
66
+ - lib/milvus/search.rb
67
+ - lib/milvus/version.rb
68
+ - sig/milvus.rbs
69
+ homepage: https://github.com/andreibondarev/milvus
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/andreibondarev/milvus
74
+ source_code_uri: https://github.com/andreibondarev/milvus
75
+ changelog_uri: https://github.com/andreibondarev/milvus/CHANGELOG.md
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.3.7
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Ruby wrapper for the Milvus vector search database API
95
+ test_files: []