Class: Supabase::Storage::VectorsClient

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/supabase/storage/vectors.rb

Overview

Vector bucket / index / record management. Mirrors storage3’s ‘SyncStorageVectorsClient`. All endpoints are POSTs to actions under `storage_url/vector/…`.

vectors = client.vectors
vectors.create_bucket("docs")
vectors.from("docs").create_index("paragraphs", 1536, "cosine", "float32")
vectors.from("docs").index("paragraphs").put([{ key: "p1", data: { float32: [...] } }])

Instance Method Summary collapse

Constructor Details

#initialize(session, base_url, headers) ⇒ VectorsClient

Returns a new instance of VectorsClient.



20
21
22
23
24
25
# File 'lib/supabase/storage/vectors.rb', line 20

def initialize(session, base_url, headers)
  @session  = session
  normalized = base_url.end_with?("/") ? base_url : "#{base_url}/"
  @base_url = "#{normalized}vector/"
  @headers  = headers
end

Instance Method Details

#create_bucket(bucket_name) ⇒ Object



34
35
36
37
# File 'lib/supabase/storage/vectors.rb', line 34

def create_bucket(bucket_name)
  _request(:post, ["CreateVectorBucket"], json: { "vectorBucketName" => bucket_name })
  nil
end

#delete_bucket(bucket_name) ⇒ Object



54
55
56
57
# File 'lib/supabase/storage/vectors.rb', line 54

def delete_bucket(bucket_name)
  _request(:post, ["DeleteVectorBucket"], json: { "vectorBucketName" => bucket_name })
  nil
end

#from(bucket_name) ⇒ Object Also known as: from_

Scope subsequent index/record operations to a particular vector bucket.



28
29
30
# File 'lib/supabase/storage/vectors.rb', line 28

def from(bucket_name)
  VectorBucketScope.new(self, bucket_name)
end

#get_bucket(bucket_name) ⇒ Object

Returns nil if the bucket doesn’t exist (matches py’s swallow of StorageApiError). Any other API failure still surfaces.



41
42
43
44
45
46
# File 'lib/supabase/storage/vectors.rb', line 41

def get_bucket(bucket_name)
  body = _request(:post, ["GetVectorBucket"], json: { "vectorBucketName" => bucket_name })
  Types::GetVectorBucketResponse.from_hash(body)
rescue Errors::StorageApiError
  nil
end

#list_buckets(prefix: nil, max_results: nil, next_token: nil) ⇒ Object



48
49
50
51
52
# File 'lib/supabase/storage/vectors.rb', line 48

def list_buckets(prefix: nil, max_results: nil, next_token: nil)
  json = { "prefix" => prefix, "maxResults" => max_results, "nextToken" => next_token }.compact
  body = _request(:post, ["ListVectorBuckets"], json: json)
  Types::ListVectorBucketsResponse.from_hash(body)
end

#send_action(path:, json: nil) ⇒ Object

Exposed so the scope classes can reuse our wired-up session/headers without re-implementing ‘_request`. Not part of the public API.



61
62
63
# File 'lib/supabase/storage/vectors.rb', line 61

def send_action(path:, json: nil) # :nodoc:
  _request(:post, [path], json: json)
end