voyageai 1.0.1 → 1.1.0
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 +7 -1
- data/lib/voyageai/embed.rb +9 -4
- data/lib/voyageai/version.rb +1 -1
- metadata +1 -2
- 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: a2fc61d8673a96f88ae7e69d9cfb27f00c741f077fd05793ff921e27c0fd869a
|
4
|
+
data.tar.gz: 4734e6ac573b6251ca1789a37fbf9a9db8294c5e82d63b51613b20bfea793e10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d403d37213b6f9666fbafb58fbc82fcbb9752be9e5d29a9e88d34ea6a198f43d860e809e2d890906bf0c298254d9054fcace76d3e5e8e3f70620abd8d27ec791
|
7
|
+
data.tar.gz: f1ad0fcaf76b8a0a0296dc46507c46d6d9b7e2f47a21b6ca9e2d7e8140483c18ece161ff4570db71649c344679b7a92e80287648324a3700c720e00a7b6e2854
|
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
@@ -33,7 +33,7 @@ module VoyageAI
|
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -52,7 +52,6 @@ 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
|
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
|