voyageai 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -4
- data/lib/voyageai/client.rb +8 -2
- data/lib/voyageai/embed.rb +9 -4
- data/lib/voyageai/version.rb +1 -1
- metadata +5 -6
- data/lib/voyageai/embedding.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c834adfa635ba86d940fab56c4ac8bb46086fc6a025319d392c818533389e7dd
|
4
|
+
data.tar.gz: a610e60874f1440eaf05ae2f545350b79fd432b786ad60392251032e5b1cc7e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9560b027aa73f921175a2b06ff6f551ed582f945b8838dd8fdd632ee2d321be89312fad8d3d0179490dbc06e1342a1b6f6973374953c797ce00b2a43f4a334b
|
7
|
+
data.tar.gz: efb6b2f84bfe349d2f909895d14c9291ace8c7af16179d4e1b83fc911b2216f69aa71826a7996fcdd97fa1b347f113eb976a8ca941ab2643726a6e20fa1b1aa6
|
data/README.md
CHANGED
@@ -10,6 +10,23 @@ gem install voyageai
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
+
### Generating Single Embedding
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'voyageai'
|
17
|
+
|
18
|
+
input = 'A quick brown fox jumps over the lazy dog.'
|
19
|
+
|
20
|
+
voyageai = VoyageAI::Client.new(api_key: 'pa-...') # or configure ENV['VOYAGEAI_API_KEY']
|
21
|
+
|
22
|
+
embed = voyageai.emed(input)
|
23
|
+
embed.model # "..."
|
24
|
+
embed.usage # "#<VoyageAI::Usage total_tokens=...>"
|
25
|
+
embed.embedding # [0.0, ...]
|
26
|
+
```
|
27
|
+
|
28
|
+
### Generating Multiple Embeddings
|
29
|
+
|
13
30
|
```ruby
|
14
31
|
require 'voyageai'
|
15
32
|
|
@@ -22,10 +39,8 @@ input = [
|
|
22
39
|
|
23
40
|
voyageai = VoyageAI::Client.new(api_key: 'pa-...') # or configure ENV['VOYAGEAI_API_KEY']
|
24
41
|
|
25
|
-
|
42
|
+
embed = voyageai.embed(input)
|
26
43
|
embed.model # "..."
|
27
44
|
embed.usage # "#<VoyageAI::Usage total_tokens=...>"
|
28
|
-
embed.embeddings.
|
29
|
-
embedding.index # "#<VoyageAI::Embedding index=... embedding=...>
|
30
|
-
end
|
45
|
+
embed.embeddings # [[0.0, ...], ...]
|
31
46
|
```
|
data/lib/voyageai/client.rb
CHANGED
@@ -29,11 +29,11 @@ module VoyageAI
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# @param model [String] optional (e.g. VoyageAI::Model::VOYAGE or "voyage-3")
|
32
|
-
# @param input [Array<String>] required (e.g. ["Sample 1", "Sample 2", ...])
|
32
|
+
# @param input [String, Array<String>] required (e.g. "Sample" or ["Sample 1", "Sample 2", ...])
|
33
33
|
#
|
34
34
|
# @return [Embedding]
|
35
35
|
def embed(input, model: Model::VOYAGE)
|
36
|
-
payload = { input: input, model: model }
|
36
|
+
payload = { input: arrayify(input), model: model }
|
37
37
|
response = HTTP
|
38
38
|
.accept(:json)
|
39
39
|
.auth("Bearer #{@api_key}")
|
@@ -43,5 +43,11 @@ module VoyageAI
|
|
43
43
|
|
44
44
|
Embed.parse(data: response.parse)
|
45
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def arrayify(input)
|
50
|
+
input.is_a?(Array) ? input : [input]
|
51
|
+
end
|
46
52
|
end
|
47
53
|
end
|
data/lib/voyageai/embed.rb
CHANGED
@@ -15,7 +15,7 @@ module VoyageAI
|
|
15
15
|
attr_accessor :usage
|
16
16
|
|
17
17
|
# @!attribute [rw] embeddings
|
18
|
-
# @return [Array<
|
18
|
+
# @return [Array<Array<Float>>]
|
19
19
|
attr_accessor :embeddings
|
20
20
|
|
21
21
|
# @param data [Hash]
|
@@ -23,9 +23,7 @@ module VoyageAI
|
|
23
23
|
def self.parse(data:)
|
24
24
|
model = data["model"]
|
25
25
|
usage = Usage.parse(data: data["usage"])
|
26
|
-
embeddings = data["data"].map
|
27
|
-
Embedding.parse(data: embedding_data)
|
28
|
-
end
|
26
|
+
embeddings = data["data"].map { |embedding_data| embedding_data["embedding"] }
|
29
27
|
|
30
28
|
Embed.new(model: model, usage: usage, embeddings: embeddings)
|
31
29
|
end
|
@@ -43,5 +41,12 @@ module VoyageAI
|
|
43
41
|
def inspect
|
44
42
|
"#<#{self.class.name} model=#{@model.inspect} embeddings=#{@embeddings.inspect} usage=#{@usage.inspect}>"
|
45
43
|
end
|
44
|
+
|
45
|
+
# @param index [Integer] optional
|
46
|
+
#
|
47
|
+
# @return [Array<Float>]
|
48
|
+
def embedding(index: 0)
|
49
|
+
@embeddings[index]
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
data/lib/voyageai/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voyageai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: A library for generating embeddings with https://voyageai.com
|
41
|
+
description: A library for generating embeddings with https://voyageai.com
|
42
42
|
email:
|
43
43
|
- kevin@ksylvest.com
|
44
44
|
executables: []
|
@@ -52,16 +52,15 @@ files:
|
|
52
52
|
- lib/voyageai.rb
|
53
53
|
- lib/voyageai/client.rb
|
54
54
|
- lib/voyageai/embed.rb
|
55
|
-
- lib/voyageai/embedding.rb
|
56
55
|
- lib/voyageai/model.rb
|
57
56
|
- lib/voyageai/usage.rb
|
58
57
|
- lib/voyageai/version.rb
|
59
|
-
homepage: https://github.com/ksylvest/voyageai
|
58
|
+
homepage: https://github.com/ksylvest/voyageai
|
60
59
|
licenses:
|
61
60
|
- MIT
|
62
61
|
metadata:
|
63
|
-
homepage_uri: https://github.com/ksylvest/voyageai
|
64
|
-
changelog_uri: https://github.com/ksylvest/voyageai
|
62
|
+
homepage_uri: https://github.com/ksylvest/voyageai
|
63
|
+
changelog_uri: https://github.com/ksylvest/voyageai/releases
|
65
64
|
rubygems_mfa_required: 'true'
|
66
65
|
post_install_message:
|
67
66
|
rdoc_options: []
|
data/lib/voyageai/embedding.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module VoyageAI
|
4
|
-
# An embedding returned by the VoyageAI API.
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# VoyageAI::Embedding.new(index: 0, embedding: [0.0, 1.0, 2.0, 3.0])
|
8
|
-
class Embedding
|
9
|
-
# @!attribute [rw] model
|
10
|
-
# @return [Integer]
|
11
|
-
attr_accessor :index
|
12
|
-
|
13
|
-
# @!attribute [rw] embedding
|
14
|
-
# @return [Array<Float>]
|
15
|
-
attr_accessor :embedding
|
16
|
-
|
17
|
-
# @param data [Hash]
|
18
|
-
# @return [Embedding]
|
19
|
-
def self.parse(data:)
|
20
|
-
index = data["index"]
|
21
|
-
embedding = data["embedding"]
|
22
|
-
new(index:, embedding:)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param index [Integer]
|
26
|
-
# @param embedding [Array<Float>]
|
27
|
-
def initialize(index:, embedding:)
|
28
|
-
@index = index
|
29
|
-
@embedding = embedding
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [String]
|
33
|
-
def inspect
|
34
|
-
"#<#{self.class.name} index=#{index} embedding=#{embedding.inspect}>"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|