Skip to content

Commit

Permalink
Adding Standard Formatting (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScotterC authored Jan 29, 2024
1 parent 639b24f commit 23a634a
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 234 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run StandardRB Lint
run: bundle exec standardrb
- name: Run tests
run: bundle exec rspec
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
source "https://rubygems.org"

gemspec

gem "dotenv", "~> 2.8"
gem "awesome_print", "~> 1.9"
gem "rake", "~> 13.0"
gem "debug", "~> 1.7"
gem "rspec", "~> 3.12"
gem "webmock", "~> 3.14"
gem "vcr", "~> 6.1"
gem "standard", "~> 1.33"
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GEM
specs:
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
awesome_print (1.9.2)
concurrent-ruby (1.2.2)
crack (0.4.5)
Expand Down Expand Up @@ -65,10 +66,20 @@ GEM
io-console (0.6.0)
irb (1.6.4)
reline (>= 0.3.0)
json (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
mini_mime (1.1.2)
multi_xml (0.6.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
public_suffix (5.0.1)
racc (1.7.3)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.9.0)
reline (0.3.3)
io-console (~> 0.5)
rexml (3.2.5)
Expand All @@ -85,6 +96,36 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (1.13.0)
standard (1.33.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.59.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
unicode-display_width (2.5.0)
vcr (6.1.0)
webmock (3.18.1)
addressable (>= 2.8.0)
Expand All @@ -105,6 +146,7 @@ DEPENDENCIES
pinecone!
rake (~> 13.0)
rspec (~> 3.12)
standard (~> 1.33)
vcr (~> 6.1)
webmock (~> 3.14)

Expand Down
8 changes: 5 additions & 3 deletions lib/pinecone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

module Pinecone
class ConfigurationError < StandardError; end

class IndexNotFoundError < StandardError; end

class Configuration
attr_writer :api_key, :base_uri, :environment

def initialize
@api_key = nil
@api_key = nil
@environment = nil
@base_uri = nil
@base_uri = nil
end

def api_key
Expand Down Expand Up @@ -48,4 +50,4 @@ def self.configuration
def self.configure
yield(configuration)
end
end
end
2 changes: 1 addition & 1 deletion lib/pinecone/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def index(index_name)
Pinecone::Vector.new(index_name)
end
end
end
end
10 changes: 5 additions & 5 deletions lib/pinecone/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def initialize
@headers = {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Api-Key" => Pinecone.configuration.api_key,
"Api-Key" => Pinecone.configuration.api_key
}
end

def list
self.class.get('/collections', options)
self.class.get("/collections", options)
end

def describe(collection_name)
Expand All @@ -22,7 +22,7 @@ def describe(collection_name)

def create(body)
payload = options.merge(body: body.to_json)
self.class.post('/collections', payload)
self.class.post("/collections", payload)
end

def delete(collection_name)
Expand All @@ -31,8 +31,8 @@ def delete(collection_name)

def options
{
headers: @headers,
headers: @headers
}
end
end
end
end
12 changes: 6 additions & 6 deletions lib/pinecone/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ def initialize
@headers = {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Api-Key" => Pinecone.configuration.api_key,
"Api-Key" => Pinecone.configuration.api_key
}
end

def list
self.class.get('/databases', options)
self.class.get("/databases", options)
end

def describe(index_name)
self.class.get("/databases/#{index_name}", options)
end

def create(body)
payload = options.merge(body: body.to_json)
self.class.post('/databases', payload)
self.class.post("/databases", payload)
end

def delete(index_name)
Expand All @@ -35,8 +35,8 @@ def configure(index_name, body)

def options
{
headers: @headers,
headers: @headers
}
end
end
end
end
19 changes: 9 additions & 10 deletions lib/pinecone/vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ def initialize(index_name)
@headers = {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Api-Key" => Pinecone.configuration.api_key,
"Api-Key" => Pinecone.configuration.api_key
}
end

def delete(namespace: "", ids: [], delete_all: false, filter: {})
inputs = {
"namespace": namespace,
"ids": ids,
"deleteAll": delete_all,
"filter": filter,
namespace: namespace,
ids: ids,
deleteAll: delete_all,
filter: filter
}

inputs.delete(:filter) if delete_all || ids.any?
payload = options.merge(body: inputs.to_json)
self.class.post("#{@base_uri}/vectors/delete", payload)
end

def fetch(namespace: "", ids: [])
query_string = URI.encode_www_form({ namespace: namespace, ids: ids})
query_string = URI.encode_www_form({namespace: namespace, ids: ids})
self.class.get("#{@base_uri}/vectors/fetch?#{query_string}", options)
end

Expand All @@ -49,7 +49,7 @@ def query(query)

def update(id:, values: [], sparse_values: {indices: [], values: []}, set_metadata: {}, namespace: "")
inputs = {
"id": id
id: id
}
inputs["values"] = values unless values.empty?
inputs["sparseValues"] = sparse_values unless sparse_values[:indices].empty? || sparse_values[:values].empty?
Expand All @@ -69,10 +69,9 @@ def describe_index_stats(filter: {})
self.class.post("#{@base_uri}/describe_index_stats", payload)
end


def options
{
headers: @headers,
headers: @headers
}
end

Expand Down
10 changes: 5 additions & 5 deletions lib/pinecone/vector/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
module Types
include Dry.Types()

StringOrNumberOrBoolean = Dry::Types['string'] | Dry::Types['integer'] | Dry::Types['float'] | Dry::Types['bool']
StringOrNumber = Dry::Types['string'] | Dry::Types['integer'] | Dry::Types['float']
Number = Dry::Types['integer'] | Dry::Types['float']
StringOrNumberOrBoolean = Dry::Types["string"] | Dry::Types["integer"] | Dry::Types["float"] | Dry::Types["bool"]
StringOrNumber = Dry::Types["string"] | Dry::Types["integer"] | Dry::Types["float"]
Number = Dry::Types["integer"] | Dry::Types["float"]
end

module Pinecone
Expand Down Expand Up @@ -50,7 +50,7 @@ class FilterContract < Dry::Validation::Contract

def to_filter(input)
return false unless input.is_a?(Hash)
return Filter.new(input)
Filter.new(input)
end
end

Expand All @@ -68,4 +68,4 @@ def self.default?
end
end
end
end
end
20 changes: 10 additions & 10 deletions lib/pinecone/vector/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class QueryContract < Dry::Validation::Contract

schema schema.strict

attribute :namespace, Dry::Types['string'].default("")
attribute :include_values, Dry::Types['bool'].default(false)
attribute :include_metadata, Dry::Types['bool'].default(true)
attribute :top_k, Dry::Types['integer'].default(10)
attribute? :vector, Dry::Types['array'].of(Dry::Types['float'] | Dry::Types['integer'])
attribute :namespace, Dry::Types["string"].default("")
attribute :include_values, Dry::Types["bool"].default(false)
attribute :include_metadata, Dry::Types["bool"].default(true)
attribute :top_k, Dry::Types["integer"].default(10)
attribute? :vector, Dry::Types["array"].of(Dry::Types["float"] | Dry::Types["integer"])
# Disabled contract since it wasn't carrying forward attributes to to_json
# See failing test in query_spec.rb
# attribute? :filter, Filter
attribute? :filter, Dry::Types['hash']
# attribute? :filter, Filter
attribute? :filter, Dry::Types["hash"]
attribute? :sparse_vector, SparseVector
attribute? :id, Dry::Types['string']
attribute? :id, Dry::Types["string"]

def self.new(input)
validation = QueryContract.new.call(input)
Expand All @@ -53,10 +53,10 @@ def self.new(input)
def to_json
to_h.map do |key, value|
[key.to_s.split("_").map.with_index do |word, index|
index == 0 ? word : word.capitalize
(index == 0) ? word : word.capitalize
end.join.to_sym, value]
end.to_h.to_json
end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/pinecone/vector/sparse_vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SparseVectorContract < Dry::Validation::Contract
end
end

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

def self.new(input)
validation = SparseVectorContract.new.call(input)
Expand All @@ -37,4 +37,4 @@ def self.new(input)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/pinecone/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pinecone
VERSION = "0.1.71".freeze
end
end
26 changes: 9 additions & 17 deletions pinecone.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
require_relative "lib/pinecone/version"

Gem::Specification.new do |s|
s.name = "pinecone"
s.version = Pinecone::VERSION
s.summary = "Ruby client library for Pinecone Vector DB"
s.name = "pinecone"
s.version = Pinecone::VERSION
s.summary = "Ruby client library for Pinecone Vector DB"
s.description = "Ruby client library which includes index and vector operations to upload embeddings into Pinecone and do similarity searches on them."
s.authors = ["Scott Carleton"]
s.email = "[email protected]"
s.files = Dir["lib/pinecone.rb", "lib/pinecone/**/*.rb"]
s.homepage = "https://rubygems.org/gems/pinecone"
s.metadata = {"source_code_uri" => "https://github.com/ScotterC/pinecone"}
s.license = "MIT"
s.authors = ["Scott Carleton"]
s.email = "[email protected]"
s.files = Dir["lib/pinecone.rb", "lib/pinecone/**/*.rb"]
s.homepage = "https://rubygems.org/gems/pinecone"
s.metadata = {"source_code_uri" => "https://github.com/ScotterC/pinecone"}
s.license = "MIT"

s.add_dependency "httparty", "~> 0.21.0"
s.add_dependency "dry-struct", "~> 1.6.0"
s.add_dependency "dry-validation", "~> 1.10.0"

s.add_development_dependency "dotenv", "~> 2.8"
s.add_development_dependency "awesome_print", '~> 1.9'
s.add_development_dependency "rake", "~> 13.0"
s.add_development_dependency "debug", "~> 1.7"
s.add_development_dependency "rspec", "~> 3.12"
s.add_development_dependency "webmock", "~> 3.14"
s.add_development_dependency "vcr", "~> 6.1"
end
Loading

0 comments on commit 23a634a

Please sign in to comment.