#core/store

    CoreStore provides contiguous vector storage with id-to-index mapping.

    #Features

    • Compact storage: vectors stored in flat Array[Double] with strided access
    • Automatic normalization for cosine metric
    • O(1) compaction on remove via swap-with-last
    • Id-to-index mapping for fast lookups

    #Usage

    let store = CoreStore::new(128, @types.Cosine, capacity=1024)

    // Add vector
    store.add(id, vector, attrs)

    // Get vector at index
    let (vec, attrs) = store.get_at(idx)

    // Remove by id
    store.remove(id)

    CoreStore

    pub struct CoreStore {
    dim : Int
    metric :
    Metric

    ids : Array[
    VectorId
    ]
    data : Array[Double]
    attrs : Array[
    Attrs
    ]
    pos : Map[
    VectorId
    , Int]
    capacity : Int
    count : Int
    }

    CoreStore: contiguous vector storage + id mapping. Provides a compact foundation for both bruteforce and approximate search. Normalizes vectors for cosine metric, maintains id->index mapping, and supports O(1) compaction on remove.

    CoreStore::add_or_update

    fn CoreStore::add_or_update(self : CoreStore, id :
    VectorId
    , vector : Array[Double], attrs :
    Attrs
    , upsert? : Bool) -> (Int, Bool)

    Add or update a vector. Returns (index, created). If upsert is false and id exists, raises error.

    CoreStore::capacity

    fn CoreStore::capacity(self : CoreStore) -> Int

    Get the current capacity

    CoreStore::deserialize

    fn CoreStore::deserialize(data : Bytes) -> CoreStore

    Deserialize CoreStore from bytes

    CoreStore::ensure_capacity

    fn CoreStore::ensure_capacity(self : CoreStore, extra : Int) -> Bool

    Ensure capacity for additional elements

    CoreStore::get_by_index

    Get vector and attrs by index

    CoreStore::get_index

    Get index for an id

    CoreStore::has

    Check if an id exists in the store

    CoreStore::id_at

    Get vector ID by index.

    CoreStore::new

    fn CoreStore::new(dim : Int, metric :
    Metric
    , capacity? : Int) -> CoreStore

    Create a new CoreStore

    CoreStore::normalize_query

    fn CoreStore::normalize_query(self : CoreStore, q : Array[Double]) -> Array[Double]

    Normalize query vector for cosine metric

    CoreStore::remove_by_id

    Remove a vector by id. Returns move info if compaction occurred.

    CoreStore::serialize

    fn CoreStore::serialize(self : CoreStore) -> Bytes

    Serialize CoreStore to bytes

    CoreStore::shrink_to_fit

    fn CoreStore::shrink_to_fit(self : CoreStore) -> Unit

    Shrink backing arrays to fit current count

    CoreStore::size

    fn CoreStore::size(self : CoreStore) -> Int

    Get the current size (number of vectors)

    CoreStore::update_attrs

    Update only attrs for an id. Returns true if updated.

    MoveInfo

    pub struct MoveInfo {
    moved_id :
    VectorId
    ?
    moved_from : Int?
    moved_to : Int?
    } derive(
    Debug
    )

    Move info returned by remove
    impl Show for MoveInfo

    Source Files