diff --git a/CHANGELOG.md b/CHANGELOG.md index c79134e..c470049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ ## [Unreleased] +## [0.9.0] - 2024-07-08 + +- Add object.replace method which uses PUT which performs a complete object replacement + +### Breaking +- Change the object.update method to use PATCH which only performs a partial update(previously performed a replacement) + ## [0.8.11] - 2024-07-02 +- Allow the user to specify any options they want for multi-tenancy when creating a schema using their own hash +- Allow Ollama vectorizer ## [0.8.10] - 2024-01-25 diff --git a/Gemfile.lock b/Gemfile.lock index 289aaed..aa39dfc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - weaviate-ruby (0.8.11) + weaviate-ruby (0.9.0) faraday (>= 2.0.1, < 3.0) graphlient (~> 0.7.0) diff --git a/README.md b/README.md index c8e0e66..c7043e3 100644 --- a/README.md +++ b/README.md @@ -168,14 +168,17 @@ client.objects.exists?( id: "uuid" ) -# Delete a single data object from Weaviate. -client.objects.delete( +# Perform a partial update on an object based on its uuid. +client.objects.update( class_name: "Question", - id: "uuid" + id: "uuid", + properties: { + category: "simple-math" + } ) -# Update a single data object based on its uuid. -client.objects.update( +# Replace an object based on its uuid. +client.objects.replace( class_name: "Question", id: "uuid", properties: { @@ -185,6 +188,12 @@ client.objects.update( } ) +# Delete a single data object from Weaviate. +client.objects.delete( + class_name: "Question", + id: "uuid" +) + # Batch create objects client.objects.batch_create(objects: [ { diff --git a/lib/weaviate/objects.rb b/lib/weaviate/objects.rb index e1905ca..e511689 100644 --- a/lib/weaviate/objects.rb +++ b/lib/weaviate/objects.rb @@ -122,6 +122,31 @@ def update( ) validate_consistency_level!(consistency_level) unless consistency_level.nil? + response = client.connection.patch("#{PATH}/#{class_name}/#{id}") do |req| + req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil? + + req.body = {} + req.body["id"] = id + req.body["class"] = class_name + req.body["properties"] = properties + req.body["vector"] = vector unless vector.nil? + req.body["tenant"] = tenant unless tenant.nil? + end + + response.body + end + + # Replace an individual data object based on its uuid. + def replace( + class_name:, + id:, + properties:, + vector: nil, + tenant: nil, + consistency_level: nil + ) + validate_consistency_level!(consistency_level) unless consistency_level.nil? + response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req| req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil? diff --git a/lib/weaviate/version.rb b/lib/weaviate/version.rb index c979436..9d19596 100644 --- a/lib/weaviate/version.rb +++ b/lib/weaviate/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Weaviate - VERSION = "0.8.11" + VERSION = "0.9.0" end diff --git a/spec/weaviate/objects_spec.rb b/spec/weaviate/objects_spec.rb index 2b0c4fe..52a84f3 100644 --- a/spec/weaviate/objects_spec.rb +++ b/spec/weaviate/objects_spec.rb @@ -132,7 +132,7 @@ let(:response) { OpenStruct.new(success?: true, body: object_fixture) } before do - allow_any_instance_of(Faraday::Connection).to receive(:put) + allow_any_instance_of(Faraday::Connection).to receive(:patch) .with("objects/Question/123") .and_return(response) end @@ -151,6 +151,29 @@ end end + describe "#replace" do + let(:response) { OpenStruct.new(success?: true, body: object_fixture) } + + before do + allow_any_instance_of(Faraday::Connection).to receive(:put) + .with("objects/Question/123") + .and_return(response) + end + + it "returns the schema" do + response = objects.replace( + class_name: "Question", + id: "123", + properties: { + question: "What does 6 times 7 equal to?", + category: "math", + answer: "42" + } + ) + expect(response.dig("class")).to eq("Question") + end + end + describe "#batch_create" do let(:response) { OpenStruct.new(success?: true, body: objects_fixture) }