pinecone 1.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e5f89bdb821f056dde85c82168420d575599d116508b083fb987ea7b3b60da
4
- data.tar.gz: b4d1da67d606505ca251db63cc63a9077d363e92425ddfeb4ea55263af30aac6
3
+ metadata.gz: bd51f81f28189542ff84a77216c9d2dae42d1946733415ef804a955eb7bcf7e0
4
+ data.tar.gz: 548e9a37125b33ed6d19a3e63f18365608810f55a557ba6d95d16a1cc3a31f93
5
5
  SHA512:
6
- metadata.gz: c429ec85b521a797a73597a6cba93b77e4892e84176064079367605c8436b15709aa03fd7ab563240c96bc8406c6b805c3d43bb7cc7f91c8c7ad1b016724acfe
7
- data.tar.gz: 749c157e0650086c2365023cf8a9626ef04fd4bce9b5eac886de5007480c64318aa0c3312ea1795713ca08475c5e2f5396130aaabe2bb84d5d853d52969c12d1
6
+ metadata.gz: 2c13dad3d6c0f20f092369fc92c87fb26d2aa0345d02355b06945565959303e5717bb72893e5307d270cc6a4b6dca7b3a2241cbdff1aad2cecaba8ff0f0155cf
7
+ data.tar.gz: f75288c1975136acd8125d5bd74b46d80e8b756a6c3e8a9f2e329d5e973cf7af2af076993142e4153e46a0e8299dab0c4f68e2e07c372b3fe53b63525c7b357f
@@ -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
- Pinecone::Vector.new(index_name)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pinecone
2
4
  class Collection
3
5
  include HTTParty
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pinecone
2
4
  class Index
3
5
  include HTTParty
@@ -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
- key(:$and).failure("'$any' must be an array of filters") unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
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
- key(:$or).failure("'$or' must be an array of filters") unless v.is_a?(Filter) || to_filter(v).is_a?(Filter)
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
- if validation.success?
60
- super
61
- else
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
- if validation.success?
47
- super
48
- else
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.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
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
- if validation.success?
33
- super
34
- else
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
@@ -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
- @base_uri = set_base_uri(index_name)
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",
@@ -114,7 +131,7 @@ module Pinecone
114
131
 
115
132
  def describe_index_stats(filter: {})
116
133
  payload = if filter.empty?
117
- options
134
+ options.merge(body: {}.to_json)
118
135
  else
119
136
  options.merge(body: {filter: filter}.to_json)
120
137
  end
@@ -130,9 +147,10 @@ module Pinecone
130
147
  private
131
148
 
132
149
  # https://index_name-project_id.svc.environment.pinecone.io
133
- def set_base_uri(index_name)
150
+ def set_fallback_base_uri(index_name)
134
151
  index_description = Pinecone::Index.new.describe(index_name)
135
152
  raise Pinecone::IndexNotFoundError, "Index #{index_name} does not exist" if index_description.code != 200
153
+
136
154
  uri = index_description.parsed_response["host"]
137
155
  "https://#{uri}"
138
156
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Pinecone
2
- VERSION = "1.1.0".freeze
4
+ VERSION = "1.2.1"
3
5
  end
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.1.0
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: 2024-08-09 00:00:00.000000000 Z
10
+ date: 2025-06-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: httparty
13
+ name: dry-struct
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: 0.22.0
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: 0.22.0
25
+ version: '1.6'
27
26
  - !ruby/object:Gem::Dependency
28
- name: dry-struct
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.6.0
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.6.0
39
+ version: '1.10'
41
40
  - !ruby/object:Gem::Dependency
42
- name: dry-validation
41
+ name: httparty
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: 1.10.0
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: 1.10.0
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
@@ -89,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
87
  - !ruby/object:Gem::Version
90
88
  version: '0'
91
89
  requirements: []
92
- rubygems_version: 3.5.15
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: []