pinecone 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ba29ca8e87743d1fb9641ecdd722ac1c18cc55f06d0314dd688d0474da48257
4
- data.tar.gz: 29660db1e94027e9701999487c022f8b7ff281881e4166db05d972e55d054630
3
+ metadata.gz: e278d71fc695cd9e6f0297cc0dd5e8fb6ec144cd1e599d394bb34f25dbcb4783
4
+ data.tar.gz: ecb5b591b5a8b3564c5b2790fbadf99f253925d60e25934f9fbcfec67a09b919
5
5
  SHA512:
6
- metadata.gz: ad82b573c181757f03ea1df9f7f3343561d50899e884177ea6924941c361dce337e32288a66c2f47828fe39ac7ca14753550e005c7ae7c47448f31aa4c684da0
7
- data.tar.gz: beee5be5eff743e68e65d8df4ea51b4f9dceeec1f761ff08506b8357787f0dc1c65e68da0ca369ed51ae6ea3ed838fd9134d567b5223b4cf6e44cc071a79a0f5
6
+ metadata.gz: 9b09cd21a242d82794ed5f6af15f9bd0f190d872f48a9ddce66e80eea9c9bdce191c09185d6e9d62058ca01d4ee32a98b2c4ee10460a4e726261eec1093d9da6
7
+ data.tar.gz: c3254d2c223308f0a0c56bb0c4b4f08fae0a807682f1ab502b7a622ebdea63a2cd719a691a1589d61888485938e5750fd4ea7d9b4e003d95d2115e9543e97a6d
@@ -18,6 +18,10 @@ module Pinecone
18
18
  Pinecone::Index.new.delete(index_name)
19
19
  end
20
20
 
21
+ def configure_index(index_name, body)
22
+ Pinecone::Index.new.configure(index_name, body)
23
+ end
24
+
21
25
  def list_collections
22
26
  Pinecone::Collection.new.list
23
27
  end
@@ -28,6 +28,11 @@ module Pinecone
28
28
  self.class.delete("/databases/#{index_name}", options)
29
29
  end
30
30
 
31
+ def configure(index_name, body)
32
+ payload = options.merge(body: body.to_json)
33
+ self.class.patch("/databases/#{index_name}", payload)
34
+ end
35
+
31
36
  def options
32
37
  {
33
38
  headers: @headers,
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-struct"
4
+ require "dry-validation"
5
+
6
+ module Types
7
+ include Dry.Types()
8
+
9
+ StringOrNumberOrBoolean = Dry::Types['string'] | Dry::Types['integer'] | Dry::Types['float'] | Dry::Types['bool']
10
+ StringOrNumber = Dry::Types['string'] | Dry::Types['integer'] | Dry::Types['float']
11
+ Number = Dry::Types['integer'] | Dry::Types['float']
12
+ end
13
+
14
+ module Pinecone
15
+ class Vector
16
+ class Filter < Dry::Struct
17
+ class FilterContract < Dry::Validation::Contract
18
+ schema do
19
+ optional(:$and).filled(:array)
20
+ optional(:$or).filled(:array)
21
+ optional(:$eq).filled(Types::StringOrNumberOrBoolean)
22
+ optional(:$ne).filled(Types::StringOrNumberOrBoolean)
23
+ optional(:$gt).filled(Types::Number)
24
+ optional(:$gte).filled(Types::Number)
25
+ optional(:$lt).filled(Types::Number)
26
+ optional(:$lte).filled(Types::Number)
27
+ optional(:$in).filled(:array).each(Types::StringOrNumber)
28
+ optional(:$nin).filled(:array).each(Types::StringOrNumber)
29
+ end
30
+
31
+ rule(:$and) do
32
+ if key?
33
+ key(:$and).failure("'$any' must be an array") unless value.is_a?(Array)
34
+
35
+ value.each do |v|
36
+ key(:$and).failure("'$any' must be an array of filters") unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
37
+ end
38
+ end
39
+ end
40
+
41
+ rule(:$or) do
42
+ if key?
43
+ key(:$or).failure("'$or' must be an array") unless value.is_a?(Array)
44
+
45
+ value.each do |v|
46
+ key(:$or).failure("'$or' must be an array of filters") unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
47
+ end
48
+ end
49
+ end
50
+
51
+ def to_filter(input)
52
+ return false unless input.is_a?(Hash)
53
+ return Filter.new(input)
54
+ end
55
+ end
56
+
57
+ def self.new(input)
58
+ validation = FilterContract.new.call(input)
59
+ if validation.success?
60
+ super(input)
61
+ else
62
+ raise ArgumentError.new(validation.errors.to_h.inspect)
63
+ end
64
+ end
65
+
66
+ def self.default?
67
+ nil
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-struct"
4
+ require "dry-validation"
5
+
6
+ require "pinecone/vector/filter"
7
+ require "pinecone/vector/sparse_vector"
8
+
9
+ module Types
10
+ include Dry.Types()
11
+ end
12
+
13
+ module Pinecone
14
+ class Vector
15
+ class Query < Dry::Struct
16
+ class QueryContract < Dry::Validation::Contract
17
+ params do
18
+ optional(:vector).filled(:array)
19
+ optional(:id).filled(:string)
20
+ end
21
+
22
+ rule(:vector, :id) do
23
+ if !values[:vector].nil? && !values[:id].nil?
24
+ key(:vector).failure("Only one of vector or id can be specified")
25
+ key(:id).failure("Only one of vector or id can be specified")
26
+ end
27
+ end
28
+ end
29
+
30
+ schema schema.strict
31
+
32
+ attribute :namespace, Dry::Types['string'].default("")
33
+ attribute :include_values, Dry::Types['bool'].default(false)
34
+ attribute :include_metadata, Dry::Types['bool'].default(true)
35
+ attribute :top_k, Dry::Types['integer'].default(10)
36
+ attribute? :vector, Dry::Types['array'].of(Dry::Types['float'] | Dry::Types['integer'])
37
+ # Disabled contract since it wasn't carrying forward attributes to to_json
38
+ # See failing test in query_spec.rb
39
+ # attribute? :filter, Filter
40
+ attribute? :filter, Dry::Types['hash']
41
+ attribute? :sparse_vector, SparseVector
42
+ attribute? :id, Dry::Types['string']
43
+
44
+ def self.new(input)
45
+ validation = QueryContract.new.call(input)
46
+ if validation.success?
47
+ super(input)
48
+ else
49
+ raise ArgumentError.new(validation.errors.to_h.inspect)
50
+ end
51
+ end
52
+
53
+ def to_json
54
+ to_h.map do |key, value|
55
+ [key.to_s.split("_").map.with_index do |word, index|
56
+ index == 0 ? word : word.capitalize
57
+ end.join.to_sym, value]
58
+ end.to_h.to_json
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-struct"
4
+ require "dry-validation"
5
+
6
+ module Types
7
+ include Dry.Types()
8
+ end
9
+
10
+ module Pinecone
11
+ class Vector
12
+ class SparseVector < Dry::Struct
13
+ class SparseVectorContract < Dry::Validation::Contract
14
+ params do
15
+ required(:indices).filled(:array)
16
+ required(:values).filled(:array)
17
+ end
18
+
19
+ rule(:indices, :values) do
20
+ unless values[:indices].size === values[:values].size
21
+ key(:indices).failure("Indices and values must be the same size")
22
+ key(:values).failure("Indices and values must be the same size")
23
+ end
24
+ end
25
+ end
26
+
27
+ attribute :indices, Dry::Types['array'].of(Dry::Types['integer'])
28
+ attribute :values, Dry::Types['array'].of(Dry::Types['float'] | Dry::Types['integer'])
29
+
30
+ def self.new(input)
31
+ validation = SparseVectorContract.new.call(input)
32
+ if validation.success?
33
+ super(input)
34
+ else
35
+ raise ArgumentError.new(validation.errors.to_h.inspect)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -55,6 +55,15 @@ module Pinecone
55
55
  self.class.post('/vectors/update', payload)
56
56
  end
57
57
 
58
+ def describe_index_stats(filter: {})
59
+ payload = if filter.empty?
60
+ options
61
+ else
62
+ options.merge(body: {filter: filter}.to_json)
63
+ end
64
+ self.class.post('/describe_index_stats', payload)
65
+ end
66
+
58
67
 
59
68
  def options
60
69
  {
@@ -1,3 +1,3 @@
1
1
  module Pinecone
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinecone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Carleton
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: dry-validation
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.9.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.9.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dotenv
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +162,9 @@ files:
162
162
  - lib/pinecone/collection.rb
163
163
  - lib/pinecone/index.rb
164
164
  - lib/pinecone/vector.rb
165
+ - lib/pinecone/vector/filter.rb
166
+ - lib/pinecone/vector/query.rb
167
+ - lib/pinecone/vector/sparse_vector.rb
165
168
  - lib/pinecone/version.rb
166
169
  homepage: https://rubygems.org/gems/pinecone
167
170
  licenses: