Class: Supabase::Storage::VectorIndexScope

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

Overview

A bucket+index-scoped facade for record-level operations. Mirrors storage3’s ‘SyncVectorIndexScope`.

Constant Summary collapse

VECTOR_BATCH_MIN =
1
VECTOR_BATCH_MAX =
500

Instance Method Summary collapse

Constructor Details

#initialize(vectors_client, bucket_name, index_name) ⇒ VectorIndexScope

Returns a new instance of VectorIndexScope.



122
123
124
125
126
# File 'lib/supabase/storage/vectors.rb', line 122

def initialize(vectors_client, bucket_name, index_name)
  @client      = vectors_client
  @bucket_name = bucket_name
  @index_name  = index_name
end

Instance Method Details

#delete(keys) ⇒ Object



169
170
171
172
173
174
175
176
177
# File 'lib/supabase/storage/vectors.rb', line 169

def delete(keys)
  keys = Array(keys)
  if keys.size < VECTOR_BATCH_MIN || keys.size > VECTOR_BATCH_MAX
    raise Errors::VectorBucketException, "Keys batch size must be between #{VECTOR_BATCH_MIN} and #{VECTOR_BATCH_MAX}."
  end

  @client.send_action(path: "DeleteVectors", json: ("keys" => keys))
  nil
end

#get(*keys, return_data: true, return_metadata: true) ⇒ Object



137
138
139
140
141
# File 'lib/supabase/storage/vectors.rb', line 137

def get(*keys, return_data: true, return_metadata: true)
  json = ("keys" => keys, "returnData" => return_data, "returnMetadata" => )
  body = @client.send_action(path: "GetVectors", json: json)
  Types::GetVectorsResponse.from_hash(body)
end

#list(max_results: nil, next_token: nil, return_data: true, return_metadata: true, segment_count: nil, segment_index: nil) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/supabase/storage/vectors.rb', line 143

def list(max_results: nil, next_token: nil, return_data: true, return_metadata: true,
         segment_count: nil, segment_index: nil)
  json = (
    "maxResults"     => max_results,
    "nextToken"      => next_token,
    "returnData"     => return_data,
    "returnMetadata" => ,
    "segmentCount"   => segment_count,
    "segmentIndex"   => segment_index
  )
  body = @client.send_action(path: "ListVectors", json: json)
  Types::ListVectorsResponse.from_hash(body)
end

#put(vectors) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/supabase/storage/vectors.rb', line 128

def put(vectors)
  # Accept either Hashes or VectorMatch-like Structs; serialize hashes
  # directly so callers can pass plain `{ key:, data:, metadata: }`.
  serialized = Array(vectors).map { |v| v.respond_to?(:to_h) ? v.to_h : v }
                             .map { |h| h.reject { |_, val| val.nil? } }
  @client.send_action(path: "PutVectors", json: ("vectors" => serialized))
  nil
end

#query(query_vector, top_k: nil, filter: nil, return_distance: true, return_metadata: true) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/supabase/storage/vectors.rb', line 157

def query(query_vector, top_k: nil, filter: nil, return_distance: true, return_metadata: true)
  json = (
    "queryVector"     => query_vector,
    "topK"            => top_k,
    "filter"          => filter,
    "returnDistance"  => return_distance,
    "returnMetadata"  => 
  )
  body = @client.send_action(path: "QueryVectors", json: json)
  Types::QueryVectorsResponse.from_hash(body)
end