turbopuffer 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9b214208dbf23c334c0a464b1dcb97937aeab3f74ca8b9afa5a001dc4cb5a2e
4
+ data.tar.gz: b49f0fe71b1423e38e53e07277a6ca8567ea04534279e498466a50cbd59aad1d
5
+ SHA512:
6
+ metadata.gz: 3282d03c38c4f1cecf53d38f7b50356a1fd3571d6f16f422ffab07f25fbe28db2653987850d5b52e5dad2daefba0df803225d4fc6a898b0b6372dae240669659
7
+ data.tar.gz: 4092bf2ccbf9df5e2be3f44752eb2d16b3625f62ea5bd95585451f2b3a4fae8a41b01baaefd759a51e11ce861bcdd492f8ce3598c5e73d3a84fb28ccedb98006
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Adrián Mugnolo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Turbopuffer
2
+
3
+ A Ruby client for accessing the Turbopuffer API.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace
8
+ `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your
9
+ gem name right after releasing it to RubyGems.org. Please do not do it earlier
10
+ due to security reasons. Alternatively, replace this section with instructions
11
+ to install your gem from git if you don't plan to release to RubyGems.org.
12
+
13
+ Install the gem and add to the application's Gemfile by executing:
14
+
15
+ ```bash
16
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by
20
+ executing:
21
+
22
+ ```bash
23
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ tpuf = Turbopuffer::Client.new("your-token")
30
+
31
+ ns = tpuf.namespace("namespace-name")
32
+
33
+ ns.upsert(
34
+ ids: [1, 2],
35
+ vectors: [[0.1, 0.2], [0.3, 0.4]],
36
+ attributes: {name: ["foo", "bar"]}
37
+ )
38
+
39
+ results = ns.query(
40
+ vector: [0.15, 0.22],
41
+ top_k: 10
42
+ )
43
+
44
+ ns.delete_all
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
50
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
51
+ prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To
54
+ release a new version, update the version number in `version.rb`, and then run
55
+ `bundle exec rake release`, which will create a git tag for the version, push
56
+ git commits and the created tag, and push the `.gem` file to
57
+ [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at
62
+ https://github.com/xymbol/turbopuffer-ruby.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT
67
+ License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module Turbopuffer
6
+ class Client
7
+ BASE_URL = "https://api.turbopuffer.com"
8
+
9
+ def initialize(api_token)
10
+ @api_token = api_token
11
+ @connection = Faraday.new(url: BASE_URL) do |conn|
12
+ conn.request :json
13
+ conn.response :json, parser_options: {symbolize_names: true}
14
+ conn.headers["Authorization"] = "Bearer #{@api_token}"
15
+ conn.headers["Accept-Encoding"] = "gzip"
16
+ conn.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+
20
+ def namespace(name)
21
+ Namespace.new(name, @connection)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbopuffer
4
+ class Namespace
5
+ def initialize(name, connection)
6
+ @name = name
7
+ @connection = connection
8
+ end
9
+
10
+ def delete(ids:)
11
+ payload = {
12
+ ids: ids,
13
+ vectors: [nil] * ids.length
14
+ }
15
+ response = @connection.delete("/v1/namespaces/#{@name}", payload)
16
+ handle_response(response)
17
+ end
18
+
19
+ def delete_all
20
+ response = @connection.delete("/v1/namespaces/#{@name}")
21
+ handle_response(response)
22
+ end
23
+
24
+ def query(vector:, top_k: 10, distance_metric: "cosine_distance", filters: nil, include_attributes: false, include_vectors: false)
25
+ payload = {
26
+ vector: vector,
27
+ top_k: top_k,
28
+ distance_metric: distance_metric,
29
+ filters: filters,
30
+ include_attributes: include_attributes,
31
+ include_vectors: include_vectors
32
+ }
33
+ response = @connection.post("/v1/namespaces/#{@name}/query", payload)
34
+ handle_response(response)
35
+ end
36
+
37
+ def upsert(ids:, vectors:, attributes: nil, distance_metric: "cosine_distance")
38
+ payload = {
39
+ ids: ids,
40
+ vectors: vectors,
41
+ attributes: attributes,
42
+ distance_metric: distance_metric
43
+ }
44
+ response = @connection.post("/v1/namespaces/#{@name}", payload)
45
+ handle_response(response)
46
+ end
47
+
48
+ private
49
+
50
+ def handle_response(response)
51
+ if response.success?
52
+ response.body
53
+ else
54
+ raise Error, "API Error: #{response.status} - #{response.body}"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turbopuffer
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "turbopuffer/version"
4
+ require_relative "turbopuffer/client"
5
+ require_relative "turbopuffer/namespace"
6
+
7
+ module Turbopuffer
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Turbopuffer
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turbopuffer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrián Mugnolo
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-01-04 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.12'
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.12'
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.12.2
32
+ description: Turbopuffer is a serverless vector database. This gem lets you access
33
+ the Turbopuffer API from Ruby.
34
+ email:
35
+ - adrian@mugnolo.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".standard.yml"
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - lib/turbopuffer.rb
45
+ - lib/turbopuffer/client.rb
46
+ - lib/turbopuffer/namespace.rb
47
+ - lib/turbopuffer/version.rb
48
+ - sig/turbopuffer.rbs
49
+ homepage: https://github.com/xymbol/turbopuffer-ruby
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/xymbol/turbopuffer-ruby
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.6
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.6.2
69
+ specification_version: 4
70
+ summary: A Ruby client for accessing the Turbopuffer API.
71
+ test_files: []