diff --git a/Gemfile b/Gemfile index e77754b..0963f18 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gemspec gem "rake", "~> 13.0" gem "rspec", "~> 3.0" +gem "standard", "~> 1.27.0" diff --git a/Gemfile.lock b/Gemfile.lock index aeff3a2..62943d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,7 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.4.2) byebug (11.1.3) coderay (1.1.3) diff-lcs (1.5.0) @@ -14,14 +15,22 @@ GEM faraday-net_http (>= 2.0, < 3.1) ruby2_keywords (>= 0.0.4) faraday-net_http (3.0.2) + json (2.6.3) + language_server-protocol (3.17.0.3) method_source (1.0.0) + parallel (1.23.0) + parser (3.2.2.0) + ast (~> 2.4.1) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.10.1) byebug (~> 11.0) pry (>= 0.13, < 0.15) + rainbow (3.1.1) rake (13.0.6) + regexp_parser (2.8.0) + rexml (3.2.5) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -35,17 +44,40 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.0) + rubocop (1.50.2) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.0) + parser (>= 3.2.1.0) + rubocop-performance (1.16.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + standard (1.27.0) + language_server-protocol (~> 3.17.0.2) + rubocop (~> 1.50.2) + rubocop-performance (~> 1.16.0) + unicode-display_width (2.4.2) PLATFORMS x86_64-darwin-19 x86_64-darwin-22 + x86_64-linux DEPENDENCIES milvus! pry-byebug (~> 3.10.0) rake (~> 13.0) rspec (~> 3.0) + standard (~> 1.27.0) BUNDLED WITH 2.4.0 diff --git a/README.md b/README.md index 2bdfbce..2e3674e 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,8 @@ client.entities.compact!( collection_id: "book" ) # => {"status"=>{}, "compactionID"=>440928616022809499} - +``` +```ruby # Check compaction status client.entities.compact_status( compaction_id: 440928616022809499 diff --git a/lib/milvus/client.rb b/lib/milvus/client.rb index 0d02d88..9230f30 100644 --- a/lib/milvus/client.rb +++ b/lib/milvus/client.rb @@ -6,7 +6,7 @@ module Milvus class Client attr_reader :url, :api_key - API_VERSION = "api/v1".freeze + API_VERSION = "api/v1" def initialize( url:, diff --git a/lib/milvus/collections.rb b/lib/milvus/collections.rb index e107612..3b87560 100644 --- a/lib/milvus/collections.rb +++ b/lib/milvus/collections.rb @@ -2,7 +2,7 @@ module Milvus class Collections < Base - PATH = "collection".freeze + PATH = "collection" # Create a Collection def create( diff --git a/lib/milvus/constants.rb b/lib/milvus/constants.rb index bd6700f..674c4f1 100644 --- a/lib/milvus/constants.rb +++ b/lib/milvus/constants.rb @@ -14,4 +14,4 @@ module Milvus "binary_vector" => 101, "float_vector" => 102 }.freeze -end \ No newline at end of file +end diff --git a/lib/milvus/entities.rb b/lib/milvus/entities.rb index e462c12..0b02910 100644 --- a/lib/milvus/entities.rb +++ b/lib/milvus/entities.rb @@ -2,7 +2,7 @@ module Milvus class Entities < Base - PATH = "entities".freeze + PATH = "entities" # Insert the data to the collection. def insert( @@ -18,7 +18,7 @@ def insert( num_rows: num_rows }.to_json - req.body['partition_name'] = partition_name if partition_name + req.body["partition_name"] = partition_name if partition_name end response.body.empty? ? true : response.body end diff --git a/lib/milvus/health.rb b/lib/milvus/health.rb index 9258cb5..44f4d9d 100644 --- a/lib/milvus/health.rb +++ b/lib/milvus/health.rb @@ -2,7 +2,7 @@ module Milvus class Health < Base - PATH = "health".freeze + PATH = "health" def get response = client.connection.get(PATH.to_s) diff --git a/lib/milvus/indices.rb b/lib/milvus/indices.rb index 069c283..bea99dd 100644 --- a/lib/milvus/indices.rb +++ b/lib/milvus/indices.rb @@ -2,7 +2,7 @@ module Milvus class Indices < Base - PATH = "index".freeze + PATH = "index" def create( collection_name:, diff --git a/lib/milvus/partitions.rb b/lib/milvus/partitions.rb index 4919fa4..c0f91fa 100644 --- a/lib/milvus/partitions.rb +++ b/lib/milvus/partitions.rb @@ -2,7 +2,7 @@ module Milvus class Partitions < Base - PATH = "partition".freeze + PATH = "partition" # Create a partition def create(collection_name:, partition_name:) diff --git a/lib/milvus/query.rb b/lib/milvus/query.rb index d1def85..b53041c 100644 --- a/lib/milvus/query.rb +++ b/lib/milvus/query.rb @@ -2,7 +2,7 @@ module Milvus class Query < Base - PATH = "query".freeze + PATH = "query" def post( collection_name:, diff --git a/lib/milvus/search.rb b/lib/milvus/search.rb index b1d054e..f57bc39 100644 --- a/lib/milvus/search.rb +++ b/lib/milvus/search.rb @@ -2,34 +2,28 @@ module Milvus class Search < Base - PATH = "search".freeze + PATH = "search" def post( collection_name:, - output_fields: nil, - anns_field:, - top_k:, - params:, - metric_type:, - round_decimal: nil, - vectors:, - dsl_type: + anns_field:, top_k:, params:, metric_type:, vectors:, dsl_type:, output_fields: nil, + round_decimal: nil ) response = client.connection.post(PATH) do |req| req.body = { collection_name: collection_name, search_params: [ - { key: "anns_field", value: anns_field }, - { key: "topk", value: top_k }, - { key: "params", value: params }, - { key: "metric_type", value: metric_type }, + {key: "anns_field", value: anns_field}, + {key: "topk", value: top_k}, + {key: "params", value: params}, + {key: "metric_type", value: metric_type} ], dsl_type: dsl_type, vectors: vectors } if round_decimal req.body[:search_params].push( - { key: "round_decimal", value: round_decimal } + {key: "round_decimal", value: round_decimal} ) end if output_fields diff --git a/lib/milvus/version.rb b/lib/milvus/version.rb index e769b6c..13059d8 100644 --- a/lib/milvus/version.rb +++ b/lib/milvus/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Milvus - VERSION = "0.9.0".freeze + VERSION = "0.9.0" end diff --git a/spec/milvus/collections_spec.rb b/spec/milvus/collections_spec.rb index fb3f69a..68e7727 100644 --- a/spec/milvus/collections_spec.rb +++ b/spec/milvus/collections_spec.rb @@ -28,27 +28,27 @@ auto_id: false, fields: [ { - "name": "book_id", - "description": "book id", - "is_primary_key": true, - "autoID": false, - "data_type": Milvus::DATA_TYPES["int64"] + name: "book_id", + description: "book id", + is_primary_key: true, + autoID: false, + data_type: Milvus::DATA_TYPES["int64"] }, { - "name": "word_count", - "description": "count of words", - "is_primary_key": false, - "data_type": Milvus::DATA_TYPES["int64"] + name: "word_count", + description: "count of words", + is_primary_key: false, + data_type: Milvus::DATA_TYPES["int64"] }, { - "name": "book_intro", - "description": "embedded vector of book introduction", - "data_type": Milvus::DATA_TYPES["binary_vector"], - "is_primary_key": false, - "type_params": [ + name: "book_intro", + description: "embedded vector of book introduction", + data_type: Milvus::DATA_TYPES["binary_vector"], + is_primary_key: false, + type_params: [ { - "key": "dim", - "value": "2" + key: "dim", + value: "2" } ] } diff --git a/spec/milvus/entities_spec.rb b/spec/milvus/entities_spec.rb index 55ba692..e1e4314 100644 --- a/spec/milvus/entities_spec.rb +++ b/spec/milvus/entities_spec.rb @@ -30,21 +30,21 @@ num_rows: 5, fields_data: [ { - "field_name": "book_id", - "type": Milvus::DATA_TYPES["int64"], - "field": [1,2,3,4,5] + field_name: "book_id", + type: Milvus::DATA_TYPES["int64"], + field: [1, 2, 3, 4, 5] }, { - "field_name": "word_count", - "type": Milvus::DATA_TYPES["int64"], - "field": [1000,2000,3000,4000,5000] + field_name: "word_count", + type: Milvus::DATA_TYPES["int64"], + field: [1000, 2000, 3000, 4000, 5000] }, { - "field_name": "book_intro", - "type": 101, - "field": [ [1,1],[2,1],[3,1],[4,1],[5,1] ] + field_name: "book_intro", + type: 101, + field: [[1, 1], [2, 1], [3, 1], [4, 1], [5, 1]] } - ] + ] ) expect(response).to eq(entities_created_fixture) end diff --git a/spec/milvus/indices_spec.rb b/spec/milvus/indices_spec.rb index 3670ee1..66139e7 100644 --- a/spec/milvus/indices_spec.rb +++ b/spec/milvus/indices_spec.rb @@ -26,9 +26,9 @@ collection_name: "book", field_name: "book_intro", extra_params: [ - { key: "metric_type", "value": "L2" }, - { key: "index_type", "value": "IVF_FLAT" }, - { key: "params", "value": "{\"nlist\":1024}" } + {key: "metric_type", value: "L2"}, + {key: "index_type", value: "IVF_FLAT"}, + {key: "params", value: "{\"nlist\":1024}"} ] ) expect(response).to eq(true) @@ -52,4 +52,4 @@ expect(response).to eq(true) end end -end \ No newline at end of file +end diff --git a/spec/milvus/query_spec.rb b/spec/milvus/query_spec.rb index af1e849..616c559 100644 --- a/spec/milvus/query_spec.rb +++ b/spec/milvus/query_spec.rb @@ -29,4 +29,4 @@ expect(response).to eq(true) end end -end \ No newline at end of file +end diff --git a/spec/milvus/search_spec.rb b/spec/milvus/search_spec.rb index 7b7a073..5e59ca6 100644 --- a/spec/milvus/search_spec.rb +++ b/spec/milvus/search_spec.rb @@ -29,7 +29,7 @@ params: "{\"nprobe\": 10}", metric_type: "L2", round_decimal: "-1", - vectors: [ [0.1,0.2] ], + vectors: [[0.1, 0.2]], dsl_type: 1 ) expect(response).to eq(search_result)