pinecone 0.1.2 → 0.1.3
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 +65 -0
- data/lib/pinecone/version.rb +3 -0
- metadata +120 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b17e749b07052d08df706ff8f60ca5a40c2bdb752a19662c15ebab0745cf813
|
4
|
+
data.tar.gz: f0789949de4ceab10e7a195798aa0ebc6d77dd9c32f049cab27ff82f13c182fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41a0fddf6cd3376e4d4869b9695732db64bfcab2a0e487210927d0fa9e78d6ae3ab6e893c653afd9cbdba0e5bded804216e3b385a0882f1853eba518c2bc8b4
|
7
|
+
data.tar.gz: 314e5ae920fa3c02f1d46899c0bd9508fd6c5dee228e675d3a7f9d0fc742f10c2d43e24032a0a5a227ad32d7f1bb36e53b4221f228840b7357143c0708106bd1
|
@@ -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,65 @@
|
|
1
|
+
module Pinecone
|
2
|
+
class Vector
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
def initialize(index_name)
|
6
|
+
self.class.base_uri set_base_uri(index_name)
|
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 delete(namespace: "", ids: [], delete_all: false)
|
16
|
+
inputs = {
|
17
|
+
"namespace": namespace,
|
18
|
+
"ids": ids,
|
19
|
+
"deleteAll": delete_all,
|
20
|
+
}.to_json
|
21
|
+
payload = options.merge(body: inputs)
|
22
|
+
self.class.post('/vectors/delete', payload)
|
23
|
+
end
|
24
|
+
|
25
|
+
# This requires manually building the query string to unbundle ids
|
26
|
+
def fetch(namespace: "", ids: [])
|
27
|
+
ids_query_string = ids.map { |id| "ids=#{id}" }.join('&')
|
28
|
+
query_string = "namespace=#{namespace}&#{ids_query_string}"
|
29
|
+
self.class.get("/vectors/fetch?#{query_string}", options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def upsert(body)
|
33
|
+
payload = options.merge(body: body.to_json)
|
34
|
+
self.class.post('/vectors/upsert', payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
def query(namespace: "", vector:, top_k: 10, include_values: false, include_metadata: true)
|
38
|
+
inputs = {
|
39
|
+
"namespace": namespace,
|
40
|
+
"includeValues": include_values,
|
41
|
+
"includeMetadata": include_metadata,
|
42
|
+
"topK": top_k,
|
43
|
+
"vector": vector,
|
44
|
+
}.to_json
|
45
|
+
payload = options.merge(body: inputs)
|
46
|
+
self.class.post('/query', payload)
|
47
|
+
end
|
48
|
+
|
49
|
+
def options
|
50
|
+
{
|
51
|
+
headers: @headers,
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# https://index_name-project_id.svc.environment.pinecone.io
|
58
|
+
def set_base_uri(index_name)
|
59
|
+
index_description = Pinecone::Index.new.describe(index_name)
|
60
|
+
raise Pinecone::IndexNotFoundError, "Index #{index_name} does not exist" if index_description.code != 200
|
61
|
+
uri = index_description.parsed_response["status"]["host"]
|
62
|
+
"https://#{uri}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,127 @@
|
|
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.3
|
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-25 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: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awesome_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.14'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.14'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vcr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '6.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '6.1'
|
13
125
|
description: Ruby client library which includes index and vector operations to upload
|
14
126
|
embeddings into Pinecone and do similarity searches on them.
|
15
127
|
email: scott@extrayarn.com
|
@@ -18,6 +130,11 @@ extensions: []
|
|
18
130
|
extra_rdoc_files: []
|
19
131
|
files:
|
20
132
|
- lib/pinecone.rb
|
133
|
+
- lib/pinecone/client.rb
|
134
|
+
- lib/pinecone/collection.rb
|
135
|
+
- lib/pinecone/index.rb
|
136
|
+
- lib/pinecone/vector.rb
|
137
|
+
- lib/pinecone/version.rb
|
21
138
|
homepage: https://rubygems.org/gems/pinecone
|
22
139
|
licenses:
|
23
140
|
- MIT
|