pinecone 1.0.1 → 1.2.1
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/lib/pinecone/client.rb +20 -2
- data/lib/pinecone/collection.rb +2 -0
- data/lib/pinecone/index.rb +2 -0
- data/lib/pinecone/response_parser.rb +3 -1
- data/lib/pinecone/vector/filter.rb +10 -7
- data/lib/pinecone/vector/query.rb +9 -11
- data/lib/pinecone/vector/sparse_vector.rb +3 -5
- data/lib/pinecone/vector.rb +74 -5
- data/lib/pinecone/version.rb +3 -1
- data/lib/pinecone.rb +10 -1
- metadata +13 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd51f81f28189542ff84a77216c9d2dae42d1946733415ef804a955eb7bcf7e0
|
4
|
+
data.tar.gz: 548e9a37125b33ed6d19a3e63f18365608810f55a557ba6d95d16a1cc3a31f93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c13dad3d6c0f20f092369fc92c87fb26d2aa0345d02355b06945565959303e5717bb72893e5307d270cc6a4b6dca7b3a2241cbdff1aad2cecaba8ff0f0155cf
|
7
|
+
data.tar.gz: f75288c1975136acd8125d5bd74b46d80e8b756a6c3e8a9f2e329d5e973cf7af2af076993142e4153e46a0e8299dab0c4f68e2e07c372b3fe53b63525c7b357f
|
data/lib/pinecone/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Pinecone
|
2
4
|
class Client
|
3
5
|
include HTTParty
|
@@ -40,8 +42,24 @@ module Pinecone
|
|
40
42
|
|
41
43
|
# This is a very confusing naming convention
|
42
44
|
# Pinecone's reference now delineates between 'control plane' and 'data plane' which we'll reflect eventually
|
43
|
-
def index(index_name)
|
44
|
-
|
45
|
+
def index(index_name = nil, host: nil)
|
46
|
+
# Direct host provided
|
47
|
+
return Pinecone::Vector.new(host: host) if host
|
48
|
+
|
49
|
+
# Use global host if configured
|
50
|
+
return Pinecone::Vector.new(host: Pinecone.configuration.host) if Pinecone.configuration.host
|
51
|
+
|
52
|
+
# Legacy: index name provided
|
53
|
+
if index_name
|
54
|
+
unless Pinecone.configuration.silence_deprecation_warnings?
|
55
|
+
warn "[DEPRECATED] client.index('name') is deprecated. Use client.index(host: 'host') for better performance."
|
56
|
+
end
|
57
|
+
return Pinecone::Vector.new(index_name)
|
58
|
+
end
|
59
|
+
|
60
|
+
# No host available
|
61
|
+
raise ArgumentError,
|
62
|
+
"No host provided. Set via Pinecone.configure { |c| c.host = 'host' } or client.index(host: 'host')"
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
data/lib/pinecone/collection.rb
CHANGED
data/lib/pinecone/index.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Pinecone
|
2
4
|
class ResponseParser < HTTParty::Parser
|
3
5
|
# standard:disable Naming/ConstantName
|
4
6
|
SupportedFormats = {
|
5
7
|
"application/json" => :json,
|
6
8
|
"text/plain" => :json
|
7
|
-
}
|
9
|
+
}.freeze
|
8
10
|
# standard:enable Naming/ConstantName
|
9
11
|
|
10
12
|
def json
|
@@ -33,7 +33,9 @@ module Pinecone
|
|
33
33
|
key(:$and).failure("'$any' must be an array") unless value.is_a?(Array)
|
34
34
|
|
35
35
|
value.each do |v|
|
36
|
-
|
36
|
+
unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
|
37
|
+
key(:$and).failure("'$any' must be an array of filters")
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -43,24 +45,25 @@ module Pinecone
|
|
43
45
|
key(:$or).failure("'$or' must be an array") unless value.is_a?(Array)
|
44
46
|
|
45
47
|
value.each do |v|
|
46
|
-
|
48
|
+
unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
|
49
|
+
key(:$or).failure("'$or' must be an array of filters")
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
55
|
def to_filter(input)
|
52
56
|
return false unless input.is_a?(Hash)
|
57
|
+
|
53
58
|
Filter.new(input)
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
57
62
|
def self.new(input)
|
58
63
|
validation = FilterContract.new.call(input)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
raise ArgumentError.new(validation.errors.to_h.inspect)
|
63
|
-
end
|
64
|
+
raise ArgumentError, validation.errors.to_h.inspect unless validation.success?
|
65
|
+
|
66
|
+
super
|
64
67
|
end
|
65
68
|
|
66
69
|
def self.default?
|
@@ -43,19 +43,17 @@ module Pinecone
|
|
43
43
|
|
44
44
|
def self.new(input)
|
45
45
|
validation = QueryContract.new.call(input)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise ArgumentError.new(validation.errors.to_h.inspect)
|
50
|
-
end
|
46
|
+
raise ArgumentError, validation.errors.to_h.inspect unless validation.success?
|
47
|
+
|
48
|
+
super
|
51
49
|
end
|
52
50
|
|
53
|
-
def to_json
|
54
|
-
to_h.
|
55
|
-
|
56
|
-
|
57
|
-
end.join.to_sym
|
58
|
-
end.
|
51
|
+
def to_json(*_args)
|
52
|
+
to_h.transform_keys do |key|
|
53
|
+
key.to_s.split("_").map.with_index do |word, index|
|
54
|
+
index.zero? ? word : word.capitalize
|
55
|
+
end.join.to_sym
|
56
|
+
end.to_json
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
@@ -29,11 +29,9 @@ module Pinecone
|
|
29
29
|
|
30
30
|
def self.new(input)
|
31
31
|
validation = SparseVectorContract.new.call(input)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
raise ArgumentError.new(validation.errors.to_h.inspect)
|
36
|
-
end
|
32
|
+
raise ArgumentError, validation.errors.to_h.inspect unless validation.success?
|
33
|
+
|
34
|
+
super
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/pinecone/vector.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "pinecone/vector/query"
|
2
4
|
require "pinecone/vector/filter"
|
3
5
|
require "pinecone/vector/sparse_vector"
|
6
|
+
require "json"
|
4
7
|
|
5
8
|
module Pinecone
|
6
9
|
class Vector
|
@@ -9,8 +12,22 @@ module Pinecone
|
|
9
12
|
|
10
13
|
attr_reader :base_uri
|
11
14
|
|
12
|
-
def initialize(index_name)
|
13
|
-
|
15
|
+
def initialize(index_name = nil, host: nil)
|
16
|
+
if host
|
17
|
+
# Direct host targeting (preferred)
|
18
|
+
@base_uri = if host.start_with?("http://", "https://")
|
19
|
+
host
|
20
|
+
elsif host.start_with?("localhost")
|
21
|
+
"http://#{host}" # Use HTTP for localhost
|
22
|
+
else
|
23
|
+
"https://#{host}" # Use HTTPS for production hosts
|
24
|
+
end
|
25
|
+
elsif index_name
|
26
|
+
# Legacy path: call describe_index
|
27
|
+
@base_uri = set_fallback_base_uri(index_name)
|
28
|
+
else
|
29
|
+
raise ArgumentError, "Must provide either index_name or host: parameter"
|
30
|
+
end
|
14
31
|
|
15
32
|
@headers = {
|
16
33
|
"Content-Type" => "application/json",
|
@@ -26,7 +43,6 @@ module Pinecone
|
|
26
43
|
deleteAll: delete_all,
|
27
44
|
filter: filter
|
28
45
|
}
|
29
|
-
|
30
46
|
inputs.delete(:filter) if delete_all || ids.any?
|
31
47
|
payload = options.merge(body: inputs.to_json)
|
32
48
|
self.class.post("#{@base_uri}/vectors/delete", payload)
|
@@ -37,6 +53,58 @@ module Pinecone
|
|
37
53
|
self.class.get("#{@base_uri}/vectors/fetch?#{query_string}", options)
|
38
54
|
end
|
39
55
|
|
56
|
+
def list(prefix: nil, limit: nil, namespace: nil, &block)
|
57
|
+
all_ids = []
|
58
|
+
pagination_token = nil
|
59
|
+
total_fetched = 0
|
60
|
+
|
61
|
+
loop do
|
62
|
+
current_limit = limit.nil? ? 100 : [limit - total_fetched, 100].min
|
63
|
+
|
64
|
+
response = list_paginated(
|
65
|
+
prefix: prefix,
|
66
|
+
limit: current_limit,
|
67
|
+
pagination_token: pagination_token,
|
68
|
+
namespace: namespace
|
69
|
+
)
|
70
|
+
|
71
|
+
break unless response.success?
|
72
|
+
|
73
|
+
results = response.parsed_response
|
74
|
+
ids = results["vectors"]&.map { |v| v["id"] } || []
|
75
|
+
|
76
|
+
if block
|
77
|
+
yield ids
|
78
|
+
else
|
79
|
+
all_ids.concat(ids)
|
80
|
+
end
|
81
|
+
|
82
|
+
total_fetched += ids.length
|
83
|
+
pagination_token = results.dig("pagination", "next")
|
84
|
+
|
85
|
+
break if ids.empty?
|
86
|
+
break if limit && total_fetched >= limit
|
87
|
+
break if pagination_token.nil? || pagination_token.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
if block
|
91
|
+
nil
|
92
|
+
else
|
93
|
+
limit ? all_ids.first(limit) : all_ids
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def list_paginated(prefix: nil, limit: nil, pagination_token: nil, namespace: nil)
|
98
|
+
query_params = {}
|
99
|
+
query_params["prefix"] = prefix if prefix
|
100
|
+
query_params["limit"] = limit if limit
|
101
|
+
query_params["paginationToken"] = pagination_token if pagination_token
|
102
|
+
query_params["namespace"] = namespace if namespace
|
103
|
+
|
104
|
+
query_string = URI.encode_www_form(query_params)
|
105
|
+
self.class.get("#{@base_uri}/vectors/list?#{query_string}", options)
|
106
|
+
end
|
107
|
+
|
40
108
|
def upsert(body)
|
41
109
|
payload = options.merge(body: body.to_json)
|
42
110
|
self.class.post("#{@base_uri}/vectors/upsert", payload)
|
@@ -63,7 +131,7 @@ module Pinecone
|
|
63
131
|
|
64
132
|
def describe_index_stats(filter: {})
|
65
133
|
payload = if filter.empty?
|
66
|
-
options
|
134
|
+
options.merge(body: {}.to_json)
|
67
135
|
else
|
68
136
|
options.merge(body: {filter: filter}.to_json)
|
69
137
|
end
|
@@ -79,9 +147,10 @@ module Pinecone
|
|
79
147
|
private
|
80
148
|
|
81
149
|
# https://index_name-project_id.svc.environment.pinecone.io
|
82
|
-
def
|
150
|
+
def set_fallback_base_uri(index_name)
|
83
151
|
index_description = Pinecone::Index.new.describe(index_name)
|
84
152
|
raise Pinecone::IndexNotFoundError, "Index #{index_name} does not exist" if index_description.code != 200
|
153
|
+
|
85
154
|
uri = index_description.parsed_response["host"]
|
86
155
|
"https://#{uri}"
|
87
156
|
end
|
data/lib/pinecone/version.rb
CHANGED
data/lib/pinecone.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "httparty"
|
2
4
|
|
3
5
|
require "pinecone/response_parser"
|
@@ -13,12 +15,15 @@ module Pinecone
|
|
13
15
|
class IndexNotFoundError < StandardError; end
|
14
16
|
|
15
17
|
class Configuration
|
16
|
-
attr_writer :api_key, :base_uri, :environment
|
18
|
+
attr_writer :api_key, :base_uri, :environment, :silence_deprecation_warnings
|
19
|
+
attr_accessor :host
|
17
20
|
|
18
21
|
def initialize
|
19
22
|
@api_key = nil
|
20
23
|
@environment = nil
|
21
24
|
@base_uri = nil
|
25
|
+
@host = nil
|
26
|
+
@silence_deprecation_warnings = false
|
22
27
|
end
|
23
28
|
|
24
29
|
def api_key
|
@@ -38,6 +43,10 @@ module Pinecone
|
|
38
43
|
|
39
44
|
raise ConfigurationError, "Pinecone environment not set"
|
40
45
|
end
|
46
|
+
|
47
|
+
def silence_deprecation_warnings?
|
48
|
+
@silence_deprecation_warnings
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
52
|
class << self
|
metadata
CHANGED
@@ -1,57 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinecone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Carleton
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-06-19 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: dry-struct
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: '1.6'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: '1.6'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-
|
27
|
+
name: dry-validation
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
32
|
+
version: '1.10'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
37
36
|
requirements:
|
38
37
|
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
39
|
+
version: '1.10'
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
41
|
+
name: httparty
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
46
|
+
version: 0.22.0
|
48
47
|
type: :runtime
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
51
|
- - "~>"
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
version: 0.22.0
|
55
54
|
description: Ruby client library which includes index and vector operations to upload
|
56
55
|
embeddings into Pinecone and do similarity searches on them.
|
57
56
|
email: scott@extrayarn.com
|
@@ -74,7 +73,6 @@ licenses:
|
|
74
73
|
- MIT
|
75
74
|
metadata:
|
76
75
|
source_code_uri: https://github.com/ScotterC/pinecone
|
77
|
-
post_install_message:
|
78
76
|
rdoc_options: []
|
79
77
|
require_paths:
|
80
78
|
- lib
|
@@ -82,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements:
|
83
81
|
- - ">="
|
84
82
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
83
|
+
version: '3'
|
86
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
85
|
requirements:
|
88
86
|
- - ">="
|
89
87
|
- !ruby/object:Gem::Version
|
90
88
|
version: '0'
|
91
89
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
93
|
-
signing_key:
|
90
|
+
rubygems_version: 3.6.2
|
94
91
|
specification_version: 4
|
95
92
|
summary: Ruby client library for Pinecone Vector DB
|
96
93
|
test_files: []
|