Skip to content

Repository

Repository: entity CRUD across the mapped stores.

Each store keeps its part of an entity (rhizodat.core.parts). A write adds a version of every part in one Unit of Work, so the parts of one version always share a dat_txn; a read assembles the parts of one version.

  • Repository works inside a Unit of Work (uow.repository(T)): its writes commit with the rest of the work, its reads see them.
  • EntityRepository is the facade's (dat.repository(T)): each write is one Unit of Work of its own, with retries; reads go to the committed data and take as_of (transaction time).

A Vector field is checked on write and stored like any list of floats, so re-embedding is a new version. EntityRepository.similar finds the entities whose vectors are nearest to a query among the versions valid at a moment: an exact scan of the store's versions (ScansParts), without an index.

Delete is a hard delete, erasing every version in every store, unless the type is declared with soft_delete: then it adds a version marked deleted, hidden from reads, restorable within the window and erased by purge_expired after.

EntityRepository

dat.repository(T): committed reads, and one Unit of Work per write.

get

get(
    dat_id: UUID,
    *,
    as_of: datetime | None = None,
    known_at: datetime | None = None,
    include_deleted: bool = False,
) -> T | None

The entity as known at known_at (now if None).

For a type with valid time, the version that holds at as_of (now if None): among the versions known then, the latest one whose period contains it. Without valid time as_of and known_at both name the moment of knowledge; give one of them.

history

history(dat_id: UUID) -> list[T]

Every committed version, oldest first (soft deletes included).

similar

similar(
    field: str,
    query: str | Sequence[float],
    *,
    k: int = 10,
    as_of: datetime | None = None,
    known_at: datetime | None = None,
    embedder: Embedder | None = None,
) -> list[Match[T]]

The k entities whose field vector is nearest to query, closest first.

query is a vector, or a text embedded with embedder (the model that made the stored vectors). Only the version get would return at the same as_of / known_at counts; entities without a vector there are left out.

restore

restore(dat_id: UUID) -> Outcome

Bring a soft-deleted entity back; value is the restored entity.

purge_expired

purge_expired(*, limit: int = 1000) -> int

Erase soft-deleted entities whose window is over; how many were erased.

Repository

Entity reads and writes inside one Unit of Work.

created instance-attribute

created: dict[UUID, int | None] = {}

Creation time of each entity this repository wrote; None: created now.

get

get(
    dat_id: UUID, *, include_deleted: bool = False
) -> T | None

The latest version, this Unit of Work's writes included.

save

save(obj: T) -> None

add or update, whichever applies.

purge

purge(dat_id: UUID, *, deleted_before: int) -> bool

Erase a soft-deleted entity if it is still deleted and old enough.

NotRestorable

Bases: Exception

restore of an entity that is not soft-deleted, or left its window.