Sha256: 533fee3ad86ecb83b1b28fce01a5cd171186d031461e952697de5aeccc272424

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "dry-struct"
require "dry-validation"

require "roseflow/pinecone/object"
require "roseflow/pinecone/vectors/common"

module Types
  include Dry.Types()
end

module Roseflow
  module Pinecone
    class Vector
      class SparseVector < PineconeObject
        include Roseflow::Pinecone::Vectors::Common

        class SparseVectorContract < Dry::Validation::Contract
          params do
            required(:indices).filled(:array)
            required(:values).filled(:array)
          end

          rule(:indices, :values) do
            unless values[:indices].size === values[:values].size
              key(:indices).failure("Indices and values must be the same size")
              key(:values).failure("Indices and values must be the same size")
            end
          end
        end

        contract_object SparseVectorContract

        attribute :indices, Dry::Types['array'].of(Dry::Types['integer'])
        attribute :values, Dry::Types['array'].of(Dry::Types['float'] | Dry::Types['integer'])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roseflow-pinecone-0.1.0 lib/roseflow/pinecone/vectors/sparse_vector.rb