Table of Contents

Interface IEmbeddingSpendLedger

Namespace
MailFathom.Application.Emails.Embeddings.Limits
Assembly
MailFathom.Application.dll

Keeps the durable count of what each budget period has already sent to a provider, and for whom.

public interface IEmbeddingSpendLedger

Remarks

Durable rather than held in memory, because the failure a spend ceiling exists to prevent is precisely the one an in-process counter cannot see: a process that crashes and restarts in a loop would begin every period again from zero and spend the whole ceiling on each attempt.

It is also deliberately not derived from the stored vectors, which would need no table at all. A generation that is superseded has its vectors removed in bounded batches, so a count taken over them would erase the record of a spend that genuinely happened — and the period in which a model change is paid for is exactly the period an operator is watching.

Every spend names the users it was incurred for, because a deployment serving several people bounds each of them as well as itself and a ledger keyed by the period alone could say only what was spent and never by whom. What the deployment spent is counted separately from them rather than summed out of them, because ADR 0014 counts a shared mailbox in full against each of its users: the per-user figures deliberately add up to more than was sent, and a deployment ceiling read off their sum would stop a shared mailbox at a fraction of what an operator declared. The user outlives its own record here on purpose: ADR 0014 keeps a spend row as a cost record rather than erasing it with the mail it paid to index.

Methods

ReadConsumedInputCharactersAsync(DateTimeOffset, UserId, CancellationToken)

Reads what one period has consumed so far, for one user and for the deployment.

ReadDeploymentConsumedInputCharactersAsync(DateTimeOffset, CancellationToken)

Reads what one period actually sent to a provider, whoever it was counted against.

RecordSpendAsync(IPersistenceSession, DateTimeOffset, IReadOnlyCollection<UserId>, long, CancellationToken)

Adds what one provider call sent, once to the period and in full to each user it is counted against.