weaviate-ruby 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -1
- data/README.md +27 -1
- data/lib/weaviate/client.rb +21 -0
- data/lib/weaviate/objects.rb +2 -2
- data/lib/weaviate/query.rb +36 -0
- data/lib/weaviate/response/collection.rb +1 -2
- data/lib/weaviate/schema.rb +1 -1
- data/lib/weaviate/version.rb +1 -1
- data/lib/weaviate.rb +1 -0
- metadata +17 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 26b105dbf4536df10fd278d0aac2c437483440c87caf37ec9f6c06e34eeb690b
         | 
| 4 | 
            +
              data.tar.gz: 24b3933c80ebd659f292c0785cdd311733337d1adf21e9ea9d04da602f274d43
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d1961b6e0123e21b60414b53055807ce83305a241c01b74747240cb0022e42483e2a2c2bb9305d2e35630ea2ab28517c311fa094de927c19246f199f91598ce4
         | 
| 7 | 
            +
              data.tar.gz: 68ceaf84cded37b443cd7cf8879d5b947352b7be718f2b5a041571eacc584cfddfffd04f94f3b3daa6d1b712f842ac27a4ae105edb2711ebaef28a7cfe73541a
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,23 +1,40 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                weaviate-ruby (0. | 
| 4 | 
            +
                weaviate-ruby (0.2.0)
         | 
| 5 5 | 
             
                  faraday (~> 2.7)
         | 
| 6 | 
            +
                  graphlient (~> 0.7.0)
         | 
| 6 7 |  | 
| 7 8 | 
             
            GEM
         | 
| 8 9 | 
             
              remote: https://rubygems.org/
         | 
| 9 10 | 
             
              specs:
         | 
| 11 | 
            +
                activesupport (7.0.4.3)
         | 
| 12 | 
            +
                  concurrent-ruby (~> 1.0, >= 1.0.2)
         | 
| 13 | 
            +
                  i18n (>= 1.6, < 2)
         | 
| 14 | 
            +
                  minitest (>= 5.1)
         | 
| 15 | 
            +
                  tzinfo (~> 2.0)
         | 
| 10 16 | 
             
                ast (2.4.2)
         | 
| 11 17 | 
             
                byebug (11.1.3)
         | 
| 12 18 | 
             
                coderay (1.1.3)
         | 
| 19 | 
            +
                concurrent-ruby (1.2.2)
         | 
| 13 20 | 
             
                diff-lcs (1.5.0)
         | 
| 14 21 | 
             
                faraday (2.7.4)
         | 
| 15 22 | 
             
                  faraday-net_http (>= 2.0, < 3.1)
         | 
| 16 23 | 
             
                  ruby2_keywords (>= 0.0.4)
         | 
| 17 24 | 
             
                faraday-net_http (3.0.2)
         | 
| 25 | 
            +
                graphlient (0.7.0)
         | 
| 26 | 
            +
                  faraday (~> 2.0)
         | 
| 27 | 
            +
                  graphql-client
         | 
| 28 | 
            +
                graphql (2.0.19)
         | 
| 29 | 
            +
                graphql-client (0.18.0)
         | 
| 30 | 
            +
                  activesupport (>= 3.0)
         | 
| 31 | 
            +
                  graphql
         | 
| 32 | 
            +
                i18n (1.12.0)
         | 
| 33 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 18 34 | 
             
                json (2.6.3)
         | 
| 19 35 | 
             
                language_server-protocol (3.17.0.3)
         | 
| 20 36 | 
             
                method_source (1.0.0)
         | 
| 37 | 
            +
                minitest (5.18.0)
         | 
| 21 38 | 
             
                parallel (1.22.1)
         | 
| 22 39 | 
             
                parser (3.2.1.1)
         | 
| 23 40 | 
             
                  ast (~> 2.4.1)
         | 
| @@ -65,6 +82,8 @@ GEM | |
| 65 82 | 
             
                  language_server-protocol (~> 3.17.0.2)
         | 
| 66 83 | 
             
                  rubocop (~> 1.48.1)
         | 
| 67 84 | 
             
                  rubocop-performance (~> 1.16.0)
         | 
| 85 | 
            +
                tzinfo (2.0.6)
         | 
| 86 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 68 87 | 
             
                unicode-display_width (2.4.2)
         | 
| 69 88 |  | 
| 70 89 | 
             
            PLATFORMS
         | 
    
        data/README.md
    CHANGED
    
    | @@ -48,7 +48,9 @@ client.schema.create( | |
| 48 48 | 
             
                        "description": "The category",
         | 
| 49 49 | 
             
                        "name": "category"
         | 
| 50 50 | 
             
                    }
         | 
| 51 | 
            -
                ]
         | 
| 51 | 
            +
                ],
         | 
| 52 | 
            +
                # Possible values: 'text2vec-cohere', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'
         | 
| 53 | 
            +
                vectorizer: "text2vec-openai"
         | 
| 52 54 | 
             
            )
         | 
| 53 55 |  | 
| 54 56 | 
             
            # Get a single class from the schema
         | 
| @@ -134,6 +136,30 @@ response = client.objects.batch_create(objects: [ | |
| 134 136 | 
             
            response.data
         | 
| 135 137 | 
             
            ```
         | 
| 136 138 |  | 
| 139 | 
            +
            ### Querying
         | 
| 140 | 
            +
            ```ruby
         | 
| 141 | 
            +
            near_text = { "concepts": ["biology"] }
         | 
| 142 | 
            +
             | 
| 143 | 
            +
            client.query.get(
         | 
| 144 | 
            +
                class_name: 'Question',
         | 
| 145 | 
            +
                fields: ['question', 'answer', 'category'],
         | 
| 146 | 
            +
                limit: 1,
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                # To use this parameter you must have created your schema by setting the `vectorizer:` property to
         | 
| 149 | 
            +
                # either 'text2vec-transformers', 'text2vec-contextionary', 'text2vec-openai', 'multi2vec-clip', 'text2vec-huggingface' or 'text2vec-cohere'
         | 
| 150 | 
            +
                near_text: near_text,
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                # To use this parameter you must have created your schema by setting the `vectorizer:` property to 'multi2vec-clip' or 'img2vec-neural'
         | 
| 153 | 
            +
                # near_image: ...,
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                # hybrid: ...,
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                # bm25: ...,
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                # near_object: ...,
         | 
| 160 | 
            +
            )
         | 
| 161 | 
            +
            ```
         | 
| 162 | 
            +
             | 
| 137 163 | 
             
            ## Development
         | 
| 138 164 |  | 
| 139 165 | 
             
            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.
         | 
    
        data/lib/weaviate/client.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 3 | 
             
            require "faraday"
         | 
| 4 | 
            +
            require "graphlient"
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Weaviate
         | 
| 6 7 | 
             
              class Client
         | 
| @@ -47,6 +48,26 @@ module Weaviate | |
| 47 48 | 
             
                  @objects ||= Weaviate::Objects.new(client: self)
         | 
| 48 49 | 
             
                end
         | 
| 49 50 |  | 
| 51 | 
            +
                def query
         | 
| 52 | 
            +
                  @query ||= Weaviate::Query.new(client: self)
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def graphql
         | 
| 56 | 
            +
                  headers = {}
         | 
| 57 | 
            +
                  if model_service && model_service_api_key
         | 
| 58 | 
            +
                    headers[API_KEY_HEADERS[model_service]] = model_service_api_key
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  @graphql ||= Graphlient::Client.new(
         | 
| 62 | 
            +
                    "#{scheme}://#{host}/#{API_VERSION}/graphql",
         | 
| 63 | 
            +
                    headers: headers,
         | 
| 64 | 
            +
                    http_options: {
         | 
| 65 | 
            +
                      read_timeout: 20,
         | 
| 66 | 
            +
                      write_timeout: 30
         | 
| 67 | 
            +
                    }
         | 
| 68 | 
            +
                  )
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 50 71 | 
             
                def connection
         | 
| 51 72 | 
             
                  @connection ||= Faraday.new(url: "#{scheme}://#{host}/#{API_VERSION}/") do |faraday|
         | 
| 52 73 | 
             
                    faraday.request :json
         | 
    
        data/lib/weaviate/objects.rb
    CHANGED
    
    | @@ -23,7 +23,7 @@ module Weaviate | |
| 23 23 | 
             
                    req.params["sort"] = sort unless sort.nil?
         | 
| 24 24 | 
             
                    req.params["order"] = order unless order.nil?
         | 
| 25 25 | 
             
                  end
         | 
| 26 | 
            -
                  Response::Collection.from_response(response, key: "objects", type: Response::Object)
         | 
| 26 | 
            +
                  Response::Collection.from_response(response.body, key: "objects", type: Response::Object)
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                # Create a new data object. The provided meta-data and schema values are validated.
         | 
| @@ -52,7 +52,7 @@ module Weaviate | |
| 52 52 | 
             
                  end
         | 
| 53 53 |  | 
| 54 54 | 
             
                  if response.success?
         | 
| 55 | 
            -
                    Response::Collection.from_response(response, type: Response::Object)
         | 
| 55 | 
            +
                    Response::Collection.from_response(response.body, type: Response::Object)
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 | 
             
                end
         | 
| 58 58 |  | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Weaviate
         | 
| 4 | 
            +
              class Query < Base
         | 
| 5 | 
            +
                def get(
         | 
| 6 | 
            +
                  class_name:,
         | 
| 7 | 
            +
                  fields:,
         | 
| 8 | 
            +
                  limit: nil,
         | 
| 9 | 
            +
                  near_text: nil
         | 
| 10 | 
            +
                )
         | 
| 11 | 
            +
                  params = {}
         | 
| 12 | 
            +
                  params["nearText"] = near_text unless near_text.nil?
         | 
| 13 | 
            +
                  params["limit"] = limit unless limit.nil?
         | 
| 14 | 
            +
                  # TODO implement the rest of the API params
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  response = client.graphql.execute(get_query(class_name, params, fields), near_text: near_text)
         | 
| 17 | 
            +
                  response.data.get.send(class_name.downcase)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                private
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def get_query(class_name, params, fields)
         | 
| 23 | 
            +
                  client.graphql.parse do
         | 
| 24 | 
            +
                    query do
         | 
| 25 | 
            +
                      Get do
         | 
| 26 | 
            +
                        public_send(class_name, params) do
         | 
| 27 | 
            +
                          fields.map do |field|
         | 
| 28 | 
            +
                            public_send(field)
         | 
| 29 | 
            +
                          end
         | 
| 30 | 
            +
                        end
         | 
| 31 | 
            +
                      end
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
| @@ -5,8 +5,7 @@ module Weaviate | |
| 5 5 | 
             
                class Collection
         | 
| 6 6 | 
             
                  attr_reader :data, :total_results
         | 
| 7 7 |  | 
| 8 | 
            -
                  def self.from_response( | 
| 9 | 
            -
                    body = response.body
         | 
| 8 | 
            +
                  def self.from_response(body, type:, key: nil)
         | 
| 10 9 | 
             
                    new(
         | 
| 11 10 | 
             
                      data: (key.nil? ? body : body[key]).map { |attrs| type.new(attrs) }
         | 
| 12 11 | 
             
                      # TODO: Integrate and use the totalResults from the response.
         | 
    
        data/lib/weaviate/schema.rb
    CHANGED
    
    | @@ -7,7 +7,7 @@ module Weaviate | |
| 7 7 | 
             
                # Dumps the current Weaviate schema. The result contains an array of objects.
         | 
| 8 8 | 
             
                def list
         | 
| 9 9 | 
             
                  response = client.connection.get(PATH)
         | 
| 10 | 
            -
                  Response::Collection.from_response(response, key: "classes", type: Response::Class)
         | 
| 10 | 
            +
                  Response::Collection.from_response(response.body, key: "classes", type: Response::Class)
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 13 | 
             
                # Get a single class from the schema
         | 
    
        data/lib/weaviate/version.rb
    CHANGED
    
    
    
        data/lib/weaviate.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: weaviate-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrei Bondarev
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-03- | 
| 11 | 
            +
            date: 2023-03-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -24,6 +24,20 @@ dependencies: | |
| 24 24 | 
             
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '2.7'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: graphlient
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 0.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: 0.7.0
         | 
| 27 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 42 | 
             
              name: pry-byebug
         | 
| 29 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -60,6 +74,7 @@ files: | |
| 60 74 | 
             
            - lib/weaviate/meta.rb
         | 
| 61 75 | 
             
            - lib/weaviate/objects.rb
         | 
| 62 76 | 
             
            - lib/weaviate/oidc.rb
         | 
| 77 | 
            +
            - lib/weaviate/query.rb
         | 
| 63 78 | 
             
            - lib/weaviate/response/base.rb
         | 
| 64 79 | 
             
            - lib/weaviate/response/class.rb
         | 
| 65 80 | 
             
            - lib/weaviate/response/collection.rb
         |