Module: Phronomy::VectorStore::AsyncBackend

Included in:
Base
Defined in:
lib/phronomy/vector_store/async_backend.rb

Overview

Mixin that defines the async interface for VectorStore backends.

Mixing this module into a VectorStore class provides three choices:

  1. Do nothing — inherits default implementations from Base that route through BlockingAdapterPool (the previous behaviour).

  2. Override selectively — override only the async methods where the backend has a native async driver, while the remaining methods fall back to the pool.

  3. Implement all natively — override all async methods to avoid pool allocation entirely.

Examples:

Native async search (no pool worker thread allocated)

class MyFastStore < Phronomy::VectorStore::Base
  include Phronomy::VectorStore::AsyncBackend

  def search_async(query_embedding:, k: 5, cancellation_token: nil, timeout: nil)
    # Returns a PendingOperation backed by a native async driver.
    native_async_search(query_embedding, k)
  end
end

Instance Method Summary collapse

Instance Method Details

#add_async(id:, embedding:, metadata: {}, cancellation_token: nil, timeout: nil) ⇒ BlockingAdapterPool::PendingOperation

Async variant of Base#add.

Submits the add call to BlockingAdapterPool by default. Override to use a native async driver.

Parameters:

  • id (String)
  • embedding (Array<Float>)
  • metadata (Hash) (defaults to: {})
  • cancellation_token (Phronomy::CancellationToken, nil) (defaults to: nil)
  • timeout (Numeric, nil) (defaults to: nil)

Returns:



43
44
45
46
47
48
49
50
# File 'lib/phronomy/vector_store/async_backend.rb', line 43

def add_async(id:, embedding:, metadata: {}, cancellation_token: nil, timeout: nil)
  Phronomy::Runtime.instance.blocking_io.submit(
    timeout: timeout,
    cancellation_token: cancellation_token
  ) do
    add(id: id, embedding: embedding, metadata: , cancellation_token: cancellation_token)
  end
end

#clear_async(cancellation_token: nil, timeout: nil) ⇒ BlockingAdapterPool::PendingOperation

Async variant of Base#clear.

Submits the clear call to BlockingAdapterPool by default. Override to use a native async driver.

Parameters:

Returns:



100
101
102
103
104
105
106
107
# File 'lib/phronomy/vector_store/async_backend.rb', line 100

def clear_async(cancellation_token: nil, timeout: nil)
  Phronomy::Runtime.instance.blocking_io.submit(
    timeout: timeout,
    cancellation_token: cancellation_token
  ) do
    clear
  end
end

#remove_async(id:, cancellation_token: nil, timeout: nil) ⇒ BlockingAdapterPool::PendingOperation

Async variant of Base#remove.

Submits the remove call to BlockingAdapterPool by default. Override to use a native async driver.

Parameters:

Returns:



82
83
84
85
86
87
88
89
# File 'lib/phronomy/vector_store/async_backend.rb', line 82

def remove_async(id:, cancellation_token: nil, timeout: nil)
  Phronomy::Runtime.instance.blocking_io.submit(
    timeout: timeout,
    cancellation_token: cancellation_token
  ) do
    remove(id: id)
  end
end

#search_async(query_embedding:, k: 5, cancellation_token: nil, timeout: nil) ⇒ BlockingAdapterPool::PendingOperation

Async variant of Base#search.

Submits the search call to BlockingAdapterPool by default. Override to use a native async driver.

Parameters:

  • query_embedding (Array<Float>)
  • k (Integer) (defaults to: 5)
  • cancellation_token (Phronomy::CancellationToken, nil) (defaults to: nil)
  • timeout (Numeric, nil) (defaults to: nil)

Returns:



63
64
65
66
67
68
69
70
# File 'lib/phronomy/vector_store/async_backend.rb', line 63

def search_async(query_embedding:, k: 5, cancellation_token: nil, timeout: nil)
  Phronomy::Runtime.instance.blocking_io.submit(
    timeout: timeout,
    cancellation_token: cancellation_token
  ) do
    search(query_embedding: query_embedding, k: k, cancellation_token: cancellation_token)
  end
end