pinecone 0.1.5 → 0.1.71
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pinecone/vector/filter.rb +71 -0
- data/lib/pinecone/vector/query.rb +62 -0
- data/lib/pinecone/vector/sparse_vector.rb +40 -0
- data/lib/pinecone/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea82946a00b57e8d81af48478eee15aa1f0a17a22316d982878f1033aa57dc7f
|
4
|
+
data.tar.gz: 6db21ac3336d691bce0064f2c22a8e1f1f5ced9a725e5b76eec14a0752c5d488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6265199be8db129c2b428cebef001249cc6827819643e19421eea23727484c69bd7054eb0eb0e3a3fc9e332eecfadaed900a618664bdb8fc61f320b9e4833c6b
|
7
|
+
data.tar.gz: '0913f7fe938dddfc78a150847f73da703b375250d55150c1718ee408b0f8b2012321db7c10a4de2fbb5e6fdf8f15ec8a3e1c27067903b807a0574de85f2455da'
|
@@ -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
|
data/lib/pinecone/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinecone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.71
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Carleton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.6.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.6.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
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: 1.
|
47
|
+
version: 1.10.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: 1.
|
54
|
+
version: 1.10.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:
|