pinecone 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pinecone/client.rb +42 -0
- data/lib/pinecone/collection.rb +38 -0
- data/lib/pinecone/index.rb +37 -0
- data/lib/pinecone/vector.rb +75 -0
- data/lib/pinecone/version.rb +3 -0
- metadata +148 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ba29ca8e87743d1fb9641ecdd722ac1c18cc55f06d0314dd688d0474da48257
|
4
|
+
data.tar.gz: 29660db1e94027e9701999487c022f8b7ff281881e4166db05d972e55d054630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad82b573c181757f03ea1df9f7f3343561d50899e884177ea6924941c361dce337e32288a66c2f47828fe39ac7ca14753550e005c7ae7c47448f31aa4c684da0
|
7
|
+
data.tar.gz: beee5be5eff743e68e65d8df4ea51b4f9dceeec1f761ff08506b8357787f0dc1c65e68da0ca369ed51ae6ea3ed838fd9134d567b5223b4cf6e44cc071a79a0f5
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pinecone
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def list_indexes
|
6
|
+
Pinecone::Index.new.list
|
7
|
+
end
|
8
|
+
|
9
|
+
def describe_index(index_name)
|
10
|
+
Pinecone::Index.new.describe(index_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_index(body)
|
14
|
+
Pinecone::Index.new.create(body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_index(index_name)
|
18
|
+
Pinecone::Index.new.delete(index_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_collections
|
22
|
+
Pinecone::Collection.new.list
|
23
|
+
end
|
24
|
+
|
25
|
+
def describe_collection(collection_name)
|
26
|
+
Pinecone::Collection.new.describe(collection_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_collection(body)
|
30
|
+
Pinecone::Collection.new.create(body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_collection(collection_name)
|
34
|
+
Pinecone::Collection.new.delete(collection_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
# This is a very confusing naming convention
|
38
|
+
def index(index_name)
|
39
|
+
@index ||= Pinecone::Vector.new(index_name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Pinecone
|
2
|
+
class Collection
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.class.base_uri "https://controller.#{Pinecone.configuration.environment}.pinecone.io"
|
7
|
+
|
8
|
+
@headers = {
|
9
|
+
"Content-Type" => "application/json",
|
10
|
+
"Accept" => "application/json",
|
11
|
+
"Api-Key" => Pinecone.configuration.api_key,
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
self.class.get('/collections', options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def describe(collection_name)
|
20
|
+
self.class.get("/collections/#{collection_name}", options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(body)
|
24
|
+
payload = options.merge(body: body.to_json)
|
25
|
+
self.class.post('/collections', payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(collection_name)
|
29
|
+
self.class.delete("/collections/#{collection_name}", options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def options
|
33
|
+
{
|
34
|
+
headers: @headers,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Pinecone
|
2
|
+
class Index
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.class.base_uri "https://controller.#{Pinecone.configuration.environment}.pinecone.io"
|
7
|
+
@headers = {
|
8
|
+
"Content-Type" => "application/json",
|
9
|
+
"Accept" => "application/json",
|
10
|
+
"Api-Key" => Pinecone.configuration.api_key,
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
self.class.get('/databases', options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def describe(index_name)
|
19
|
+
self.class.get("/databases/#{index_name}", options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(body)
|
23
|
+
payload = options.merge(body: body.to_json)
|
24
|
+
self.class.post('/databases', payload)
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(index_name)
|
28
|
+
self.class.delete("/databases/#{index_name}", options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def options
|
32
|
+
{
|
33
|
+
headers: @headers,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "pinecone/vector/query"
|
2
|
+
require "pinecone/vector/filter"
|
3
|
+
require "pinecone/vector/sparse_vector"
|
4
|
+
|
5
|
+
module Pinecone
|
6
|
+
class Vector
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
def initialize(index_name)
|
10
|
+
self.class.base_uri set_base_uri(index_name)
|
11
|
+
|
12
|
+
@headers = {
|
13
|
+
"Content-Type" => "application/json",
|
14
|
+
"Accept" => "application/json",
|
15
|
+
"Api-Key" => Pinecone.configuration.api_key,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(namespace: "", ids: [], delete_all: false)
|
20
|
+
inputs = {
|
21
|
+
"namespace": namespace,
|
22
|
+
"ids": ids,
|
23
|
+
"deleteAll": delete_all,
|
24
|
+
}.to_json
|
25
|
+
payload = options.merge(body: inputs)
|
26
|
+
self.class.post('/vectors/delete', payload)
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch(namespace: "", ids: [])
|
30
|
+
query_string = URI.encode_www_form({ namespace: namespace, ids: ids})
|
31
|
+
self.class.get("/vectors/fetch?#{query_string}", options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def upsert(body)
|
35
|
+
payload = options.merge(body: body.to_json)
|
36
|
+
self.class.post('/vectors/upsert', payload)
|
37
|
+
end
|
38
|
+
|
39
|
+
def query(query)
|
40
|
+
object = query.is_a?(Pinecone::Vector::Query) ? query : Pinecone::Vector::Query.new(query)
|
41
|
+
payload = options.merge(body: object.to_json)
|
42
|
+
self.class.post('/query', payload)
|
43
|
+
end
|
44
|
+
|
45
|
+
def update(id:, values: [], sparse_values: {indices: [], values: []}, set_metadata: {}, namespace: "")
|
46
|
+
inputs = {
|
47
|
+
"id": id
|
48
|
+
}
|
49
|
+
inputs["values"] = values unless values.empty?
|
50
|
+
inputs["sparseValues"] = sparse_values unless sparse_values[:indices].empty? || sparse_values[:values].empty?
|
51
|
+
inputs["setMetadata"] = set_metadata unless set_metadata.empty?
|
52
|
+
inputs["namespace"] = namespace unless namespace.empty?
|
53
|
+
|
54
|
+
payload = options.merge(body: inputs.to_json)
|
55
|
+
self.class.post('/vectors/update', payload)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def options
|
60
|
+
{
|
61
|
+
headers: @headers,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# https://index_name-project_id.svc.environment.pinecone.io
|
68
|
+
def set_base_uri(index_name)
|
69
|
+
index_description = Pinecone::Index.new.describe(index_name)
|
70
|
+
raise Pinecone::IndexNotFoundError, "Index #{index_name} does not exist" if index_description.code != 200
|
71
|
+
uri = index_description.parsed_response["status"]["host"]
|
72
|
+
"https://#{uri}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,155 @@
|
|
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.4
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-04-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.21.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.21.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-validation
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '13.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '13.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: debug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.12'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.12'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.14'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.14'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '6.1'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '6.1'
|
13
153
|
description: Ruby client library which includes index and vector operations to upload
|
14
154
|
embeddings into Pinecone and do similarity searches on them.
|
15
155
|
email: scott@extrayarn.com
|
@@ -18,6 +158,11 @@ extensions: []
|
|
18
158
|
extra_rdoc_files: []
|
19
159
|
files:
|
20
160
|
- lib/pinecone.rb
|
161
|
+
- lib/pinecone/client.rb
|
162
|
+
- lib/pinecone/collection.rb
|
163
|
+
- lib/pinecone/index.rb
|
164
|
+
- lib/pinecone/vector.rb
|
165
|
+
- lib/pinecone/version.rb
|
21
166
|
homepage: https://rubygems.org/gems/pinecone
|
22
167
|
licenses:
|
23
168
|
- MIT
|