emb 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4a415f04bd5c26d788aed81f94684054a563b26884c74d8ef7fa7f6eec909c7
4
- data.tar.gz: 752cd3992f5cd48f31ec7f6d9387f04f36990532b7d9fbce88098c3a87e8eb9d
3
+ metadata.gz: cc1be692fe3d651429a292c2e2d0b912aa1bb8af22dbf56b9390d7e8a00fe516
4
+ data.tar.gz: 433caba4f427a465b9717970884ea64e12c4169fca3f54df8e91858dc1ef21bb
5
5
  SHA512:
6
- metadata.gz: 7ccade7ad0c808e237a382f4a3172c35ca651b21082135c2a1d4202bdb03acd18c47ff1bcc1a06767a07cf4050d5d3b7fdfd5eaa0789c0bcfd78f24cd31784f1
7
- data.tar.gz: d95c5f9c7064ecf7d61d1a81211909152ce8e465cf2c0e0f39d9d1585e7798210b68b6c4a76a450d641201ecafe834c5909d57c489204328a9404e4d014d8991
6
+ metadata.gz: 553e753f5a90217312bd7f6e2e9240c16747b6fcc01e876cdabdc2b33a2c430cb937cb214926ee8a4d3fb77a66a45439ad6fb6c1be1885617fb0fa68026ee336
7
+ data.tar.gz: 478a17bbf82026da26580ead85fae29bd6f8b1350bbe841aa32b098ce0845e3005641a80f388fd7912df0ba3e2c9652a98d8dfda8769a8d48c3ceb1d3eed1ae4
data/README.md CHANGED
@@ -1,45 +1,83 @@
1
1
  # emb — Ruby client
2
2
 
3
- Thin Ruby wrapper for [emb](https://github.com/elcuervo/emb), a Redis-compatible embedding server.
3
+ [![emb gem](https://img.shields.io/gem/v/emb?logo=rubygems&color=red&label=emb)](https://rubygems.org/gems/emb)
4
4
 
5
- ## Usage
5
+ Thin Ruby wrapper for [emb](https://github.com/elcuervo/emb), a Redis-compatible embedding server. Auto-decodes float32 binary responses to Ruby arrays.
6
+
7
+ ## Installation
8
+
9
+ Add to your Gemfile:
10
+
11
+ ```ruby
12
+ gem "emb"
13
+ ```
14
+
15
+ Or install globally:
16
+
17
+ ```bash
18
+ gem install emb
19
+ ```
20
+
21
+ ## Setup
22
+
23
+ Configure the connection pool (defaults shown):
6
24
 
7
25
  ```ruby
8
26
  require "emb"
9
27
 
10
28
  Emb.setup(host: "localhost", port: 6379, pool: 5)
29
+ ```
30
+
31
+ `Emb.config` is an alias for `Emb.setup`.
11
32
 
12
- Emb[:minilm]["hello world"]
13
- # → raw float32 bytes
33
+ ## Usage
34
+
35
+ ### Single text
36
+
37
+ ```ruby
38
+ result = Emb[:minilm]["hello world"]
39
+ # => [0.0123, -0.0456, 0.0789, ...] (384 floats)
40
+ ```
41
+
42
+ ### Multiple texts
43
+
44
+ ```ruby
45
+ results = Emb[:minilm]["hello", "world"]
46
+ # => [[0.0123, ...], [-0.0456, ...]]
47
+ ```
14
48
 
15
- Emb.models
16
- # → [{name: "minilm", dim: 384, status: "ready"}, ...]
49
+ ### Multi-model queries
17
50
 
18
- Emb.info(:minilm)
19
- # → {dim: 384, workers: 10, ...}
51
+ Send texts to different models in one round trip:
20
52
 
53
+ ```ruby
21
54
  Emb.multi do |m|
22
55
  m[:minilm]["hello"]
23
56
  m[:bge]["world"]
24
57
  end
25
- # EMB.MULTI minilm "hello" bge "world"
58
+ # => EMB.MULTI minilm "hello" bge "world"
26
59
  ```
27
60
 
28
- ## Testing end to end
61
+ ### Commands
29
62
 
30
- ### Prerequisites
63
+ ```ruby
64
+ Emb.models # => [{name: "minilm", dim: 384, status: "ready"}, ...]
65
+ Emb.info(:minilm) # => {dim: 384, workers: 10, requests: 42, ...}
66
+ Emb.stats # => server statistics hash
67
+ Emb.help # => command reference string
68
+ Emb.ping # => "PONG"
69
+ ```
31
70
 
32
- - An `emb` binary built from the repo root (`just build` or `go build`)
33
- - Ruby 3.3+ with bundler
71
+ ## Testing end to end
34
72
 
35
- ### Running tests
73
+ Start the emb server, then run the test suite:
36
74
 
37
75
  ```bash
38
- # From the repo root, start the emb server:
76
+ # From the repo root:
39
77
  ./bin/emb -config test-two-models.yaml &
40
78
 
41
- # From gems/emb/, run the test suite:
79
+ # From gems/emb/:
42
80
  bundle exec rake
43
81
  ```
44
82
 
45
- This starts the full test suite against a real running `emb` server. Tests cover all commands: `EMB`, `EMB.MODELS`, `EMB.INFO`, `EMB.HELP`, `PING`, and `EMB.MULTI`.
83
+ Tests cover all commands: `EMB`, `EMB.MODELS`, `EMB.INFO`, `EMB.HELP`, `PING`, and `EMB.MULTI`.
data/lib/emb/client.rb CHANGED
@@ -6,7 +6,7 @@ require "redis_client"
6
6
  module Emb
7
7
  @pool = nil
8
8
 
9
- DEFAULTS = {host: "localhost", port: 6379, pool: 5}.freeze
9
+ DEFAULTS = { host: "localhost", port: 6379, pool: 5 }.freeze
10
10
 
11
11
  class << self
12
12
  def setup(host: DEFAULTS[:host], port: DEFAULTS[:port], pool: DEFAULTS[:pool])
@@ -14,6 +14,7 @@ module Emb
14
14
  RedisClient.new(host: host, port: port, protocol: 2, reconnect_attempts: 3)
15
15
  end
16
16
  end
17
+
17
18
  alias_method :config, :setup
18
19
 
19
20
  def send_command(*args)
data/lib/emb/multi.rb CHANGED
@@ -12,6 +12,7 @@ module Emb
12
12
 
13
13
  def run
14
14
  args = @pairs.flat_map { |pair| [pair[:model].to_s, pair[:text]] }
15
+
15
16
  Emb.send_command("EMB.MULTI", *args)
16
17
  end
17
18
 
@@ -22,7 +23,8 @@ module Emb
22
23
  end
23
24
 
24
25
  def [](text)
25
- @pairs << {model: @model, text: text}
26
+ @pairs << {
27
+ model: @model, text: text }
26
28
  end
27
29
  end
28
30
  end
@@ -30,7 +32,9 @@ module Emb
30
32
  class << self
31
33
  def multi
32
34
  mp = MultiProxy.new
35
+
33
36
  yield mp
37
+
34
38
  mp.run
35
39
  end
36
40
  end
data/lib/emb/proxy.rb CHANGED
@@ -21,7 +21,12 @@ module Emb
21
21
  end
22
22
 
23
23
  def [](text, *texts)
24
- Emb.send_command("EMB", @name.to_s, text, *texts)
24
+ set = Array(Emb.send_command("EMB", @name.to_s, text, *texts))
25
+ result = set.map { |entry| entry.unpack("e*") }
26
+
27
+ return result.first if result.size == 1
28
+
29
+ result
25
30
  end
26
31
 
27
32
  def inspect
data/lib/emb/version.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emb
4
- VERSION =
5
- begin
6
- File.read(File.expand_path('../../../../VERSION', __dir__)).strip
7
- rescue Errno::ENOENT
8
- Gem::Specification.find_by_name("emb").version.to_s
9
- end
4
+ VERSION = Gem.loaded_specs['emb'].version.to_s
10
5
  end
data/lib/emb.rb CHANGED
@@ -9,8 +9,12 @@ module Emb
9
9
  class << self
10
10
  def models
11
11
  raw = send_command("EMB.MODELS")
12
+
12
13
  return [] if raw.nil?
13
- raw.map { |name, dim, status| {name: name, dim: dim.to_i, status: status} }
14
+
15
+ raw.map do |name, dim, status|
16
+ { name: name, dim: dim.to_i, status: status }
17
+ end
14
18
  end
15
19
 
16
20
  def info(name)
@@ -18,7 +22,9 @@ module Emb
18
22
 
19
23
  return {} if raw.nil?
20
24
 
21
- raw.each_slice(2).map { |k, v| [k.to_sym, v] }.to_h
25
+ raw
26
+ .each_slice(2)
27
+ .to_h { |k, v| [k.to_sym, v] }
22
28
  end
23
29
 
24
30
  def stats = send_command("EMB.STATS")
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.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - elcuervo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-01 00:00:00.000000000 Z
11
+ date: 2026-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool