turborag 0.5.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/turborag.rb +122 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1cc6fcd1aa419dfd220cdc266013202acf0cc0f776772b779175aaf64493f423
4
+ data.tar.gz: 1fe99d19c27e42f523499682a4d83f1a3ac09898d8e4dbbd53a83c5dca9d716e
5
+ SHA512:
6
+ metadata.gz: 62253f8b873f76877b4e0a435e49a65dbbfdda1d2dead8cfa2e9864e6743cb503bf713adb2a12efa5b1227d437deb29726f47cb8c18e6698214a7d335b3e3eea
7
+ data.tar.gz: 0c2e86110b7aea52109b65a23effc53edf174fb92138a4ce6f1ee2eaa40b5a15d534738cc420a646766e8fec89bc6f166b141f6742c24d59d1219b67e916cf97
data/lib/turborag.rb ADDED
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TurboRAG Ruby client — typed wrapper over the TurboRAG HTTP API.
4
+ # Zero dependencies beyond stdlib (net/http, json).
5
+ #
6
+ # Usage:
7
+ # client = TurboRAG::Client.new("http://localhost:8080")
8
+ # results = client.query(vector: [0.1, 0.2, 0.3], top_k: 5)
9
+
10
+ require "net/http"
11
+ require "json"
12
+ require "uri"
13
+
14
+ module TurboRAG
15
+ class Error < StandardError
16
+ attr_reader :status, :body
17
+
18
+ def initialize(status, body)
19
+ @status = status
20
+ @body = body
21
+ super("TurboRAG HTTP #{status}: #{body}")
22
+ end
23
+ end
24
+
25
+ class Client
26
+ # @param base_url [String] TurboRAG server URL (e.g. "http://localhost:8080")
27
+ # @param timeout [Integer] request timeout in seconds (default: 30)
28
+ def initialize(base_url, timeout: 30)
29
+ @base_uri = URI.parse(base_url.chomp("/"))
30
+ @timeout = timeout
31
+ end
32
+
33
+ # Search by embedding vector.
34
+ # @param vector [Array<Float>]
35
+ # @param top_k [Integer]
36
+ # @return [Hash] { "count" => N, "results" => [...] }
37
+ def query(vector:, top_k: 5)
38
+ post("/query", { query_vector: vector, top_k: top_k })
39
+ end
40
+
41
+ # Search by text (requires --model on the server).
42
+ # @param text [String]
43
+ # @param top_k [Integer]
44
+ # @return [Hash]
45
+ def query_text(text:, top_k: 5)
46
+ post("/query", { query_text: text, top_k: top_k })
47
+ end
48
+
49
+ # Batch vector search.
50
+ # @param queries [Array<Hash>] each with :vector key
51
+ # @param top_k [Integer]
52
+ # @return [Hash]
53
+ def query_batch(queries:, top_k: 5)
54
+ payload = {
55
+ queries: queries.map { |q| { query_vector: q[:vector] } },
56
+ top_k: top_k,
57
+ }
58
+ post("/query/batch", payload)
59
+ end
60
+
61
+ # Add records with precomputed embeddings.
62
+ # @param records [Array<Hash>] each with :chunk_id, :text, :embedding
63
+ # @return [Hash]
64
+ def ingest(records:)
65
+ post("/ingest", { records: records })
66
+ end
67
+
68
+ # Ingest raw text with auto-chunking (requires --model).
69
+ # @param text [String]
70
+ # @param source_doc [String, nil]
71
+ # @return [Hash]
72
+ def ingest_text(text:, source_doc: nil)
73
+ post("/ingest-text", { text: text, source_doc: source_doc })
74
+ end
75
+
76
+ # Health check.
77
+ # @return [Hash]
78
+ def health
79
+ get("/health")
80
+ end
81
+
82
+ # Index configuration and stats.
83
+ # @return [Hash]
84
+ def index
85
+ get("/index")
86
+ end
87
+
88
+ # Latency and error metrics.
89
+ # @return [Hash]
90
+ def metrics
91
+ get("/metrics")
92
+ end
93
+
94
+ private
95
+
96
+ def get(path)
97
+ uri = URI.join(@base_uri.to_s, path)
98
+ req = Net::HTTP::Get.new(uri)
99
+ execute(uri, req)
100
+ end
101
+
102
+ def post(path, body)
103
+ uri = URI.join(@base_uri.to_s, path)
104
+ req = Net::HTTP::Post.new(uri)
105
+ req["Content-Type"] = "application/json"
106
+ req.body = JSON.generate(body)
107
+ execute(uri, req)
108
+ end
109
+
110
+ def execute(uri, req)
111
+ http = Net::HTTP.new(uri.host, uri.port)
112
+ http.use_ssl = (uri.scheme == "https")
113
+ http.open_timeout = @timeout
114
+ http.read_timeout = @timeout
115
+
116
+ res = http.request(req)
117
+ raise Error.new(res.code.to_i, res.body) unless res.is_a?(Net::HTTPSuccess)
118
+
119
+ JSON.parse(res.body)
120
+ end
121
+ end
122
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turborag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - Ratnam Shah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Typed wrapper over the TurboRAG HTTP API for compressed vector search.
14
+ Zero dependencies beyond stdlib.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/turborag.rb
21
+ homepage: https://github.com/ratnam1510/turborag
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.3.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Ruby client for the TurboRAG compressed vector retrieval API
44
+ test_files: []