INNER CODE UNIT · Swift
estimatedSizeInBytes
ZachNagengast/similarity-search-kit · Sources/SimilaritySearchKit/Core/Index/SimilarityIndex.swift:380
func estimatedSizeInBytes() -> Int {
var totalSize = 0
for item in indexItems {
// Calculate the size of 'id' property
let idSize = item.id.utf8.count
// Calculate the size of 'text' property
let textSize = item.text.utf8.count
// Calculate the size of 'embedding' property
let floatSize = MemoryLayout<Float>.size
let embeddingSize = item.embedding.count * floatSize
// Calculate the size of 'metadata' property
let metadataSize = item.metadata.reduce(0) { size, keyValue -> Int in
let keySize = keyValue.key.utf8.count
let valueSize = keyValue.value.utf8.count