pinecone 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/pinecone.rb +125 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9de142f1852fd8049b7a1c35466e51b45564a3a3a9dcfb102c9347407f53e1e9
4
+ data.tar.gz: 4cce7e39f6b2c16885059341f19ff5bafcd5745b76660131d4a35d380cd22cb9
5
+ SHA512:
6
+ metadata.gz: 19aac1527777be26bfec6e35f056b50029d1656bdc24f71912c8dfe5d9de5d19b0298c9a58767dacab39f6df4dd33ac736f1223151b309681850723122271a72
7
+ data.tar.gz: 26d1506aa12318845f02b2a60fcf2d10113b53459356ffc2239ede9b8ed53a1a6fcdd6c46ed10652ed674e8ab96d217e49f0c30c51c74602d297dcae12fe4bf4
data/lib/pinecone.rb ADDED
@@ -0,0 +1,125 @@
1
+ require 'httparty'
2
+
3
+ # Usage
4
+ #
5
+ # pinecone = Pinecone.new
6
+ # pinecone.upsert(Vector Hash)
7
+ # pinecone.query(Vector Array)
8
+
9
+ class Pinecone
10
+ class ConfigurationError < StandardError; end
11
+ class Configuration
12
+ attr_writer :api_key, :base_uri
13
+
14
+ def initialize
15
+ @api_key = nil
16
+ @base_uri = nil
17
+ end
18
+
19
+ def api_key
20
+ return @api_key if @api_key
21
+
22
+ raise ConfigurationError, "Pinecone API key not set"
23
+ end
24
+
25
+ def base_uri
26
+ return @base_uri if @base_uri
27
+
28
+ raise ConfigurationError, "Pinecone domain not set"
29
+ end
30
+ end
31
+
32
+ include HTTParty
33
+
34
+ class << self
35
+ attr_writer :configuration
36
+ end
37
+
38
+ def self.configuration
39
+ @configuration ||= Pinecone::Configuration.new
40
+ end
41
+
42
+ def self.configure
43
+ yield(configuration)
44
+ end
45
+
46
+ def initialize
47
+ self.class.base_uri Pinecone.configuration.base_uri
48
+ @headers = {
49
+ "Content-Type" => "application/json",
50
+ "Accept" => "application/json",
51
+ "Api-Key" => Pinecone.configuration.api_key,
52
+ }
53
+ end
54
+
55
+ # # Post Upsert
56
+ # # The Upsert operation inserts or updates vectors in a namespace.
57
+ # https://index_name-project_id.svc.environment.pinecone.io/vectors/upsert
58
+ def upsert(body)
59
+ payload = options.merge(body: body.to_json)
60
+ self.class.post('/vectors/upsert', payload)
61
+ end
62
+
63
+ # # POST Query
64
+ # https://index_name-project_id.svc.environment.pinecone.io/query
65
+ # vector is an array of floats
66
+ def query(vector)
67
+ defaults = {
68
+ "includeValues": false,
69
+ "includeMetadata": true,
70
+ "topK": 5,
71
+ "vector": vector
72
+ }.to_json
73
+ payload = options.merge(body: defaults)
74
+ self.class.post('/query', payload)
75
+ end
76
+
77
+ def options
78
+ {
79
+ headers: @headers,
80
+ }
81
+ end
82
+ end
83
+
84
+ # Vector Operations
85
+
86
+ # # GET Describe Index Stats
87
+ # https://index_name-project_id.svc.environment.pinecone.io/describe_index_stats
88
+
89
+ # # POST Describe Index Stats
90
+ # https://index_name-project_id.svc.environment.pinecone.io/describe_index_stats
91
+
92
+ # # DELETE Delete Vectors
93
+ # https://index_name-project_id.svc.environment.pinecone.io/vectors/delete
94
+
95
+ # # POST Delete Vectors
96
+ # # The Delete operation deletes vectors, by id, from a single namespace.
97
+ # https://index_name-project_id.svc.environment.pinecone.io/vectors/delete
98
+
99
+ # # GET Fetch
100
+ # # The Fetch operation looks up and returns vectors, by ID, from a single namespace.
101
+ # https://index_name-project_id.svc.environment.pinecone.io/vectors/fetch
102
+
103
+ # # POST Update
104
+ # # The Update operation updates vector in a namespace.
105
+ # # If a value is included, it will overwrite the previous value.
106
+ # https://index_name-project_id.svc.environment.pinecone.io/vectors/update
107
+
108
+ # # GET list_collections
109
+ # https://controller.unknown.pinecone.io/collections
110
+
111
+ # POST create_collection
112
+
113
+ # GET describe_collection
114
+
115
+ # DELETE delete_collection
116
+
117
+ # GET list_indexes
118
+
119
+ # POST create_index
120
+
121
+ # GET describe_index
122
+
123
+ # DELETEdelete_index
124
+
125
+ # Patch configure_index
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinecone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Carleton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Enables ruby access to upsert and query vectors in Pinecone
14
+ email: scott@extrayarn.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/pinecone.rb
20
+ homepage: https://rubygems.org/gems/pinecone
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ source_code_uri: https://github.com/ScotterC/pinecone
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.4.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Ruby client library for Pinecone Vector DB
44
+ test_files: []