ruby-pinecone 0.1.1 → 0.1.3

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: 447e688337c17e18023d086c8804315bc1a099de3340c07671d65aae4cddebac
4
- data.tar.gz: 29d79c0ff8231503de054078444f25261887a23ce6c8e84ac946192e164ee3f7
3
+ metadata.gz: '02983788a34817547e0a83bafc90326efbd30972051d8443bac656748db51405'
4
+ data.tar.gz: 2deeb29347b525badc8f42cc4b7332868a15f5ed7e126c4331aab6c44da9c622
5
5
  SHA512:
6
- metadata.gz: a02a1a45d1091741e4cd390ff701b850e2a0b4bb391f156228890a69e265390838a7a572a4a8223404a6deee8d6d7ccac73715bd6d44c650e411029add55741b
7
- data.tar.gz: be810f94389decfd4548edd56ba81cbd390821c7d8ace6a510a41ad053a96c83dfb444637289cc3146997284d1bd5132898d3783553952c3029b21d2cb1a977d
6
+ metadata.gz: e8b7d45d58bb80b5ca42d1937b5843d45cd851cb080148edffd8ea96cc1099e6051dff230deb529ad9a51c4d63f31c2d70963fe2461a048e66c62eb3e274affa
7
+ data.tar.gz: 15f5d360ae79fd1bebed170c0322c5b48a3f77c59587f9bbfe97980897b074b908d234797c81ffdbaa5e889c751de5e8b62a83f6cad788c679acfc50b4ed1e96
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2023-03-10
4
+
5
+ - Index#Query to return parsed body
6
+ - Add QueryError
7
+ - Document Index#query
8
+
3
9
  ## [0.1.1] - 2023-03-08
4
10
 
5
11
  - Initial release
data/README.md CHANGED
@@ -111,6 +111,23 @@ index = client.indexes['my-index']
111
111
  index.vectors.delete(ids: ['id-1', 'id-2'])
112
112
  ```
113
113
 
114
+ #### Query
115
+ ```ruby
116
+ client = Pinecone::Client.new
117
+ index = client.indexes['my-index']
118
+
119
+ options = {
120
+ "includeValues": false,
121
+ "includeMetadata": true,
122
+ "topK": 10,
123
+ }
124
+ index.query([1.0, 1.0], options: options)
125
+ # => {"results"=>[], "matches"=>[{"id"=>"id-1", "score"=>1, "values"=>[], "metadata"=>{"type"=>"Thing"}}, {"id"=>"id-2", "score"=>0.89825207, "values"=>[], "metadata"=>{"type"=>"Thing"}}], "namespace"=>""}
126
+
127
+ index.query(nil, options: options)
128
+ # => raise QueryError (Query failed with 400 - {"code"=>3, "message"=>"No query provided", "details"=>[]})
129
+ ```
130
+
114
131
  ## Development
115
132
 
116
133
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -52,7 +52,7 @@ module Pinecone
52
52
  end
53
53
 
54
54
  def self.project_name
55
- Thread.current[:project_name] ||= Pinecone::Client.get(prefix: 'controller', path: '/actions/whoami')['project_name']
55
+ @project_name ||= Pinecone::Client.get(prefix: 'controller', path: '/actions/whoami')['project_name']
56
56
  end
57
57
 
58
58
  private_class_method def self.uri(path:, prefix: '')
@@ -1,5 +1,7 @@
1
1
  module Pinecone
2
2
  class Index
3
+ class QueryError < StandardError; end
4
+
3
5
  attr_accessor :name
4
6
  def initialize(name:)
5
7
  self.name = name
@@ -51,7 +53,11 @@ module Pinecone
51
53
  "vector": vector
52
54
  }
53
55
  body = defaults.merge(options)
54
- Pinecone::Client.json_post(prefix: prefix, path: '/query', parameters: body)
56
+ result = Pinecone::Client.json_post(prefix: prefix, path: '/query', parameters: body)
57
+ if !result.success?
58
+ raise QueryError.new("Query failed with #{result.response.code} - #{result.parsed_response.to_s}")
59
+ end
60
+ result.parsed_response
55
61
  end
56
62
 
57
63
  # # Get Show
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pinecone
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/pinecone.rb CHANGED
@@ -37,7 +37,7 @@ module Pinecone
37
37
  end
38
38
 
39
39
  def self.configuration
40
- Thread.current[:configuration] ||= Pinecone::Configuration.new
40
+ @configuration ||= Pinecone::Configuration.new
41
41
  end
42
42
 
43
43
  def self.configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pinecone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Hirst
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2023-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty