Skip to content

Commit

Permalink
Fixes (#12)
Browse files Browse the repository at this point in the history
* Fixes

* fix spec
andreibondarev authored Jul 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 076cae6 commit 8895f61
Showing 5 changed files with 12 additions and 21 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -64,27 +64,23 @@ client.collections.get_stats(collection_name: "example_collection")
# Creating a new collection schema
client.collections.create(
collection_name: "example_collection",
description: "Book search",
auto_id: true,
fields: [
{
fieldName: "book_id",
description: "Book ID",
isPrimary: true,
autoID: false,
dataType: "Int64"
},
{
fieldName: "content",
description: "Chunk Content",
dataType: "VarChar",
elementTypeParams: {
max_length: "512"
}
},
{
fieldName: "vector",
description: "Chunk Embedding",
dataType: "FloatVector",
elementTypeParams: {
dim: 1536
14 changes: 6 additions & 8 deletions lib/milvus/collections.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ def has(collection_name:)
response = client.connection.post("#{PATH}/has") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body
end
@@ -40,7 +40,7 @@ def get_stats(collection_name:)
response = client.connection.post("#{PATH}/get_stats") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body
end
@@ -55,19 +55,17 @@ def get_stats(collection_name:)
def create(
collection_name:,
auto_id:,
description:,
fields:
)
response = client.connection.post("#{PATH}/create") do |req|
req.body = {
collectionName: collection_name,
schema: {
autoId: auto_id,
description: description,
fields: fields,
name: collection_name # This duplicated field is kept for historical reasons.
}
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -80,7 +78,7 @@ def describe(collection_name:)
response = client.connection.post("#{PATH}/describe") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body
end
@@ -103,7 +101,7 @@ def drop(collection_name:)
response = client.connection.post("#{PATH}/drop") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -142,7 +140,7 @@ def release(collection_name:)
response = client.connection.post("#{PATH}/release") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body.empty? ? true : response.body
end
4 changes: 1 addition & 3 deletions lib/milvus/entities.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ def insert(
collectionName: collection_name,
data: data
}

req.body[:partitionName] = partition_name if partition_name
end
response.body.empty? ? true : response.body
@@ -40,7 +39,7 @@ def delete(
req.body = {
collectionName: collection_name,
filter: filter
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -84,7 +83,6 @@ def upsert(
collectionName: collection_name,
data: data
}

req.body[:partitionName] = partition_name if partition_name
end
response.body.empty? ? true : response.body
8 changes: 4 additions & 4 deletions lib/milvus/indexes.rb
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ def create(
req.body = {
collectionName: collection_name,
indexParams: index_params
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -35,7 +35,7 @@ def drop(
req.body = {
collectionName: collection_name,
indexName: index_name
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -53,7 +53,7 @@ def describe(
req.body = {
collectionName: collection_name,
indexName: index_name
}.to_json
}
end
response.body.empty? ? true : response.body
end
@@ -68,7 +68,7 @@ def list(
response = client.connection.post("#{PATH}/list") do |req|
req.body = {
collectionName: collection_name
}.to_json
}
end
response.body.empty? ? true : response.body
end
3 changes: 1 addition & 2 deletions spec/milvus/collections_spec.rb
Original file line number Diff line number Diff line change
@@ -62,14 +62,13 @@
describe "#create" do
let(:collection_name) { "test_collection" }
let(:auto_id) { true }
let(:description) { "Test collection" }
let(:fields) { [{name: "field1", type: "int64"}] }
let(:response_body) { File.read("spec/fixtures/collections/create.json") }
let(:response) { instance_double("Faraday::Response", body: response_body) }

it "creates a collection" do
expect(connection).to receive(:post).with("collections/create").and_return(response)
result = collections.create(collection_name: collection_name, auto_id: auto_id, description: description, fields: fields)
result = collections.create(collection_name: collection_name, auto_id: auto_id, fields: fields)
expect(result).to eq(response_body)
end
end

0 comments on commit 8895f61

Please sign in to comment.