emb 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/emb/batch.rb +18 -12
- data/lib/emb/client.rb +3 -2
- data/lib/emb/configuration.rb +2 -1
- data/lib/emb/multi.rb +10 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0465face51bde07116c17303587651ae8c947875b9702a587654ead5256c71da
|
|
4
|
+
data.tar.gz: b0e8cf2d155a51c9b65a2bb006eec6be4d7a60e932301bea426b2ae986a91015
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 843e3cdb952a4a1ece48413aad778939d155f4e345c9ebbce3ccd18ce703e53183a099dcae3b815856d062a0d7a80b3d028587704c736402ce659133eb1d7b8a
|
|
7
|
+
data.tar.gz: 786734c2ac2765bde4810313f998f83550e0823cd47887e16ebf5b2014fe2c865e22b021286187cedaf105d2d5b818c8885d85acceab72ead5e07915da17d9f3
|
data/lib/emb/batch.rb
CHANGED
|
@@ -7,18 +7,24 @@ module Emb
|
|
|
7
7
|
|
|
8
8
|
BATCH_BLOCK = lambda do |items, loader, _args|
|
|
9
9
|
items.group_by(&:first).each do |client, client_items|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
client_items.
|
|
15
|
-
_,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
offset
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
chunk = client.respond_to?(:batch_size) && client.batch_size ? client.batch_size : Emb.configuration.batch_size
|
|
11
|
+
|
|
12
|
+
# Chunk at batch_size pairs per EMB.MULTI so a single command stays well
|
|
13
|
+
# under the server's max_pairs cap and within client read timeouts.
|
|
14
|
+
client_items.each_slice(chunk) do |slice|
|
|
15
|
+
pairs = slice.flat_map { |_, model, text| Array(text).flat_map { |t| [model.to_s, t] } }
|
|
16
|
+
results = Array(client.send_command('EMB.MULTI', *pairs))
|
|
17
|
+
|
|
18
|
+
offset = 0
|
|
19
|
+
slice.each do |item|
|
|
20
|
+
_, _, text = item
|
|
21
|
+
texts = Array(text)
|
|
22
|
+
values = results[offset, texts.size].map { |entry| entry&.unpack('e*') }
|
|
23
|
+
offset += texts.size
|
|
24
|
+
|
|
25
|
+
# eager Proxy#[] shape: vector for a single text, vectors for many
|
|
26
|
+
loader.call(item, values.size == 1 ? values.first : values)
|
|
27
|
+
end
|
|
22
28
|
end
|
|
23
29
|
end
|
|
24
30
|
end
|
data/lib/emb/client.rb
CHANGED
|
@@ -7,11 +7,12 @@ module Emb
|
|
|
7
7
|
class Client
|
|
8
8
|
include Commands
|
|
9
9
|
|
|
10
|
-
attr_reader :pool
|
|
10
|
+
attr_reader :pool, :batch_size
|
|
11
11
|
|
|
12
12
|
def initialize(pool: nil, batch: nil, **redis_options)
|
|
13
13
|
cfg = Emb.configuration
|
|
14
14
|
@batch_enabled = batch.nil? ? cfg.batch : batch
|
|
15
|
+
@batch_size = redis_options.delete(:batch_size) || cfg.batch_size
|
|
15
16
|
size = pool.nil? ? cfg.pool : pool
|
|
16
17
|
url = extract_url!(redis_options, cfg)
|
|
17
18
|
redis_options = merged_redis_options(redis_options, cfg, url)
|
|
@@ -104,7 +105,7 @@ module Emb
|
|
|
104
105
|
|
|
105
106
|
def merged_redis_options(opts, cfg, url)
|
|
106
107
|
defaults = cfg.to_h
|
|
107
|
-
keys = defaults.keys - %i[url pool batch]
|
|
108
|
+
keys = defaults.keys - %i[url pool batch batch_size]
|
|
108
109
|
keys -= %i[host port] if url
|
|
109
110
|
|
|
110
111
|
keys.each do |key|
|
data/lib/emb/configuration.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Emb
|
|
4
4
|
class Configuration
|
|
5
5
|
OPTIONS = %i[
|
|
6
|
-
host port url pool batch driver protocol
|
|
6
|
+
host port url pool batch batch_size driver protocol
|
|
7
7
|
connect_timeout read_timeout write_timeout reconnect_attempts
|
|
8
8
|
].freeze
|
|
9
9
|
|
|
@@ -15,6 +15,7 @@ module Emb
|
|
|
15
15
|
self.url = nil
|
|
16
16
|
self.pool = 5
|
|
17
17
|
self.batch = true
|
|
18
|
+
self.batch_size = 512
|
|
18
19
|
self.driver = nil
|
|
19
20
|
self.protocol = 2
|
|
20
21
|
self.connect_timeout = nil
|
data/lib/emb/multi.rb
CHANGED
|
@@ -12,11 +12,17 @@ module Emb
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def run
|
|
15
|
-
|
|
15
|
+
chunk = @client.respond_to?(:batch_size) && @client.batch_size ? @client.batch_size : Emb.configuration.batch_size
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
# Chunk at batch_size pairs per EMB.MULTI so a single command stays well
|
|
18
|
+
# under the server's max_pairs cap and within client read timeouts.
|
|
19
|
+
@pairs.each_slice(chunk).flat_map do |slice|
|
|
20
|
+
args = slice.flat_map { |pair| [pair[:model].to_s, pair[:text]] }
|
|
21
|
+
|
|
22
|
+
@client
|
|
23
|
+
.send_command('EMB.MULTI', *args)
|
|
24
|
+
.map { |entry| entry&.unpack('e*') }
|
|
25
|
+
end
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
class PairCollector
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: emb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- elcuervo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-09-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: batch-loader
|