Class: Woods::CostModel::StorageCost

Inherits:
Object
  • Object
show all
Defined in:
lib/woods/cost_model/storage_cost.rb

Overview

Calculates vector storage requirements based on embedding dimensions and chunk count.

Bytes per vector = dimensions × 4 (float32), with a 1.3× metadata overhead factor applied per BACKEND_MATRIX.md.

Examples:

calc = StorageCost.new(dimensions: 1536)
calc.storage_bytes(chunks: 1250) # => 9_984_000
calc.storage_mb(chunks: 1250)    # => 9.52

Constant Summary collapse

BYTES_PER_FLOAT =

Bytes per float32 value.

4
METADATA_OVERHEAD =

Metadata overhead multiplier (JSONB payload, indexes, etc.).

1.3

Instance Method Summary collapse

Constructor Details

#initialize(dimensions:) ⇒ StorageCost

Returns a new instance of StorageCost.

Parameters:

  • dimensions (Integer)

    Embedding vector dimensions



24
25
26
# File 'lib/woods/cost_model/storage_cost.rb', line 24

def initialize(dimensions:)
  @dimensions = dimensions
end

Instance Method Details

#bytes_per_vectorInteger

Bytes per vector including metadata overhead.

Returns:

  • (Integer)


31
32
33
# File 'lib/woods/cost_model/storage_cost.rb', line 31

def bytes_per_vector
  @bytes_per_vector ||= (@dimensions * BYTES_PER_FLOAT * METADATA_OVERHEAD).ceil
end

#storage_bytes(chunks:) ⇒ Integer

Total storage in bytes for a given number of chunks.

Parameters:

  • chunks (Integer)

    Total number of chunks (units × chunk_multiplier)

Returns:

  • (Integer)


39
40
41
# File 'lib/woods/cost_model/storage_cost.rb', line 39

def storage_bytes(chunks:)
  chunks * bytes_per_vector
end

#storage_mb(chunks:) ⇒ Float

Total storage in megabytes for a given number of chunks.

Parameters:

  • chunks (Integer)

    Total number of chunks

Returns:

  • (Float)

    Storage in MB, rounded to 2 decimal places



47
48
49
# File 'lib/woods/cost_model/storage_cost.rb', line 47

def storage_mb(chunks:)
  (storage_bytes(chunks: chunks).to_f / (1024 * 1024)).round(2)
end