Memo::Storage
Low-level storage operations for embeddings and chunks
Instance methods
create_chunk(db : DB::Database, hash : Bytes, source_type : String, source_id : Int64, offset : Int32 | Nil, size : Int32, pair_id : Int64 | Nil = nil, parent_id : Int64 | Nil = nil) : Int64
Create chunk reference (or ignore if already exists)
Returns chunk id if inserted, or 0 if chunk already existed (was ignored)
Get the rowid of an embedding by hash and service_id.
get_service_by_format_model(db : DB::Database, format : String, model : String) : Tuple(Int64, String, String | Nil, String, Int32, Int32, Float64) | Nil
Returns service record by format and model, or nil if not found
get_service_by_name(db : DB::Database, name : String) : Tuple(Int64, String, String | Nil, String, Int32, Int32, Float64) | Nil
Get service by name
Increment match_count for chunks
Increment read_count for chunks
register_service(db : DB::Database, name : String | Nil, format : String, base_url : String | Nil, model : String, dimensions : Int32, max_tokens : Int32) : Int64
Register or get existing service by name
Serialize embedding to binary blob (Int16 for 50% storage reduction)
store_embedding(db : DB::Database, hash : Bytes, token_count : Int32, service_id : Int64) : Tuple(Bool, Int64)
Register embedding hash in database (deduplicated by hash + service_id)
Returns {inserted, rowid} where inserted is true if new, rowid is the USearch key.
Update tokens_per_byte ratio using exponential moving average