turbopuffer-ruby 0.2.0.pre.alpha.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 (194) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +60 -0
  4. data/README.md +291 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/turbopuffer/client.rb +130 -0
  7. data/lib/turbopuffer/errors.rb +214 -0
  8. data/lib/turbopuffer/file_part.rb +55 -0
  9. data/lib/turbopuffer/internal/namespace_page.rb +86 -0
  10. data/lib/turbopuffer/internal/transport/base_client.rb +563 -0
  11. data/lib/turbopuffer/internal/transport/pooled_net_requester.rb +209 -0
  12. data/lib/turbopuffer/internal/type/array_of.rb +167 -0
  13. data/lib/turbopuffer/internal/type/base_model.rb +534 -0
  14. data/lib/turbopuffer/internal/type/base_page.rb +55 -0
  15. data/lib/turbopuffer/internal/type/boolean.rb +77 -0
  16. data/lib/turbopuffer/internal/type/converter.rb +300 -0
  17. data/lib/turbopuffer/internal/type/enum.rb +152 -0
  18. data/lib/turbopuffer/internal/type/file_input.rb +108 -0
  19. data/lib/turbopuffer/internal/type/hash_of.rb +187 -0
  20. data/lib/turbopuffer/internal/type/request_parameters.rb +42 -0
  21. data/lib/turbopuffer/internal/type/union.rb +252 -0
  22. data/lib/turbopuffer/internal/type/unknown.rb +81 -0
  23. data/lib/turbopuffer/internal/util.rb +914 -0
  24. data/lib/turbopuffer/internal.rb +20 -0
  25. data/lib/turbopuffer/models/attribute_schema.rb +19 -0
  26. data/lib/turbopuffer/models/attribute_schema_config.rb +48 -0
  27. data/lib/turbopuffer/models/attribute_type.rb +7 -0
  28. data/lib/turbopuffer/models/client_namespaces_params.rb +38 -0
  29. data/lib/turbopuffer/models/columns.rb +64 -0
  30. data/lib/turbopuffer/models/distance_metric.rb +19 -0
  31. data/lib/turbopuffer/models/full_text_search.rb +20 -0
  32. data/lib/turbopuffer/models/full_text_search_config.rb +72 -0
  33. data/lib/turbopuffer/models/id.rb +19 -0
  34. data/lib/turbopuffer/models/include_attributes.rb +22 -0
  35. data/lib/turbopuffer/models/language.rb +32 -0
  36. data/lib/turbopuffer/models/namespace_delete_all_params.rb +20 -0
  37. data/lib/turbopuffer/models/namespace_delete_all_response.rb +19 -0
  38. data/lib/turbopuffer/models/namespace_hint_cache_warm_params.rb +20 -0
  39. data/lib/turbopuffer/models/namespace_hint_cache_warm_response.rb +26 -0
  40. data/lib/turbopuffer/models/namespace_metadata.rb +35 -0
  41. data/lib/turbopuffer/models/namespace_metadata_params.rb +20 -0
  42. data/lib/turbopuffer/models/namespace_multi_query_params.rb +73 -0
  43. data/lib/turbopuffer/models/namespace_multi_query_response.rb +51 -0
  44. data/lib/turbopuffer/models/namespace_query_params.rb +119 -0
  45. data/lib/turbopuffer/models/namespace_query_response.rb +41 -0
  46. data/lib/turbopuffer/models/namespace_recall_params.rb +57 -0
  47. data/lib/turbopuffer/models/namespace_recall_response.rb +39 -0
  48. data/lib/turbopuffer/models/namespace_schema_params.rb +20 -0
  49. data/lib/turbopuffer/models/namespace_schema_response.rb +8 -0
  50. data/lib/turbopuffer/models/namespace_summary.rb +19 -0
  51. data/lib/turbopuffer/models/namespace_update_schema_params.rb +29 -0
  52. data/lib/turbopuffer/models/namespace_update_schema_response.rb +9 -0
  53. data/lib/turbopuffer/models/namespace_write_params.rb +158 -0
  54. data/lib/turbopuffer/models/namespace_write_response.rb +67 -0
  55. data/lib/turbopuffer/models/query.rb +63 -0
  56. data/lib/turbopuffer/models/query_billing.rb +26 -0
  57. data/lib/turbopuffer/models/query_performance.rb +63 -0
  58. data/lib/turbopuffer/models/row.rb +38 -0
  59. data/lib/turbopuffer/models/tokenizer.rb +17 -0
  60. data/lib/turbopuffer/models/vector.rb +22 -0
  61. data/lib/turbopuffer/models/vector_encoding.rb +16 -0
  62. data/lib/turbopuffer/models/write_billing.rb +26 -0
  63. data/lib/turbopuffer/models.rb +101 -0
  64. data/lib/turbopuffer/namespace.rb +22 -0
  65. data/lib/turbopuffer/request_options.rb +77 -0
  66. data/lib/turbopuffer/resources/namespaces.rb +311 -0
  67. data/lib/turbopuffer/version.rb +5 -0
  68. data/lib/turbopuffer.rb +94 -0
  69. data/manifest.yaml +15 -0
  70. data/rbi/turbopuffer/client.rbi +91 -0
  71. data/rbi/turbopuffer/errors.rbi +178 -0
  72. data/rbi/turbopuffer/file_part.rbi +37 -0
  73. data/rbi/turbopuffer/internal/namespace_page.rbi +22 -0
  74. data/rbi/turbopuffer/internal/transport/base_client.rbi +298 -0
  75. data/rbi/turbopuffer/internal/transport/pooled_net_requester.rbi +80 -0
  76. data/rbi/turbopuffer/internal/type/array_of.rbi +104 -0
  77. data/rbi/turbopuffer/internal/type/base_model.rbi +304 -0
  78. data/rbi/turbopuffer/internal/type/base_page.rbi +43 -0
  79. data/rbi/turbopuffer/internal/type/boolean.rbi +58 -0
  80. data/rbi/turbopuffer/internal/type/converter.rbi +162 -0
  81. data/rbi/turbopuffer/internal/type/enum.rbi +82 -0
  82. data/rbi/turbopuffer/internal/type/file_input.rbi +59 -0
  83. data/rbi/turbopuffer/internal/type/hash_of.rbi +104 -0
  84. data/rbi/turbopuffer/internal/type/request_parameters.rbi +31 -0
  85. data/rbi/turbopuffer/internal/type/union.rbi +121 -0
  86. data/rbi/turbopuffer/internal/type/unknown.rbi +58 -0
  87. data/rbi/turbopuffer/internal/util.rbi +487 -0
  88. data/rbi/turbopuffer/internal.rbi +18 -0
  89. data/rbi/turbopuffer/models/attribute_schema.rbi +17 -0
  90. data/rbi/turbopuffer/models/attribute_schema_config.rbi +92 -0
  91. data/rbi/turbopuffer/models/attribute_type.rbi +7 -0
  92. data/rbi/turbopuffer/models/client_namespaces_params.rbi +71 -0
  93. data/rbi/turbopuffer/models/columns.rbi +82 -0
  94. data/rbi/turbopuffer/models/distance_metric.rbi +27 -0
  95. data/rbi/turbopuffer/models/full_text_search.rbi +19 -0
  96. data/rbi/turbopuffer/models/full_text_search_config.rbi +116 -0
  97. data/rbi/turbopuffer/models/id.rbi +16 -0
  98. data/rbi/turbopuffer/models/include_attributes.rbi +24 -0
  99. data/rbi/turbopuffer/models/language.rbi +36 -0
  100. data/rbi/turbopuffer/models/namespace_delete_all_params.rbi +41 -0
  101. data/rbi/turbopuffer/models/namespace_delete_all_response.rbi +31 -0
  102. data/rbi/turbopuffer/models/namespace_hint_cache_warm_params.rbi +41 -0
  103. data/rbi/turbopuffer/models/namespace_hint_cache_warm_response.rbi +38 -0
  104. data/rbi/turbopuffer/models/namespace_metadata.rbi +54 -0
  105. data/rbi/turbopuffer/models/namespace_metadata_params.rbi +41 -0
  106. data/rbi/turbopuffer/models/namespace_multi_query_params.rbi +175 -0
  107. data/rbi/turbopuffer/models/namespace_multi_query_response.rbi +111 -0
  108. data/rbi/turbopuffer/models/namespace_query_params.rbi +241 -0
  109. data/rbi/turbopuffer/models/namespace_query_response.rbi +73 -0
  110. data/rbi/turbopuffer/models/namespace_recall_params.rbi +93 -0
  111. data/rbi/turbopuffer/models/namespace_recall_response.rbi +59 -0
  112. data/rbi/turbopuffer/models/namespace_schema_params.rbi +41 -0
  113. data/rbi/turbopuffer/models/namespace_schema_response.rbi +11 -0
  114. data/rbi/turbopuffer/models/namespace_summary.rbi +28 -0
  115. data/rbi/turbopuffer/models/namespace_update_schema_params.rbi +80 -0
  116. data/rbi/turbopuffer/models/namespace_update_schema_response.rbi +11 -0
  117. data/rbi/turbopuffer/models/namespace_write_params.rbi +290 -0
  118. data/rbi/turbopuffer/models/namespace_write_response.rbi +101 -0
  119. data/rbi/turbopuffer/models/query.rbi +106 -0
  120. data/rbi/turbopuffer/models/query_billing.rbi +46 -0
  121. data/rbi/turbopuffer/models/query_performance.rbi +82 -0
  122. data/rbi/turbopuffer/models/row.rbi +47 -0
  123. data/rbi/turbopuffer/models/tokenizer.rbi +22 -0
  124. data/rbi/turbopuffer/models/vector.rbi +22 -0
  125. data/rbi/turbopuffer/models/vector_encoding.rbi +22 -0
  126. data/rbi/turbopuffer/models/write_billing.rbi +49 -0
  127. data/rbi/turbopuffer/models.rbi +64 -0
  128. data/rbi/turbopuffer/namespace.rbi +8 -0
  129. data/rbi/turbopuffer/request_options.rbi +59 -0
  130. data/rbi/turbopuffer/resources/namespaces.rbi +243 -0
  131. data/rbi/turbopuffer/version.rbi +5 -0
  132. data/sig/turbopuffer/client.rbs +41 -0
  133. data/sig/turbopuffer/errors.rbs +110 -0
  134. data/sig/turbopuffer/file_part.rbs +21 -0
  135. data/sig/turbopuffer/internal/namespace_page.rbs +13 -0
  136. data/sig/turbopuffer/internal/transport/base_client.rbs +131 -0
  137. data/sig/turbopuffer/internal/transport/pooled_net_requester.rbs +45 -0
  138. data/sig/turbopuffer/internal/type/array_of.rbs +48 -0
  139. data/sig/turbopuffer/internal/type/base_model.rbs +102 -0
  140. data/sig/turbopuffer/internal/type/base_page.rbs +24 -0
  141. data/sig/turbopuffer/internal/type/boolean.rbs +26 -0
  142. data/sig/turbopuffer/internal/type/converter.rbs +62 -0
  143. data/sig/turbopuffer/internal/type/enum.rbs +32 -0
  144. data/sig/turbopuffer/internal/type/file_input.rbs +25 -0
  145. data/sig/turbopuffer/internal/type/hash_of.rbs +48 -0
  146. data/sig/turbopuffer/internal/type/request_parameters.rbs +19 -0
  147. data/sig/turbopuffer/internal/type/union.rbs +52 -0
  148. data/sig/turbopuffer/internal/type/unknown.rbs +26 -0
  149. data/sig/turbopuffer/internal/util.rbs +185 -0
  150. data/sig/turbopuffer/internal.rbs +9 -0
  151. data/sig/turbopuffer/models/attribute_schema.rbs +11 -0
  152. data/sig/turbopuffer/models/attribute_schema_config.rbs +45 -0
  153. data/sig/turbopuffer/models/attribute_type.rbs +5 -0
  154. data/sig/turbopuffer/models/client_namespaces_params.rbs +38 -0
  155. data/sig/turbopuffer/models/columns.rbs +42 -0
  156. data/sig/turbopuffer/models/distance_metric.rbs +17 -0
  157. data/sig/turbopuffer/models/full_text_search.rbs +11 -0
  158. data/sig/turbopuffer/models/full_text_search_config.rbs +68 -0
  159. data/sig/turbopuffer/models/id.rbs +11 -0
  160. data/sig/turbopuffer/models/include_attributes.rbs +13 -0
  161. data/sig/turbopuffer/models/language.rbs +48 -0
  162. data/sig/turbopuffer/models/namespace_delete_all_params.rbs +25 -0
  163. data/sig/turbopuffer/models/namespace_delete_all_response.rbs +13 -0
  164. data/sig/turbopuffer/models/namespace_hint_cache_warm_params.rbs +25 -0
  165. data/sig/turbopuffer/models/namespace_hint_cache_warm_response.rbs +17 -0
  166. data/sig/turbopuffer/models/namespace_metadata.rbs +30 -0
  167. data/sig/turbopuffer/models/namespace_metadata_params.rbs +25 -0
  168. data/sig/turbopuffer/models/namespace_multi_query_params.rbs +86 -0
  169. data/sig/turbopuffer/models/namespace_multi_query_response.rbs +53 -0
  170. data/sig/turbopuffer/models/namespace_query_params.rbs +125 -0
  171. data/sig/turbopuffer/models/namespace_query_response.rbs +39 -0
  172. data/sig/turbopuffer/models/namespace_recall_params.rbs +56 -0
  173. data/sig/turbopuffer/models/namespace_recall_response.rbs +26 -0
  174. data/sig/turbopuffer/models/namespace_schema_params.rbs +25 -0
  175. data/sig/turbopuffer/models/namespace_schema_response.rbs +8 -0
  176. data/sig/turbopuffer/models/namespace_summary.rbs +13 -0
  177. data/sig/turbopuffer/models/namespace_update_schema_params.rbs +37 -0
  178. data/sig/turbopuffer/models/namespace_update_schema_response.rbs +8 -0
  179. data/sig/turbopuffer/models/namespace_write_params.rbs +156 -0
  180. data/sig/turbopuffer/models/namespace_write_response.rbs +56 -0
  181. data/sig/turbopuffer/models/query.rbs +61 -0
  182. data/sig/turbopuffer/models/query_billing.rbs +25 -0
  183. data/sig/turbopuffer/models/query_performance.rbs +45 -0
  184. data/sig/turbopuffer/models/row.rbs +24 -0
  185. data/sig/turbopuffer/models/tokenizer.rbs +15 -0
  186. data/sig/turbopuffer/models/vector.rbs +13 -0
  187. data/sig/turbopuffer/models/vector_encoding.rbs +14 -0
  188. data/sig/turbopuffer/models/write_billing.rbs +27 -0
  189. data/sig/turbopuffer/models.rbs +61 -0
  190. data/sig/turbopuffer/namespace.rbs +5 -0
  191. data/sig/turbopuffer/request_options.rbs +36 -0
  192. data/sig/turbopuffer/resources/namespaces.rbs +81 -0
  193. data/sig/turbopuffer/version.rbs +3 -0
  194. metadata +251 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fcf94276ec11b6cc5c64c4c45e292e6f214c8417b983f99f7d8f8b58c79c8a4a
4
+ data.tar.gz: 2b6d53f1a5828714173028e60b0a9590b591a1d9e97fb70b261164d9279f4e15
5
+ SHA512:
6
+ metadata.gz: 6b6fe86380e51ea769dfadd5b569d62332243dd6e284c7dde7fe603b07450d6bd241e9387bbc40885406f5c68600e572797f3fe9e1feec1096244d0164e83668
7
+ data.tar.gz: e69578e6a28835f21582ccb0c655c19edff7e900abe19f9cd3dcfc50e85b59a81aeacdfb1c91f31cf0baf0645e98f9d1ecdfee558fa217b94b85a415825f8bfc
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0-alpha.1 (2025-07-21)
4
+
5
+ Full Changelog: [v0.1.0-alpha.2...v0.2.0-alpha.1](https://github.com/turbopuffer/turbopuffer-ruby/compare/v0.1.0-alpha.2...v0.2.0-alpha.1)
6
+
7
+ ### Features
8
+
9
+ * **api:** introduce dedicated Query model ([420e42b](https://github.com/turbopuffer/turbopuffer-ruby/commit/420e42b03f05bafb3441e15167349184ac6705da))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **api:** api update ([7348b90](https://github.com/turbopuffer/turbopuffer-ruby/commit/7348b90f988b59a00f5bb6adb76467a699da8273))
15
+ * **api:** api update ([e600278](https://github.com/turbopuffer/turbopuffer-ruby/commit/e60027807e7ca72cc92dae225c1afebb2b5bc455))
16
+ * **api:** api update ([823d059](https://github.com/turbopuffer/turbopuffer-ruby/commit/823d05948dfb60656d7388ea7d25f11b86e41eb3))
17
+ * **api:** api update ([6380572](https://github.com/turbopuffer/turbopuffer-ruby/commit/63805720cbaf84f048907907e86831fdaa19c546))
18
+ * **api:** api update ([ca95879](https://github.com/turbopuffer/turbopuffer-ruby/commit/ca958796c50576e1c3beb80d4e1eba4b63563b56))
19
+ * **api:** api update ([6f54464](https://github.com/turbopuffer/turbopuffer-ruby/commit/6f544641410f009b954f499a5771fb62965d2750))
20
+ * **ci:** plumb API key to tests ([25603e1](https://github.com/turbopuffer/turbopuffer-ruby/commit/25603e1dff1af7f8d0a4cc5163341b039b3483fc))
21
+ * **ci:** release-doctor — report correct token name ([df0b386](https://github.com/turbopuffer/turbopuffer-ruby/commit/df0b386b694d8b46df995553dd4c4e8116eab1b5))
22
+ * don't require region unless baseUrl contains {region} placeholder ([2d537ff](https://github.com/turbopuffer/turbopuffer-ruby/commit/2d537ff0a6ce8af113b724143b38ab573591c62e))
23
+ * formatting ([5d1aa92](https://github.com/turbopuffer/turbopuffer-ruby/commit/5d1aa92fb0a17331a4c228b01301581601767d22))
24
+ * issue where we cannot mutate arrays on base model derivatives ([bc889aa](https://github.com/turbopuffer/turbopuffer-ruby/commit/bc889aa6865671327bf7f6349bff783f2242a005))
25
+ * request parameters should not be marked required if they can be derived from client properties ([aaa1c73](https://github.com/turbopuffer/turbopuffer-ruby/commit/aaa1c73043810c7d7a12aae8972c0e616765308a))
26
+ * **test:** provide distance_metric ([2c41aee](https://github.com/turbopuffer/turbopuffer-ruby/commit/2c41aee42d290fd3bbd8641eb937f8644b324311))
27
+
28
+
29
+ ### Chores
30
+
31
+ * **ci:** enable for pull requests ([0abb0af](https://github.com/turbopuffer/turbopuffer-ruby/commit/0abb0afaaf0ab9b749eaee2fe602b65a64457945))
32
+ * **ci:** only run for pushes and fork pull requests ([eb299b8](https://github.com/turbopuffer/turbopuffer-ruby/commit/eb299b82e3884da5fa620d338be2c2bc6e7e79a9))
33
+ * **internal:** allow streams to also be unwrapped on a per-row basis ([85fbc15](https://github.com/turbopuffer/turbopuffer-ruby/commit/85fbc151fba8e0262a5ae106beecaa6e8eb310c7))
34
+
35
+ ## 0.1.0-alpha.2 (2025-06-14)
36
+
37
+ Full Changelog: [v0.1.0-alpha.1...v0.1.0-alpha.2](https://github.com/turbopuffer/turbopuffer-ruby/compare/v0.1.0-alpha.1...v0.1.0-alpha.2)
38
+
39
+ ### Features
40
+
41
+ * add namespace resource and example ([5340ac0](https://github.com/turbopuffer/turbopuffer-ruby/commit/5340ac0b02ccf08dc23df33b1e75ccaa0d7c4ee7))
42
+
43
+
44
+ ### Chores
45
+
46
+ * sync repo ([816cc8d](https://github.com/turbopuffer/turbopuffer-ruby/commit/816cc8d9a8ac706c77023e7833c2cad49bc63357))
47
+
48
+ ## 0.1.0-alpha.1 (2025-06-14)
49
+
50
+ Full Changelog: [v0.0.1-alpha.0...v0.1.0-alpha.1](https://github.com/turbopuffer/turbopuffer-ruby/compare/v0.0.1-alpha.0...v0.1.0-alpha.1)
51
+
52
+ ### Features
53
+
54
+ * add namespace resource and example ([f72d1f8](https://github.com/turbopuffer/turbopuffer-ruby/commit/f72d1f8d4bdb726f1a05b70be104eff825913fe9))
55
+
56
+
57
+ ### Chores
58
+
59
+ * configure new SDK language ([80e0005](https://github.com/turbopuffer/turbopuffer-ruby/commit/80e0005caa84cf6b8d120f78c2d13245d7b2db48))
60
+ * sync repo ([3498e80](https://github.com/turbopuffer/turbopuffer-ruby/commit/3498e802bc2ae9cfe2292b33c803a7762999a5ac))
data/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # Turbopuffer Ruby API library
2
+
3
+ The Turbopuffer Ruby library provides convenient access to the Turbopuffer REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/turbopuffer/turbopuffer-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ It is generated with [Stainless](https://www.stainless.com/).
6
+
7
+ ## Documentation
8
+
9
+ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/turbopuffer-ruby).
10
+
11
+ The REST API documentation can be found on [turbopuffer.com](https://turbopuffer.com/docs/auth).
12
+
13
+ ## Installation
14
+
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
16
+
17
+ <!-- x-release-please-start-version -->
18
+
19
+ ```ruby
20
+ gem "turbopuffer-ruby", "~> 0.2.0.pre.alpha.1"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "bundler/setup"
29
+ require "turbopuffer"
30
+
31
+ turbopuffer = Turbopuffer::Client.new(
32
+ api_key: ENV["TURBOPUFFER_API_KEY"] # This is the default and can be omitted
33
+ )
34
+
35
+ response = turbopuffer.namespace("products").write(
36
+ distance_metric: "cosine_distance",
37
+ upsert_rows: [
38
+ {id: "2108ed60-6851-49a0-9016-8325434f3845", vector: [0.1, 0.2], attributes: {name: "Red boots", price: 34.99}}
39
+ ]
40
+ )
41
+
42
+ puts(response.rows_affected)
43
+ ```
44
+
45
+ ### Pagination
46
+
47
+ List methods in the Turbopuffer API are paginated.
48
+
49
+ This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
50
+
51
+ ```ruby
52
+ page = turbopuffer.namespaces(prefix: "products")
53
+
54
+ # Fetch single item from page.
55
+ client = page.namespaces[0]
56
+ puts(client.id)
57
+
58
+ # Automatically fetches more pages as needed.
59
+ page.auto_paging_each do |client|
60
+ puts(client.id)
61
+ end
62
+ ```
63
+
64
+ Alternatively, you can use the `#next_page?` and `#next_page` methods for more granular control working with pages.
65
+
66
+ ```ruby
67
+ if page.next_page?
68
+ new_page = page.next_page
69
+ puts(new_page.namespaces[0].id)
70
+ end
71
+ ```
72
+
73
+ ### Handling errors
74
+
75
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Turbopuffer::Errors::APIError` will be thrown:
76
+
77
+ ```ruby
78
+ begin
79
+ client = turbopuffer.namespaces(prefix: "foo")
80
+ rescue Turbopuffer::Errors::APIConnectionError => e
81
+ puts("The server could not be reached")
82
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
83
+ rescue Turbopuffer::Errors::RateLimitError => e
84
+ puts("A 429 status code was received; we should back off a bit.")
85
+ rescue Turbopuffer::Errors::APIStatusError => e
86
+ puts("Another non-200-range status code was received")
87
+ puts(e.status)
88
+ end
89
+ ```
90
+
91
+ Error codes are as follows:
92
+
93
+ | Cause | Error Type |
94
+ | ---------------- | -------------------------- |
95
+ | HTTP 400 | `BadRequestError` |
96
+ | HTTP 401 | `AuthenticationError` |
97
+ | HTTP 403 | `PermissionDeniedError` |
98
+ | HTTP 404 | `NotFoundError` |
99
+ | HTTP 409 | `ConflictError` |
100
+ | HTTP 422 | `UnprocessableEntityError` |
101
+ | HTTP 429 | `RateLimitError` |
102
+ | HTTP >= 500 | `InternalServerError` |
103
+ | Other HTTP error | `APIStatusError` |
104
+ | Timeout | `APITimeoutError` |
105
+ | Network error | `APIConnectionError` |
106
+
107
+ ### Retries
108
+
109
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
110
+
111
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
112
+
113
+ You can use the `max_retries` option to configure or disable this:
114
+
115
+ ```ruby
116
+ # Configure the default for all requests:
117
+ turbopuffer = Turbopuffer::Client.new(
118
+ max_retries: 0 # default is 2
119
+ )
120
+
121
+ # Or, configure per-request:
122
+ turbopuffer.namespaces(prefix: "foo", request_options: {max_retries: 5})
123
+ ```
124
+
125
+ ### Timeouts
126
+
127
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
128
+
129
+ ```ruby
130
+ # Configure the default for all requests:
131
+ turbopuffer = Turbopuffer::Client.new(
132
+ timeout: nil # default is 60
133
+ )
134
+
135
+ # Or, configure per-request:
136
+ turbopuffer.namespaces(prefix: "foo", request_options: {timeout: 5})
137
+ ```
138
+
139
+ On timeout, `Turbopuffer::Errors::APITimeoutError` is raised.
140
+
141
+ Note that requests that time out are retried by default.
142
+
143
+ ## Advanced concepts
144
+
145
+ ### BaseModel
146
+
147
+ All parameter and response objects inherit from `Turbopuffer::Internal::Type::BaseModel`, which provides several conveniences, including:
148
+
149
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
150
+
151
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
152
+
153
+ 3. Both instances and the classes themselves can be pretty-printed.
154
+
155
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
156
+
157
+ ### Making custom or undocumented requests
158
+
159
+ #### Undocumented properties
160
+
161
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
162
+
163
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
164
+
165
+ ```ruby
166
+ page =
167
+ turbopuffer.namespaces(
168
+ prefix: "foo",
169
+ request_options: {
170
+ extra_query: {my_query_parameter: value},
171
+ extra_body: {my_body_parameter: value},
172
+ extra_headers: {"my-header": value}
173
+ }
174
+ )
175
+
176
+ puts(page[:my_undocumented_property])
177
+ ```
178
+
179
+ #### Undocumented request params
180
+
181
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
182
+
183
+ #### Undocumented endpoints
184
+
185
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
186
+
187
+ ```ruby
188
+ response = client.request(
189
+ method: :post,
190
+ path: '/undocumented/endpoint',
191
+ query: {"dog": "woof"},
192
+ headers: {"useful-header": "interesting-value"},
193
+ body: {"hello": "world"}
194
+ )
195
+ ```
196
+
197
+ ### Concurrency & connection pooling
198
+
199
+ The `Turbopuffer::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
200
+
201
+ Each instance of `Turbopuffer::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
202
+
203
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
204
+
205
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
206
+
207
+ ## Sorbet
208
+
209
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
210
+
211
+ You can provide typesafe request parameters like so:
212
+
213
+ ```ruby
214
+ turbopuffer.namespace("products").write(
215
+ distance_metric: "cosine_distance",
216
+ upsert_rows: [
217
+ Turbopuffer::Row.new(
218
+ id: "2108ed60-6851-49a0-9016-8325434f3845",
219
+ vector: [0.1, 0.2],
220
+ attributes: {name: "Red boots", price: 34.99}
221
+ )
222
+ ]
223
+ )
224
+ ```
225
+
226
+ Or, equivalently:
227
+
228
+ ```ruby
229
+ # Hashes work, but are not typesafe:
230
+ turbopuffer.namespace("products").write(
231
+ distance_metric: "cosine_distance",
232
+ upsert_rows: [
233
+ {id: "2108ed60-6851-49a0-9016-8325434f3845", vector: [0.1, 0.2], attributes: {name: "Red boots", price: 34.99}}
234
+ ]
235
+ )
236
+
237
+ # You can also splat a full Params class:
238
+ params = Turbopuffer::NamespaceWriteParams.new(
239
+ distance_metric: "cosine_distance",
240
+ upsert_rows: [
241
+ Turbopuffer::Row.new(
242
+ id: "2108ed60-6851-49a0-9016-8325434f3845",
243
+ vector: [0.1, 0.2],
244
+ attributes: {name: "Red boots", price: 34.99}
245
+ )
246
+ ]
247
+ )
248
+ turbopuffer.namespace("products").write(**params)
249
+ ```
250
+
251
+ ### Enums
252
+
253
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
254
+
255
+ ```ruby
256
+ # :float
257
+ puts(Turbopuffer::VectorEncoding::FLOAT)
258
+
259
+ # Revealed type: `T.all(Turbopuffer::VectorEncoding, Symbol)`
260
+ T.reveal_type(Turbopuffer::VectorEncoding::FLOAT)
261
+ ```
262
+
263
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
264
+
265
+ ```ruby
266
+ # Using the enum constants preserves the tagged type information:
267
+ turbopuffer.namespaces.multi_query(
268
+ vector_encoding: Turbopuffer::VectorEncoding::FLOAT,
269
+ # …
270
+ )
271
+
272
+ # Literal values are also permissible:
273
+ turbopuffer.namespaces.multi_query(
274
+ vector_encoding: :float,
275
+ # …
276
+ )
277
+ ```
278
+
279
+ ## Versioning
280
+
281
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
282
+
283
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
284
+
285
+ ## Requirements
286
+
287
+ Ruby 3.2.0 or higher.
288
+
289
+ ## Contributing
290
+
291
+ See [the contributing documentation](https://github.com/turbopuffer/turbopuffer-ruby/tree/main/CONTRIBUTING.md).
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
6
+
7
+ To report a security issue, please contact the Stainless team at security@stainless.com.
8
+
9
+ ## Responsible Disclosure
10
+
11
+ We appreciate the efforts of security researchers and individuals who help us maintain the security of
12
+ SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
13
+ disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
14
+ before making any information public.
15
+
16
+ ## Reporting Non-SDK Related Security Issues
17
+
18
+ If you encounter security issues that are not directly related to SDKs but pertain to the services
19
+ or products provided by Turbopuffer, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Turbopuffer Terms and Policies
22
+
23
+ Please contact info@turbopuffer.com for any questions or concerns regarding the security of our services.
24
+
25
+ ---
26
+
27
+ Thank you for helping us keep the SDKs and systems they interact with secure.
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbopuffer
4
+ class Client < Turbopuffer::Internal::Transport::BaseClient
5
+ # Default max number of retries to attempt after a failed retryable request.
6
+ DEFAULT_MAX_RETRIES = 2
7
+
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
10
+
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
14
+
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
17
+
18
+ # API key used for authentication
19
+ # @return [String]
20
+ attr_reader :api_key
21
+
22
+ # The turbopuffer region to use.
23
+ # @return [String, nil]
24
+ attr_reader :region
25
+
26
+ # @return [String, nil]
27
+ attr_reader :default_namespace
28
+
29
+ # Creates a new namespace resource.
30
+ #
31
+ # @param namespace [String] The ID of the namespace.
32
+ #
33
+ # @return [Turbopuffer::Namespace]
34
+ def namespace(namespace)
35
+ Turbopuffer::Namespace.new(self, namespace)
36
+ end
37
+
38
+ # List namespaces.
39
+ #
40
+ # @overload namespaces(cursor: nil, page_size: nil, prefix: nil, request_options: {})
41
+ #
42
+ # @param cursor [String] Retrieve the next page of results.
43
+ #
44
+ # @param page_size [Integer] Limit the number of results per page.
45
+ #
46
+ # @param prefix [String] Retrieve only the namespaces that match the prefix.
47
+ #
48
+ # @param request_options [Turbopuffer::RequestOptions, Hash{Symbol=>Object}, nil]
49
+ #
50
+ # @return [Turbopuffer::Internal::NamespacePage<Turbopuffer::Models::NamespaceSummary>]
51
+ #
52
+ # @see Turbopuffer::Models::ClientNamespacesParams
53
+ def namespaces(params = {})
54
+ parsed, options = Turbopuffer::ClientNamespacesParams.dump_request(params)
55
+ request(
56
+ method: :get,
57
+ path: "v1/namespaces",
58
+ query: parsed,
59
+ page: Turbopuffer::Internal::NamespacePage,
60
+ model: Turbopuffer::NamespaceSummary,
61
+ options: options
62
+ )
63
+ end
64
+
65
+ # @api private
66
+ #
67
+ # @return [Hash{String=>String}]
68
+ private def auth_headers
69
+ return {} if @api_key.nil?
70
+
71
+ {"authorization" => "Bearer #{@api_key}"}
72
+ end
73
+
74
+ # Creates and returns a new client for interacting with the API.
75
+ #
76
+ # @param api_key [String, nil] API key used for authentication Defaults to `ENV["TURBOPUFFER_API_KEY"]`
77
+ #
78
+ # @param region [String, nil] The turbopuffer region to use. Defaults to `ENV["TURBOPUFFER_REGION"]`
79
+ #
80
+ # @param default_namespace [String, nil]
81
+ #
82
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
83
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["TURBOPUFFER_BASE_URL"]`
84
+ #
85
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
86
+ #
87
+ # @param timeout [Float]
88
+ #
89
+ # @param initial_retry_delay [Float]
90
+ #
91
+ # @param max_retry_delay [Float]
92
+ def initialize(
93
+ api_key: ENV["TURBOPUFFER_API_KEY"],
94
+ region: ENV["TURBOPUFFER_REGION"],
95
+ default_namespace: nil,
96
+ base_url: ENV["TURBOPUFFER_BASE_URL"],
97
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
98
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
99
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
100
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
101
+ )
102
+ base_url ||= "https://{region}.turbopuffer.com"
103
+
104
+ if api_key.nil?
105
+ raise ArgumentError.new("api_key is required, and can be set via environ: \"TURBOPUFFER_API_KEY\"")
106
+ end
107
+
108
+ if base_url.include?("{region}")
109
+ if region.nil?
110
+ raise ArgumentError.new("region is required when base_url contains {region} placeholder: #{base_url}")
111
+ end
112
+ base_url = base_url.gsub("{region}", region)
113
+ elsif !region.nil?
114
+ raise ArgumentError.new("region is set, but would be ignored (baseUrl does not contain {region} placeholder: #{base_url})")
115
+ end
116
+
117
+ @default_namespace = default_namespace&.to_s
118
+ @api_key = api_key.to_s
119
+ @region = region&.to_s
120
+
121
+ super(
122
+ base_url: base_url,
123
+ timeout: timeout,
124
+ max_retries: max_retries,
125
+ initial_retry_delay: initial_retry_delay,
126
+ max_retry_delay: max_retry_delay
127
+ )
128
+ end
129
+ end
130
+ end