pub struct SqliteStore { /* private fields */ }Expand description
Every write (via with_txn or a direct execute) goes through writer,
the single connection WAL reserves for the one process-wide writer. Reads
go through readers: a pool of separate connections in file-backed mode,
or the same connection as the writer for in_memory, where a second
connection would just see an empty, unrelated database.
Implementations§
Source§impl SqliteStore
impl SqliteStore
pub fn record_peer_view(&self, tag: &IdentityTag, view: &PeerView) -> Result<()>
Sourcepub fn peer_views(&self, tag: &IdentityTag) -> Result<Vec<PeerView>>
pub fn peer_views(&self, tag: &IdentityTag) -> Result<Vec<PeerView>>
Every view recorded under tag, ordered by peer id.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn recovery_recipients(&self, tag: &IdentityTag) -> Result<Vec<Recipient>>
pub fn recovery_recipients(&self, tag: &IdentityTag) -> Result<Vec<Recipient>>
The recovery recipients this device wraps tag’s epochs to: the
recipients of its envelopes that name no machine, less retired ones.
Handshakes only store envelopes addressed to this machine, so a peer
never adds one.
Sourcepub fn recovery_envelopes(&self, recipient: &Recipient) -> Result<Vec<Envelope>>
pub fn recovery_envelopes(&self, recipient: &Recipient) -> Result<Vec<Envelope>>
Every envelope, under any identity, wrapped to recipient with no
machine id.
pub fn recovery_offered(&self) -> Result<bool>
pub fn mark_recovery_offered(&self, now_micros: i64) -> Result<()>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn put_retirement(
&self,
signed: &SignedRetirement,
retirer_key: &VerifyingKey,
) -> Result<bool>
pub fn put_retirement( &self, signed: &SignedRetirement, retirer_key: &VerifyingKey, ) -> Result<bool>
Keeps a retirement verified under its retirer’s key. Which retirers count is the caller’s rule. A fingerprint so far retired only by an epoch’s cause gains the signed record; otherwise the first stored under its identity stays and this returns false.
Sourcepub fn note_named_retirements(&self, tag: &IdentityTag) -> Result<Vec<String>>
pub fn note_named_retirements(&self, tag: &IdentityTag) -> Result<Vec<String>>
Records each well-formed fingerprint an epoch cause of tag names
that no retirement here covers yet, unsigned: the epoch was taken, so
the phrase must open nothing here even when the signed retirement
cannot be verified. Returns the fingerprints recorded.
Sourcepub fn retirements(&self, tag: &IdentityTag) -> Result<Vec<SignedRetirement>>
pub fn retirements(&self, tag: &IdentityTag) -> Result<Vec<SignedRetirement>>
The signed retirements stored under tag, by fingerprint.
Sourcepub fn retired_under(
&self,
tag: &IdentityTag,
) -> Result<Vec<(String, Option<SignedRetirement>)>>
pub fn retired_under( &self, tag: &IdentityTag, ) -> Result<Vec<(String, Option<SignedRetirement>)>>
Every fingerprint retired under tag, with its signed retirement
when one was verified here; None for one only an epoch’s cause named.
Sourcepub fn retired_fingerprints(&self) -> Result<BTreeSet<String>>
pub fn retired_fingerprints(&self) -> Result<BTreeSet<String>>
Every retired fingerprint, under any identity.
Sourcepub fn rotating_retirements(
&self,
tag: &IdentityTag,
) -> Result<BTreeSet<String>>
pub fn rotating_retirements( &self, tag: &IdentityTag, ) -> Result<BTreeSet<String>>
The fingerprints retired under tag whose retirement calls for a new
epoch and a new store key.
Sourcepub fn mark_rotating_retirements(
&self,
tag: &IdentityTag,
) -> Result<Vec<String>>
pub fn mark_rotating_retirements( &self, tag: &IdentityTag, ) -> Result<Vec<String>>
Marks the retirements under tag, signed or named by a cause, whose
phrase a device of tag not revoked lists in its row, or this device
still wraps to, as calling for rotation; the mark is sticky. Made-up
fingerprints listed by no one are kept but rotate nothing. Run before
delete_retired_envelopes. Returns the newly marked fingerprints.
Sourcepub fn epochs_wrapped_to_retired(&self, tag: &IdentityTag) -> Result<Vec<Epoch>>
pub fn epochs_wrapped_to_retired(&self, tag: &IdentityTag) -> Result<Vec<Epoch>>
The epochs of tag this store holds an envelope for to a retired
recovery recipient.
Sourcepub fn delete_retired_envelopes(&self) -> Result<usize>
pub fn delete_retired_envelopes(&self) -> Result<usize>
Deletes every envelope, under any identity, wrapped to a retired recovery recipient. Returns how many went.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn put_revocation(
&self,
signed: &SignedRevocation,
revoker_key: &VerifyingKey,
) -> Result<bool>
pub fn put_revocation( &self, signed: &SignedRevocation, revoker_key: &VerifyingKey, ) -> Result<bool>
Keeps a revocation verified under its revoker’s key on the target’s
machine row, creating a bare row for a target this store has not
seen. Which revokers count is the caller’s rule. Returns false when
it was already stored. apply_revocations marks the devices it
reaches.
pub fn revocations(&self, tag: &IdentityTag) -> Result<Vec<SignedRevocation>>
Sourcepub fn revoked_by_rule(
&self,
tag: &IdentityTag,
extra: Option<&Revocation>,
) -> Result<BTreeSet<String>>
pub fn revoked_by_rule( &self, tag: &IdentityTag, extra: Option<&Revocation>, ) -> Result<BTreeSet<String>>
The devices of tag that its stored revocations reach, plus those
extra would reach, from the first rows held now.
Sourcepub fn revokers_of(
&self,
tag: &IdentityTag,
machine_id: &str,
) -> Result<BTreeSet<String>>
pub fn revokers_of( &self, tag: &IdentityTag, machine_id: &str, ) -> Result<BTreeSet<String>>
The revokers of the stored revocations of tag whose rule reaches
machine_id.
Sourcepub fn apply_revocations(&self, tag: &IdentityTag) -> Result<Vec<String>>
pub fn apply_revocations(&self, tag: &IdentityTag) -> Result<Vec<String>>
Marks every device the stored revocations of tag reach as revoked,
which is sticky, drops their log floor acks and pins, and returns
those newly marked.
Sourcepub fn frame_floor(&self, tag: &IdentityTag, peer: &str) -> Result<Option<u32>>
pub fn frame_floor(&self, tag: &IdentityTag, peer: &str) -> Result<Option<u32>>
The lowest epoch number peer may still seal wire frames under.
Sourcepub fn raise_frame_floor(
&self,
tag: &IdentityTag,
peer: &str,
number: u32,
) -> Result<bool>
pub fn raise_frame_floor( &self, tag: &IdentityTag, peer: &str, number: u32, ) -> Result<bool>
Raises the floor for peer, never lowering it; returns true when it
moved.
Source§impl SqliteStore
impl SqliteStore
pub fn device_route(&self, machine_id: &str) -> Result<Option<DeviceRoute>>
pub fn device_routes(&self) -> Result<Vec<DeviceRoute>>
Sourcepub fn set_device_route(&self, route: DeviceRoute) -> Result<()>
pub fn set_device_route(&self, route: DeviceRoute) -> Result<()>
Replaces what this store knows about reaching route.machine_id.
Sourcepub fn merge_device_routes(
&self,
sender: &str,
routes: &[DeviceRoute],
) -> Result<bool>
pub fn merge_device_routes( &self, sender: &str, routes: &[DeviceRoute], ) -> Result<bool>
Takes the routes a peer sent in its handshake: its own addresses go first, ahead of those this store already knew for it, and one it relays for a third device only adds to what this store already knows. Routes to this device and to machines with no active row here are ignored. True when anything changed.
pub fn legacy_routes(&self) -> Result<Vec<(String, LegacyRoute)>>
pub fn set_legacy_route( &self, machine_id: &str, route: &LegacyRoute, ) -> Result<()>
Sourcepub fn sync_peers_migrated(&self) -> Result<bool>
pub fn sync_peers_migrated(&self) -> Result<bool>
Set once every sync-peers line has been matched to a device, after
which the file is no longer read.
pub fn mark_sync_peers_migrated(&self) -> Result<()>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn put_key_epoch(
&self,
tag: &IdentityTag,
epoch: &Epoch,
cause: Option<&str>,
created_at: i64,
) -> Result<bool>
pub fn put_key_epoch( &self, tag: &IdentityTag, epoch: &Epoch, cause: Option<&str>, created_at: i64, ) -> Result<bool>
Records an epoch once, filling in its cause if a later call brings one; returns false when the epoch was already known.
pub fn key_epochs(&self, tag: &IdentityTag) -> Result<Vec<StoredEpoch>>
Sourcepub fn put_envelope(&self, envelope: &Envelope) -> Result<bool>
pub fn put_envelope(&self, envelope: &Envelope) -> Result<bool>
Keeps the first envelope stored for an epoch and recipient; age output is randomized, so a second wrap of the same key is a different blob carrying nothing new. Returns false when one was already stored.
pub fn envelope( &self, tag: &IdentityTag, epoch: &Epoch, recipient: &str, ) -> Result<Option<Envelope>>
pub fn envelopes_for_epoch( &self, tag: &IdentityTag, epoch: &Epoch, ) -> Result<Vec<Envelope>>
pub fn envelopes_for_machine(&self, machine_id: &str) -> Result<Vec<Envelope>>
Sourcepub fn insert_first_device_record(
&self,
signed: &SignedRecord,
signer: &str,
signer_key: &VerifyingKey,
) -> Result<bool>
pub fn insert_first_device_record( &self, signed: &SignedRecord, signer: &str, signer_key: &VerifyingKey, ) -> Result<bool>
Stores a device’s first record after checking it is signed by
signer under signer_key. Which signer may introduce a device
(the founder, a pairing device, a migration self-signature) is the
caller’s rule. Only that verified signature is stored, and the same
first record arriving under another signer gains its signature.
Returns false when nothing new was stored.
Sourcepub fn update_device_record(&self, signed: &SignedRecord) -> Result<bool>
pub fn update_device_record(&self, signed: &SignedRecord) -> Result<bool>
Replaces a device’s current record with a later version it signed itself under its current key, keeping only that signature. Returns false when that version is already stored unchanged.
Sourcepub fn replace_device_record_for_new_identity(
&self,
signed: &SignedRecord,
signer: &str,
signer_key: &VerifyingKey,
) -> Result<bool>
pub fn replace_device_record_for_new_identity( &self, signed: &SignedRecord, signer: &str, signer_key: &VerifyingKey, ) -> Result<bool>
Stores a first record that moves a device into another identity,
after checking it is signed by signer under signer_key. The row
held for that machine id under its earlier identity is replaced, and
its revoked flag cleared, since revocations apply per identity; the
caller reapplies the new identity’s revocations. A machine with no
row gets this one as its first. Returns false when the record is
already the stored first record.
pub fn device_record( &self, machine_id: &str, ) -> Result<Option<StoredDeviceRecord>>
pub fn device_records(&self) -> Result<Vec<StoredDeviceRecord>>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn put_keys_durably(
&self,
tag: &IdentityTag,
epochs: &[Epoch],
envelopes: &[Envelope],
created_at: i64,
) -> Result<()>
pub fn put_keys_durably( &self, tag: &IdentityTag, epochs: &[Epoch], envelopes: &[Envelope], created_at: i64, ) -> Result<()>
Commits the epochs and envelopes with the WAL synced to disk, so the caller may delete the only other copy of a key once this returns. Rows already stored are kept as they are.
Sourcepub fn own_identity_envelopes(
&self,
recipient: &str,
) -> Result<Option<(IdentityTag, Vec<Envelope>)>>
pub fn own_identity_envelopes( &self, recipient: &str, ) -> Result<Option<(IdentityTag, Vec<Envelope>)>>
This device’s identity, named by its own device record, and the
envelopes of that identity wrapped to recipient. None until the
store holds the record.
Sourcepub fn delete_envelope(
&self,
tag: &IdentityTag,
epoch: &Epoch,
recipient: &str,
) -> Result<bool>
pub fn delete_envelope( &self, tag: &IdentityTag, epoch: &Epoch, recipient: &str, ) -> Result<bool>
Returns false when no envelope was stored for that epoch and recipient.
Sourcepub fn known_peer_ids(&self) -> Result<BTreeSet<String>>
pub fn known_peer_ids(&self) -> Result<BTreeSet<String>>
Every other machine this store has synced with or holds records
from: sync cursor keys (with any push: prefix removed) and the
origins in the sync log.
Source§impl SqliteStore
impl SqliteStore
pub fn live_counts(&self) -> Result<LiveCounts>
Sourcepub fn outbox_pending(&self) -> Result<u64>
pub fn outbox_pending(&self) -> Result<u64>
Outbox rows the index drain has not applied yet. While any are pending the index counts lag the store by design, so a count mismatch then is not drift.
pub fn integrity_report( &self, indexes: Option<&Indexes>, ) -> Result<IntegrityReport>
Sourcepub fn repair(
&self,
indexes: Option<&mut Indexes>,
embed: Option<EmbedFn<'_>>,
dry_run: bool,
) -> Result<RepairStats>
pub fn repair( &self, indexes: Option<&mut Indexes>, embed: Option<EmbedFn<'_>>, dry_run: bool, ) -> Result<RepairStats>
Restores every invariant in IntegrityReport::drift, each step in
its own transactions so a failure part-way leaves earlier steps
committed. With indexes, the outbox is drained before the key
garbage collection and before the consistency check, so one pass
leaves nothing for the next. dry_run counts without writing.
Sourcepub fn backfill_embeddings(
&self,
embed: EmbedFn<'_>,
dry_run: bool,
) -> Result<(u64, u64)>
pub fn backfill_embeddings( &self, embed: EmbedFn<'_>, dry_run: bool, ) -> Result<(u64, u64)>
Embeds hot rows that have none, over the same context-plus-content
body the ingest path embeds. updated_at is bumped so the peer’s
last-writer-wins check accepts the row that now carries a vector.
Runs only this step of repair, so a caller that must not merge or
retire rows can fill vectors on its own schedule. Returns (rows
embedded, rows whose embedding failed or had the wrong dimension);
with dry_run it counts rows awaiting a vector and writes nothing.
Sourcepub fn backfill_chunk_embeddings(
&self,
embed: EmbedBatchFn<'_>,
max_memories: usize,
budget: Duration,
) -> Result<ChunkBackfill>
pub fn backfill_chunk_embeddings( &self, embed: EmbedBatchFn<'_>, max_memories: usize, budget: Duration, ) -> Result<ChunkBackfill>
Embeds the chunk sets of up to max_memories memories that need
them and stores each set whole via store_chunks, which queues the
index upsert. Texts go to embed in batches of at most 16 (a padded
ONNX batch of 64 held about 2.4 GB of arena, past the Pi’s cap), whole
memories per batch; once budget has elapsed no further batch
starts, so a caller on a shared thread gets it back promptly. A
memory any of whose vectors fails or has the wrong dimension counts
as failed and is left for a later call. Records the remaining
pending count for chunk_progress.
Sourcepub fn sync_log_row_exists(&self, local_seq: u64) -> Result<bool>
pub fn sync_log_row_exists(&self, local_seq: u64) -> Result<bool>
Whether a sync_log row with this local_seq still exists; a test and diagnostic hook for the sync log garbage collector.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn near_duplicate_groups(
&self,
indexes: &Indexes,
threshold: f32,
limit: usize,
) -> Result<NearDupListing>
pub fn near_duplicate_groups( &self, indexes: &Indexes, threshold: f32, limit: usize, ) -> Result<NearDupListing>
Groups of live distillates sharing a project and type whose cosine is
at least threshold, closest group first, at most limit, with the
total number of groups.
pub fn near_duplicate_group_count( &self, indexes: &Indexes, threshold: f32, ) -> Result<usize>
Sourcepub fn check_merge(
&self,
member_ids: &[Uuid],
) -> Result<Result<(), MergeRefusal>>
pub fn check_merge( &self, member_ids: &[Uuid], ) -> Result<Result<(), MergeRefusal>>
The member checks merge_distillates makes, read-only, so a caller
can refuse a doomed merge before paying for its embedding.
Sourcepub fn merge_distillates(
&self,
member_ids: &[Uuid],
content: &str,
embedding: Vec<f32>,
model: &str,
) -> Result<Result<MergeReport, MergeRefusal>>
pub fn merge_distillates( &self, member_ids: &[Uuid], content: &str, embedding: Vec<f32>, model: &str, ) -> Result<Result<MergeReport, MergeRefusal>>
One transaction: store content as a distillate of the members’
project, type and scope, supersede every member by it and move each
raw’s distillation marker onto it. Refused without writing anything
unless the members are 2 to 4 distinct live distillates sharing all
three. Merges for the store’s owner: members by different authors
give a distillate authored by this store.
Sourcepub fn record_near_duplicate_review(
&self,
member_ids: &[Uuid],
verdict: ReviewVerdict,
) -> Result<Result<u64, MergeRefusal>>
pub fn record_near_duplicate_review( &self, member_ids: &[Uuid], verdict: ReviewVerdict, ) -> Result<Result<u64, MergeRefusal>>
Links every pair of member_ids with the verdict’s relation and
context (see ReviewVerdict::relation); returns how many links were
new. A pair holds one edge per relation type, so a later separate
or unmerged verdict replaces the earlier one.
Sourcepub fn reopen_near_duplicate_reviews(
&self,
verdicts: &[ReviewVerdict],
) -> Result<u64>
pub fn reopen_near_duplicate_reviews( &self, verdicts: &[ReviewVerdict], ) -> Result<u64>
Deletes the review edges of verdicts, replicated as relation
deletes, so their pairs are grouped again on every peer. Returns how
many edges were removed; a rerun removes nothing.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn backfill_session_at(
&self,
evidence: &dyn SessionEvidence,
dry_run: bool,
reemit: bool,
) -> Result<SessionBackfillReport>
pub fn backfill_session_at( &self, evidence: &dyn SessionEvidence, dry_run: bool, reemit: bool, ) -> Result<SessionBackfillReport>
Fills a NULL session_at from the strongest evidence each memory has
(see SessionTier) and logs a sync Update per row, without touching
updated_at: peers merge the date apart from last-write-wins, so the
Update never beats a newer edit made elsewhere. A date already set is
never replaced, so a second run writes nothing. reemit also relogs
every date set before this run, for a peer that upgraded late.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn at_rest_keys(&self, purpose: AtRestPurpose) -> Result<Option<AtRestKeys>>
pub fn at_rest_keys(&self, purpose: AtRestPurpose) -> Result<Option<AtRestKeys>>
The keys files for purpose are sealed under; None for a store with
no store key, whose files stay plaintext. The first call mints them.
Once the store key has changed since the current key was minted (a
rotation, or the store’s first encryption), a new current key is
minted and the old one is kept as retired until the files are
resealed, so a copy of the old store key opens none of the files
written after that.
Sourcepub fn settle_at_rest_keys(
&self,
purpose: AtRestPurpose,
current: SealKeyId,
) -> Result<()>
pub fn settle_at_rest_keys( &self, purpose: AtRestPurpose, current: SealKeyId, ) -> Result<()>
Records that every file for purpose is sealed under current, and
forgets the retired keys. Nothing changes if current is no longer
the current key.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn ingest_memory_if_absent(&self, memory: &Memory) -> Result<bool>
pub fn ingest_memory_if_absent(&self, memory: &Memory) -> Result<bool>
store_memory_if_absent for ingest, which also skips a memory whose
text a delete removed from the same source, so a source file still
on disk cannot bring it back under a new id.
Sourcepub fn ingest_blocked(&self, memory: &Memory) -> Result<bool>
pub fn ingest_blocked(&self, memory: &Memory) -> Result<bool>
Whether a delete removed this memory’s text from its source.
Source§impl SqliteStore
impl SqliteStore
pub fn bootstrap_state(&self) -> Result<Option<BootstrapState>>
Sourcepub fn set_bootstrap_state(&self, state: Option<BootstrapState>) -> Result<()>
pub fn set_bootstrap_state(&self, state: Option<BootstrapState>) -> Result<()>
None clears the state.
Sourcepub fn holds_replicated_rows(&self) -> Result<bool>
pub fn holds_replicated_rows(&self) -> Result<bool>
True when any memory, entity, conversation or relation is stored.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn chunks_needing_embedding(&self, limit: usize) -> Result<Vec<ChunkWork>>
pub fn chunks_needing_embedding(&self, limit: usize) -> Result<Vec<ChunkWork>>
Live memories that split into two or more chunks and whose stored set is absent or was split from other content, oldest first. Splitting happens here in Rust, so every candidate row is split on each call; the length floor only skips rows too short to yield two chunks.
Sourcepub fn scan_chunk_work(&self, limit: usize) -> Result<(Vec<ChunkWork>, usize)>
pub fn scan_chunk_work(&self, limit: usize) -> Result<(Vec<ChunkWork>, usize)>
chunks_needing_embedding, plus the total number of memories needing
chunks. Counting past limit keeps scanning the whole table but
holds on to nothing beyond the first limit.
Sourcepub fn chunk_progress(&self) -> Result<(usize, Option<usize>)>
pub fn chunk_progress(&self) -> Result<(usize, Option<usize>)>
(live memories holding a chunk set, memories still needing one as of the last chunk backfill). The second is None before any backfill has run, because counting it fresh means splitting every live row.
Sourcepub fn store_chunks(
&self,
memory_id: Uuid,
content_hash: &str,
chunks: &[(usize, String, Vec<f32>)],
) -> Result<bool>
pub fn store_chunks( &self, memory_id: Uuid, content_hash: &str, chunks: &[(usize, String, Vec<f32>)], ) -> Result<bool>
Replaces the memory’s whole chunk set and queues an index upsert for
it, in one transaction. Returns false, writing nothing, when the
memory is no longer live or its content no longer hashes to
content_hash. Chunks are derived locally on every peer, so nothing
here touches sync_log.
pub fn chunks_for(&self, memory_id: Uuid) -> Result<Vec<MemoryChunk>>
pub fn delete_chunks(&self, memory_id: Uuid) -> Result<()>
Sourcepub fn chunk_vec_key(&self, memory_id: Uuid, ord: usize) -> Result<u64>
pub fn chunk_vec_key(&self, memory_id: Uuid, ord: usize) -> Result<u64>
Stable u64 key in chunks.usearch for one chunk, allocated on first
use, mirroring vec_key.
Sourcepub fn chunk_vec_keys_for(&self, memory_id: Uuid) -> Result<Vec<(usize, u64)>>
pub fn chunk_vec_keys_for(&self, memory_id: Uuid) -> Result<Vec<(usize, u64)>>
(ord, key) pairs allocated for the memory, by ord.
Sourcepub fn delete_chunk_vec_key(&self, memory_id: Uuid, ord: usize) -> Result<()>
pub fn delete_chunk_vec_key(&self, memory_id: Uuid, ord: usize) -> Result<()>
Drops the key row once its vector is gone from chunks.usearch, so
chunk_vec_keys only holds keys the index can still resolve.
pub fn chunk_for_vec_key(&self, key: u64) -> Result<Option<(Uuid, usize)>>
Sourcepub fn embedded_chunk_count(&self, dim: usize) -> Result<usize>
pub fn embedded_chunk_count(&self, dim: usize) -> Result<usize>
Chunk rows of live memories whose embedding has exactly dim
components: what chunks.usearch should hold once drained.
Sourcepub fn live_chunked_memories(&self) -> Result<Vec<(Uuid, String)>>
pub fn live_chunked_memories(&self) -> Result<Vec<(Uuid, String)>>
Live memories holding a chunk set, each with the hash of its current content, which the set must match to still be indexed.
Sourcepub fn purge_chunks_outside_live_set(&self) -> Result<()>
pub fn purge_chunks_outside_live_set(&self) -> Result<()>
Deletes chunk rows and chunk keys of every memory outside the live set. Only a full rebuild calls this, because it resets the chunk index first and so has no vectors to remove per key.
Sourcepub fn filtered_chunk_search(
&self,
embedding: &[f32],
source: Option<&str>,
memory_type: Option<MemoryType>,
project_path: Option<&str>,
limit: usize,
) -> Result<Vec<(Uuid, f32, usize)>>
pub fn filtered_chunk_search( &self, embedding: &[f32], source: Option<&str>, memory_type: Option<MemoryType>, project_path: Option<&str>, limit: usize, ) -> Result<Vec<(Uuid, f32, usize)>>
The scoped counterpart of Indexes::chunk_search: a brute-force
cosine scan of the embedded chunks of live in-scope memories,
returning each memory’s best (memory id, cosine, ord) for the top
limit memories, best first. Rows arrive grouped by memory (the
primary key’s order), so only the running best of one memory and the
top limit are ever held, however wide the scope.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn attach_cold_tier(&self, tier: Arc<ColdTier>) -> bool
pub fn attach_cold_tier(&self, tier: Arc<ColdTier>) -> bool
Gives the store the cold tier its cold rows live in. Only the first call takes effect; returns whether this one did.
pub fn cold_tier(&self) -> Option<&Arc<ColdTier>>
Sourcepub fn cold_record(&self, id: Uuid) -> Result<Option<ColdRecord>>
pub fn cold_record(&self, id: Uuid) -> Result<Option<ColdRecord>>
The full text and embedding of memory id from its cold segment, or
None when the row is not cold. A segment that fails to open is an
error, never an absent record.
Sourcepub fn get_memory_full(&self, id: Uuid) -> Result<Option<Memory>>
pub fn get_memory_full(&self, id: Uuid) -> Result<Option<Memory>>
get_memory_with_embedding with a cold row’s content and embedding
read back from its segment. Store readers otherwise see the stub.
Sourcepub fn seal_cold_segment(&self, older_than: DateTime<Utc>) -> Result<ColdSeal>
pub fn seal_cold_segment(&self, older_than: DateTime<Utc>) -> Result<ColdSeal>
Moves up to one segment’s worth of archived raws older than
older_than into a new cold segment. Each row keeps a stub of its
content and loses its embedding; updated_at, the sync log and the
index outbox are left alone, because archiving is local. A row that
changed after it was read, its embedding included, stays as it is.
pub fn cold_manifest(&self, segment: &str) -> Result<Option<String>>
Sourcepub fn check_cold_segments(&self) -> Result<Vec<UnreadableSegment>>
pub fn check_cold_segments(&self) -> Result<Vec<UnreadableSegment>>
Opens every segment’s header so one that would fail a recall shows up in status first. Returns the segments that failed.
Sourcepub fn run_cold_pass(
&self,
now: DateTime<Utc>,
pause: Duration,
) -> Result<ColdPassReport>
pub fn run_cold_pass( &self, now: DateTime<Utc>, pause: Duration, ) -> Result<ColdPassReport>
One full cold pass: deletes files earlier passes retired, retires or rewrites segments holding records no row points at, seals until nothing is old enough (pausing between segments so other writers get the writer lock), then checks every segment.
Sourcepub fn cold_stats(&self) -> Result<ColdStats>
pub fn cold_stats(&self) -> Result<ColdStats>
Fails when the store holds cold rows but no cold tier is attached, since none of them can then be read.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn vacuum(&self) -> Result<(u64, u64)>
pub fn vacuum(&self) -> Result<(u64, u64)>
VACUUM cannot run inside a transaction and needs the writer alone;
returns (bytes before, bytes after).
Sourcepub fn vacuum_clearing_wal(&self) -> Result<(u64, u64)>
pub fn vacuum_clearing_wal(&self) -> Result<(u64, u64)>
vacuum, then a checkpoint that truncates the WAL, because the frames
VACUUM appended, and older ones past them, would otherwise keep every
page’s previous contents on disk. Errors when readers keep the
checkpoint from finishing, though the VACUUM itself went through.
Sourcepub fn vacuum_space(&self) -> Result<VacuumSpace>
pub fn vacuum_space(&self) -> Result<VacuumSpace>
VACUUM writes a full copy of the live pages to SQLite’s temp directory and then the same again into the WAL, so both need room.
pub fn stored_redaction_compacted(&self) -> Result<bool>
pub fn mark_stored_redaction_compacted(&self) -> Result<()>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn correct_memory(
&self,
old_id: Uuid,
replacement: Memory,
evidence: &str,
) -> Result<Result<Corrected, CorrectRefusal>>
pub fn correct_memory( &self, old_id: Uuid, replacement: Memory, evidence: &str, ) -> Result<Result<Corrected, CorrectRefusal>>
Stores replacement in the corrected memory’s project and scope, supersedes the
old memory with it and links them by a supersedes relation carrying
evidence, in one transaction. The sync log gets the replacement’s
Create before the relation, so a peer never sees a dangling edge.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn delete_scope(
&self,
scope: &DeleteScope,
archived_sessions: &[String],
) -> Result<DeleteReport>
pub fn delete_scope( &self, scope: &DeleteScope, archived_sessions: &[String], ) -> Result<DeleteReport>
Removes the scope’s memories, the distillates any of them was
distilled into, their chunks, relations and markers, and the scope’s
conversations, all in one transaction. Every removed memory and
conversation is tombstoned and the delete logged, so it wins on
every peer, and the earlier log records of each removed row are
reclaimed so the log keeps none of its content.
archived_sessions are sessions the caller found in the transcript
archive under this scope; their conversations are tombstoned even
when the store holds nothing of them.
Sourcepub fn delete_purge_requested(&self) -> Result<Option<String>>
pub fn delete_purge_requested(&self) -> Result<Option<String>>
A token while a delete applied from a peer still waits for the index compaction and cold purge the deleting daemon ran itself.
Sourcepub fn delete_purge_done(&self, token: &str) -> Result<()>
pub fn delete_purge_done(&self, token: &str) -> Result<()>
Clears the request token named, unless a delete applied since.
Sourcepub fn preview_delete(
&self,
scope: &DeleteScope,
archived_sessions: &[String],
) -> Result<DeleteReport>
pub fn preview_delete( &self, scope: &DeleteScope, archived_sessions: &[String], ) -> Result<DeleteReport>
What delete_scope would remove, counted without writing anything.
pub fn conversation_deleted(&self, id: Uuid) -> Result<bool>
Sourcepub fn session_deleted(&self, path: &str) -> Result<bool>
pub fn session_deleted(&self, path: &str) -> Result<bool>
Whether the Claude Code session a transcript at path belongs to was
deleted, in which case nothing of it may be archived or ingested.
Sourcepub fn purge_cold_segments(&self) -> Result<ColdPurge>
pub fn purge_cold_segments(&self) -> Result<ColdPurge>
Retires or rewrites every cold segment holding records no row points at any more, then deletes the files left without a manifest, so a deleted cold row’s text leaves the disk now rather than at the next cold pass. A store without a cold tier has nothing to purge.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn delete_status(&self, key: &str) -> Result<Option<DeleteStatus>>
pub fn delete_status(&self, key: &str) -> Result<Option<DeleteStatus>>
The delete key names, by its id or, newest first, by its target.
Source§impl SqliteStore
impl SqliteStore
pub fn is_encrypted(&self) -> bool
Sourcepub fn rewrite_under_key(&self, to: RewriteTo<'_>) -> Result<Rewrite>
pub fn rewrite_under_key(&self, to: RewriteTo<'_>) -> Result<Rewrite>
Rewrites the whole file under to through sqlcipher_export into a
copy beside it, checks the copy, and renames it over the store.
Writes wait on the writer for the whole rewrite; reads continue
until the swap. A failure before the rename leaves the store as it
was; one after it is a NotReopened.
Sourcepub fn rewrite_space(&self) -> Result<VacuumSpace>
pub fn rewrite_space(&self) -> Result<VacuumSpace>
A rewrite needs room beside the store for a copy of its live pages, with a quarter more for the copy’s own page overhead.
Sourcepub fn write_plaintext_copy(&self, dir: &Path) -> Result<PathBuf>
pub fn write_plaintext_copy(&self, dir: &Path) -> Result<PathBuf>
Writes a plaintext copy of the store into dir for a tool that
reads the file directly, under a fresh name created with O_EXCL and
mode 0600. The copy is a deliberate local decryption; the caller
removes it with remove_plaintext_copies.
Source§impl SqliteStore
impl SqliteStore
pub fn record_encrypted(&self, at_micros: i64, pause: Duration) -> Result<()>
Sourcepub fn encryption_awaited_since(&self, now_micros: i64) -> Result<i64>
pub fn encryption_awaited_since(&self, now_micros: i64) -> Result<i64>
When something first waited on this store’s encryption migration:
now_micros on the first call, the stored time on every later one.
Sourcepub fn encrypted_record(&self) -> Result<Option<EncryptedRecord>>
pub fn encrypted_record(&self) -> Result<Option<EncryptedRecord>>
When the one-time migration rewrote this store under its key, and how long writes waited for it. None for a store created encrypted.
Sourcepub fn revocations_after_store_key(&self) -> Result<Vec<String>>
pub fn revocations_after_store_key(&self) -> Result<Vec<String>>
Revocations of other devices, under this device’s identity, that
arrived after the current store key was made. Each one means a
device that left may hold K_id, which opens every older
store.key.wrapped, so the store key must change.
Sourcepub fn retirements_after_store_key(&self) -> Result<Vec<String>>
pub fn retirements_after_store_key(&self) -> Result<Vec<String>>
Fingerprints of recovery phrases retired, in a way that calls for
rotation, after the current store key was made. A retired phrase
yields K_id, which opens every older store.key.wrapped, whether
or not this device trusted it.
Source§impl SqliteStore
impl SqliteStore
pub fn advance_floor_uptime(&self, now_micros: i64) -> Result<()>
Sourcepub fn record_peer_ack(
&self,
peer_id: &str,
acked_seq: u64,
now_micros: i64,
) -> Result<()>
pub fn record_peer_ack( &self, peer_id: &str, acked_seq: u64, now_micros: i64, ) -> Result<()>
Acks only rise; an ack that reaches a peer’s pin turns the pin into that ack.
Sourcepub fn pin_peer(&self, peer_id: &str, seq: u64) -> Result<()>
pub fn pin_peer(&self, peer_id: &str, seq: u64) -> Result<()>
A renewal restarts the pin’s day of uptime.
Sourcepub fn record_peer_in(&self, peer_id: &str, seq: u64) -> Result<()>
pub fn record_peer_in(&self, peer_id: &str, seq: u64) -> Result<()>
The highest seq of peer_id’s log that its pushes into this store
have applied; it only rises.
pub fn peer_in(&self, peer_id: &str) -> Result<Option<u64>>
Sourcepub fn push_report(&self, peer_id: &str) -> Result<Option<u64>>
pub fn push_report(&self, peer_id: &str) -> Result<Option<u64>>
The position on this store’s log that peer_id last reported in a
push handshake.
Sourcepub fn record_push_report(
&self,
peer_id: &str,
reported: Option<u64>,
) -> Result<()>
pub fn record_push_report( &self, peer_id: &str, reported: Option<u64>, ) -> Result<()>
Replaces the last report, a value that may fall: a lower one means the peer was restored.
pub fn peer_acks(&self) -> Result<Vec<PeerAck>>
pub fn log_floor(&self) -> Result<u64>
Sourcepub fn floor(&self) -> Result<u64>
pub fn floor(&self) -> Result<u64>
F: the lowest ack or pin over live neighbours, or the head when
there are none.
pub fn floor_health(&self, now_micros: i64) -> Result<FloorHealth>
pub fn floor_pass_due(&self, now_micros: i64) -> Result<bool>
pub fn run_floor_pass( &self, truncation: Truncation, now_micros: i64, ) -> Result<FloorPass>
Sourcepub fn seed_floor_neighbours(&self, peers: &[String]) -> Result<usize>
pub fn seed_floor_neighbours(&self, peers: &[String]) -> Result<usize>
Seeds peers as neighbours that have not acked yet, so a device that
just bootstrapped keeps the log tail it carries until they ack it.
Sourcepub fn reset_floor_for_new_identity(
&self,
identity_tag: &IdentityTag,
) -> Result<()>
pub fn reset_floor_for_new_identity( &self, identity_tag: &IdentityTag, ) -> Result<()>
Drops every neighbour, ack and pin of a device outside
identity_tag, so a store that founded a new identity doesn’t hold
its floor for the old one’s devices.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn ingested_sessions_since(
&self,
source: &str,
since: DateTime<Utc>,
) -> Result<Vec<IngestedSession>>
pub fn ingested_sessions_since( &self, source: &str, since: DateTime<Utc>, ) -> Result<Vec<IngestedSession>>
Distinct (session key, file) pairs of keyed source files ingested
at or after since, ordered by session key then file.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn retire_note_covered_raws(&self) -> Result<usize>
pub fn retire_note_covered_raws(&self) -> Result<usize>
Marks every undistilled Claude Code raw that a live agent note of its
session covers, meaning the raw is timed no later than the session’s
newest live note, then archives the retirable raws. A raw is timed by
session_at, else created_at, and so is a note. Returns how many
raws were marked.
Sourcepub fn llm_distilled_since(&self, cutoff: DateTime<Utc>) -> Result<bool>
pub fn llm_distilled_since(&self, cutoff: DateTime<Utc>) -> Result<bool>
Whether an LLM distilled any raw at or after cutoff, on this
machine or on a peer, since distillation markers replicate with
their original time. Markers written by note cover are not LLM work,
nor are the legacy copies repair gives their exact-text twins, which
keep the agent-note model.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn notes_for_session(
&self,
session_id: &str,
kind: Option<NoteKind>,
) -> Result<Vec<(Memory, AgentNote)>>
pub fn notes_for_session( &self, session_id: &str, kind: Option<NoteKind>, ) -> Result<Vec<(Memory, AgentNote)>>
Live agent notes filed under session_id, oldest first, each with
its fields read back from the content. A row whose content no longer
parses is skipped.
Sourcepub fn latest_notes_for_project(
&self,
project: &str,
kind: Option<NoteKind>,
limit: usize,
) -> Result<Vec<(Memory, AgentNote)>>
pub fn latest_notes_for_project( &self, project: &str, kind: Option<NoteKind>, limit: usize, ) -> Result<Vec<(Memory, AgentNote)>>
At most limit live agent notes filed under project, newest first,
with the kind filter applied before the limit. A row whose content no
longer parses is skipped.
Sourcepub fn notes_created_between(
&self,
since: DateTime<Utc>,
until: DateTime<Utc>,
project_path: Option<&str>,
) -> Result<Vec<(Memory, AgentNote)>>
pub fn notes_created_between( &self, since: DateTime<Utc>, until: DateTime<Utc>, project_path: Option<&str>, ) -> Result<Vec<(Memory, AgentNote)>>
Live agent notes created in [since, until), newest first, in one
project when project_path names it. Rows that no longer parse are
skipped.
Sourcepub fn noted_session_ids(&self) -> Result<HashSet<String>>
pub fn noted_session_ids(&self) -> Result<HashSet<String>>
Every session id any live agent note is filed under.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn archived_raws_since(&self, since: DateTime<Utc>) -> Result<ArchivedRaws>
pub fn archived_raws_since(&self, since: DateTime<Utc>) -> Result<ArchivedRaws>
Archived raw memories split by whether their session time (their
creation time when the session is unknown) is at or after since.
These are the transcript chunks consolidation took out of recall,
which the raw fallback index keeps searchable; retired and superseded
rows are left out.
Sourcepub fn is_archived_raw(&self, id: Uuid) -> Result<bool>
pub fn is_archived_raw(&self, id: Uuid) -> Result<bool>
Whether id is still an archived raw the fallback may answer from.
Sourcepub fn raw_memory_state(&self, id: Uuid) -> Result<RawMemoryState>
pub fn raw_memory_state(&self, id: Uuid) -> Result<RawMemoryState>
Whether the raw memory id still stands behind the transcript
passage it was cut from. Forgetting, deleting or correcting it
withdraws the passage; a supersede onto a byte-identical row, which is
how maintenance collapses duplicates, does not, unless the row it
collapsed onto is withdrawn in turn.
Sourcepub fn restore_archived_embedding(
&self,
id: Uuid,
embedding: &[f32],
) -> Result<bool>
pub fn restore_archived_embedding( &self, id: Uuid, embedding: &[f32], ) -> Result<bool>
Restores the vector of an archived row that lost it, which happens
when a redacted row arrives through sync. It is derived from the
content on this device, so it is written locally: no outbox, no sync
log, and updated_at is left alone so it cannot win a merge.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn rewrite_memory_content(
&self,
memory_id: Uuid,
rewrite: &dyn Fn(&str) -> String,
embed: Option<EmbedBatchFn<'_>>,
) -> Result<RewriteOutcome>
pub fn rewrite_memory_content( &self, memory_id: Uuid, rewrite: &dyn Fn(&str) -> String, embed: Option<EmbedBatchFn<'_>>, ) -> Result<RewriteOutcome>
Rewrites a memory’s content, context and retirement reason through
rewrite, whatever its tier. Vectors are computed before the write
transaction, so the writer lock is never held across model inference;
the transaction then stores the text, the memory vector, a fresh chunk
set (live rows only), an index upsert and a sync Update carrying the
new row. Without embed, or when embedding fails, the memory vector
and chunks are dropped and the repair loop’s backfills restore them. A
row outside the live set that had no vector gets none. A change to the
reason alone keeps the vectors and chunks, which are not derived from
it. A cold row is an error, since its row holds only a stub.
Source§impl SqliteStore
impl SqliteStore
The author a write records when its writer names none: this store’s identity, or its device until it joins one.
Sourcepub fn get_memory_for(
&self,
id: Uuid,
principal: &Principal,
) -> Result<Option<Memory>>
pub fn get_memory_for( &self, id: Uuid, principal: &Principal, ) -> Result<Option<Memory>>
None when no such memory exists or principal may not read it, so
a caller cannot tell another user’s private memory from a missing
one.
Sourcepub fn check_change(&self, id: Uuid, principal: &Principal) -> Result<()>
pub fn check_change(&self, id: Uuid, principal: &Principal) -> Result<()>
Fails with AccessDenied when the memory exists and principal may
not change it; an absent memory passes, leaving the change itself to
report it missing.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn claude_code_sessions_between(
&self,
since: DateTime<Utc>,
until: DateTime<Utc>,
project_path: Option<&str>,
) -> Result<Vec<ActiveSession>>
pub fn claude_code_sessions_between( &self, since: DateTime<Utc>, until: DateTime<Utc>, project_path: Option<&str>, ) -> Result<Vec<ActiveSession>>
Main-agent Claude Code sessions with a transcript line timed in
[since, until), read from the raw chunks’ session_at, so
archived and consolidated chunks still count. Subagent transcripts
are left out because no note is ever asked of them.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn note_failed_record(
&self,
source: &str,
record: &SyncRecord,
error: &Error,
now_micros: i64,
) -> Result<()>
pub fn note_failed_record( &self, source: &str, record: &SyncRecord, error: &Error, now_micros: i64, ) -> Result<()>
Keeps a record from source’s log that failed to apply, or counts
one more attempt on one already kept. A content-deterministic
failure settles after SETTLE_AFTER_ATTEMPTS attempts spread over a
day; a transient one never does.
Sourcepub fn retry_failed_records(
&self,
source: &str,
now_micros: i64,
) -> Result<RetryCounts>
pub fn retry_failed_records( &self, source: &str, now_micros: i64, ) -> Result<RetryCounts>
Applies again every unsettled record kept from source; one that
now applies or settles stops holding source’s ack back.
Sourcepub fn applied_through(&self, source: &str, reached: u64) -> Result<u64>
pub fn applied_through(&self, source: &str, reached: u64) -> Result<u64>
The highest seq of source’s log applied here without a gap: below
the first record from it that still fails and has not settled.
pub fn failed_records(&self) -> Result<Vec<FailedRecord>>
pub fn failed_record_counts(&self) -> Result<FailedCounts>
Sourcepub fn replay_settled_records(
&self,
build: &str,
) -> Result<Option<ReplayCounts>>
pub fn replay_settled_records( &self, build: &str, ) -> Result<Option<ReplayCounts>>
Applies every settled record again once per build, so a bug fixed
in a later binary or schema recovers records whose source log may
no longer hold them. A record that now lands is logged as a relay
under replay:<id>:<n>, numbered densely, so it reaches this store’s
pullers. Each page of records is its own transaction and the build is
marked done after the last page, so a retry after a crash replays
what is left under a new id.
Sourcepub fn prune_settled_records(&self, now_micros: i64) -> Result<PruneCounts>
pub fn prune_settled_records(&self, now_micros: i64) -> Result<PruneCounts>
Drops settled records that a newer build could not recover once
they are 90 days old, and the oldest past SETTLED_CAP.
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn export_snapshot(
&self,
options: SnapshotOptions,
sink: &mut dyn FnMut(SnapshotRow) -> Result<()>,
) -> Result<SnapshotState>
pub fn export_snapshot( &self, options: SnapshotOptions, sink: &mut dyn FnMut(SnapshotRow) -> Result<()>, ) -> Result<SnapshotState>
Streams every row a peer needs to converge with this store, from one
read transaction, into sink. A caller that pins the reader does so
at log_head before calling, which is at or below the seq read
here, so no row above the pin is truncated meanwhile.
pub fn snapshot_merge_progress(&self) -> Result<Option<MergeProgress>>
Sourcepub fn begin_snapshot_merge(
&self,
snapshot_id: &str,
exporter: &str,
seq: u64,
) -> Result<SnapshotMerge<'_>>
pub fn begin_snapshot_merge( &self, snapshot_id: &str, exporter: &str, seq: u64, ) -> Result<SnapshotMerge<'_>>
Starts a merge of snapshot snapshot_id, or resumes the one already
in progress for it. A merge of another snapshot is abandoned: rows
it applied stay, since merging never removes anything.
pub fn abandon_snapshot_merge(&self) -> Result<()>
Source§impl SqliteStore
impl SqliteStore
pub fn redaction_phase(&self) -> Result<RedactionPhase>
Sourcepub fn run_stored_redaction(
&self,
embed: Option<EmbedBatchFn<'_>>,
) -> Result<RedactionRun>
pub fn run_stored_redaction( &self, embed: Option<EmbedBatchFn<'_>>, ) -> Result<RedactionRun>
The one-time pass that redacts content stored before redaction
existed: every memory row whatever its tier (through
rewrite_memory_content, so peers receive the redacted row), chunk
sets the rewrite did not replace, entity names and aliases, relation
context, and the payloads already in sync_log. Progress is kept in
index_meta, not a schema migration, so peers on the same binary
still agree on the schema while their passes run. A row that cannot be
parsed has its raw text redacted in place and is recorded (see
RedactionReport::skipped) before the cursor moves past it; any other
error, including one from rewriting a row that parsed, fails the run.
Returns immediately when the pass has already finished on this store.
Sourcepub fn stored_redaction_report(&self) -> Result<RedactionReport>
pub fn stored_redaction_report(&self) -> Result<RedactionReport>
Counts what the pass would redact, by location and kind, without writing anything. Text is read leniently (invalid UTF-8 replaced, a blob read as text), as the pass reads rows it skips.
Source§impl SqliteStore
impl SqliteStore
pub fn pending_distillation(&self) -> Result<PendingDistillation>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn restore_explicit_memories(&self) -> Result<ExplicitRestoreStats>
pub fn restore_explicit_memories(&self) -> Result<ExplicitRestoreStats>
Undoes what consolidation did to explicit memories before
EXPLICIT_SOURCES was excluded from it: every archived explicit raw
returns to the hot tier and the indexes, every marker on an explicit
raw is dropped so no later pass retires it again, and a distillate
whose raws were all explicit is superseded by the oldest of them,
since nothing it summarised is missing from recall any more. A
distillate that also stands in for transcript raws stays live.
Every change replicates the way consolidation’s own writes do.
Sourcepub fn refile_nested_transcript_projects(&self) -> Result<u64>
pub fn refile_nested_transcript_projects(&self) -> Result<u64>
Re-files memories that an older adapter filed under the directory
holding the transcript file (subagents, agent-transcripts) rather
than the project directory under the projects root. Raws re-file
from their own source_id; a distillate re-files to the project most
of its raws now carry, because a consolidation batch is grouped by
conversation and one project is the only value that fits a row with a
single project_path, or to the project in its own source_id when
no raw is left to vote. Every changed row is replicated as an Update
and queued for the indexes, exactly as update_memory does.
Sourcepub fn refile_stray_project_slugs(&self) -> Result<StraySlugReport>
pub fn refile_stray_project_slugs(&self) -> Result<StraySlugReport>
Re-files explicit memories that an earlier remember filed under the
bare directory name it was given (wardrobe) instead of the slug
ingest stores for that directory (-mnt-data-wardrobe). A bare name
resolves to the stored slugs ending in -<name>, with name encoded
the way Claude Code encodes a path; the two spellings Claude Code and
Cursor give one directory (with and without the leading -) count as
one project. A name matching more than one project is reported, never
guessed, and transcript rows under a bare slug are left alone because
an adapter filed them there on purpose.
Source§impl SqliteStore
impl SqliteStore
pub fn transcript_backfill_done(&self) -> Result<bool>
pub fn mark_transcript_backfill_done(&self) -> Result<()>
Source§impl SqliteStore
impl SqliteStore
pub fn open(path: &Path, machine_id: String) -> Result<Self>
Sourcepub fn open_with_pool_size(
path: &Path,
machine_id: String,
reader_pool_size: usize,
) -> Result<Self>
pub fn open_with_pool_size( path: &Path, machine_id: String, reader_pool_size: usize, ) -> Result<Self>
Same as open, with an explicit reader pool size instead of the
parallelism-derived default. reader_pool_size is clamped to at
least 1 so a caller passing 0 still gets a working store.
Sourcepub fn open_with_key(
path: &Path,
machine_id: String,
key: &StoreKey,
) -> Result<Self>
pub fn open_with_key( path: &Path, machine_id: String, key: &StoreKey, ) -> Result<Self>
Opens or creates a store encrypted under key; a new file is
encrypted from its first page. Fails when the file is plaintext or
under another key, and in a build without the encryption feature.
pub fn open_with_pool_size_keyed( path: &Path, machine_id: String, reader_pool_size: usize, key: &StoreKey, ) -> Result<Self>
pub fn in_memory(machine_id: String) -> Result<Self>
Sourcepub fn with_wall_clock(self, clock: Arc<dyn WallClock>) -> Self
pub fn with_wall_clock(self, clock: Arc<dyn WallClock>) -> Self
Replaces the default SystemClock that every seq is minted from.
Sourcepub fn write_count(&self) -> u64
pub fn write_count(&self) -> u64
Rows changed through the writer since the store opened; unchanged across an interval means nothing was written in it.
pub fn machine_id(&self) -> &str
Sourcepub fn raise_clock_floors(&self, floors: &ClockFloors) -> Result<()>
pub fn raise_clock_floors(&self, floors: &ClockFloors) -> Result<()>
Raises the clock’s floors from a peer’s report and never lowers one.
Fails with ClockFloorRejected, raising none, when a value lies past
HLC_CEILING_MICROS (for held_origin_seq, when its incarnation does).
Sourcepub fn highest_origin_seq(&self, origin: &str) -> Result<Option<i64>>
pub fn highest_origin_seq(&self, origin: &str) -> Result<Option<i64>>
The highest origin_seq from origin this store holds, in its live log
or among the keys kept after the log rows went.
pub fn clock_state(&self) -> Result<ClockState>
pub fn tombstone_exists(&self, id: Uuid) -> Result<bool>
pub fn memory_content_exists(&self, content_prefix: &str) -> Result<bool>
pub fn max_sync_seq(&self) -> Result<u64>
Sourcepub fn schema_version(&self) -> Result<i64>
pub fn schema_version(&self) -> Result<i64>
The highest migration applied to the database file, which exceeds
SCHEMA_VERSION when a newer binary migrated it.
pub fn get_conversation(&self, id: Uuid) -> Result<Option<Conversation>>
Source§impl SqliteStore
impl SqliteStore
Sourcepub fn store_memory_if_absent(&self, memory: &Memory) -> Result<bool>
pub fn store_memory_if_absent(&self, memory: &Memory) -> Result<bool>
Stores memory only when its id is neither a row (in any state) nor
tombstoned, checked in the writer transaction so two writers of the
same id cannot both insert; insert_memory would otherwise replace a
retired row. True when it wrote.
Source§impl SqliteStore
impl SqliteStore
pub fn index_watermark(&self) -> Result<i64>
pub fn set_index_watermark(&self, seq: i64) -> Result<()>
pub fn outbox_after(&self, seq: i64) -> Result<Vec<OutboxRow>>
pub fn prune_outbox(&self, upto: i64) -> Result<()>
pub fn max_outbox_seq(&self) -> Result<i64>
Sourcepub fn vec_key(&self, memory_id: Uuid) -> Result<u64>
pub fn vec_key(&self, memory_id: Uuid) -> Result<u64>
Stable u64 usearch key for a memory id, allocated on first use.
pub fn existing_vec_key(&self, memory_id: Uuid) -> Result<Option<u64>>
Sourcepub fn delete_vec_key(&self, memory_id: Uuid) -> Result<()>
pub fn delete_vec_key(&self, memory_id: Uuid) -> Result<()>
Drops the key row once the vector is gone from usearch, so vec_keys
only ever holds keys the index can still resolve.
Sourcepub fn find_exact_duplicate(
&self,
content: &str,
project_path: Option<&str>,
) -> Result<Option<Memory>>
pub fn find_exact_duplicate( &self, content: &str, project_path: Option<&str>, ) -> Result<Option<Memory>>
The live memory content duplicates under remember’s rule: equal
once surrounding whitespace is trimmed and both sides are lowercased.
With project_path, only memories filed under that project count;
among several matches the oldest wins. SQLite’s lower() folds ASCII
only, so a stored memory that differs from content just in the case
of a non-ASCII letter is not found, which the substring shortlist this
replaces could not find either.
Sourcepub fn find_exact_duplicate_outside_source(
&self,
content: &str,
project_path: Option<&str>,
source: &str,
) -> Result<Option<Memory>>
pub fn find_exact_duplicate_outside_source( &self, content: &str, project_path: Option<&str>, source: &str, ) -> Result<Option<Memory>>
As find_exact_duplicate, but never returns a row of source, for a
source whose rows belong to something else (vault notes follow their
files) and so cannot stand in for a new memory.
Sourcepub fn scoped_text_search(
&self,
query: &str,
source: Option<&str>,
memory_type: Option<MemoryType>,
project_path: Option<&str>,
limit: usize,
) -> Result<Vec<Memory>>
pub fn scoped_text_search( &self, query: &str, source: Option<&str>, memory_type: Option<MemoryType>, project_path: Option<&str>, limit: usize, ) -> Result<Vec<Memory>>
bm25_search’s match with a source/type/project scope inside the
query, so limit counts only rows the scope admits instead of cutting
before a caller’s filter could run. The match is a substring test over
content on hot, unsuperseded rows, with no relevance score to order
by (tantivy, not SQLite, holds the text index), so matches come back
newest first. Case folding is SQLite’s lower(), which is ASCII only.
Sourcepub fn scoped_count(
&self,
source: Option<&str>,
memory_type: Option<MemoryType>,
project_path: Option<&str>,
) -> Result<usize>
pub fn scoped_count( &self, source: Option<&str>, memory_type: Option<MemoryType>, project_path: Option<&str>, ) -> Result<usize>
How many live memories a source/type/project scope holds. Answered by COUNT off the source, memory_type, and project_path indexes, so it stays O(1) in memory however large the scope grows.
Sourcepub fn retain_in_scope(
&self,
ids: &[Uuid],
source: Option<&str>,
memory_type: Option<MemoryType>,
project_path: Option<&str>,
) -> Result<HashSet<Uuid>>
pub fn retain_in_scope( &self, ids: &[Uuid], source: Option<&str>, memory_type: Option<MemoryType>, project_path: Option<&str>, ) -> Result<HashSet<Uuid>>
Which of ids fall inside a source/type/project scope.
Asks the database about the candidates in hand rather than reading the scope out to test membership locally, so the cost tracks the caller’s list and not the scope. Batched because SQLite caps how many bound parameters one statement may carry.
pub fn memory_id_for_vec_key(&self, key: u64) -> Result<Option<Uuid>>
pub fn memory_for_indexing( &self, memory_id: Uuid, ) -> Result<Option<IndexableMemory>>
pub fn all_indexable(&self) -> Result<Vec<(Uuid, Vec<f32>, String)>>
Sourcepub fn indexable_page(
&self,
after: i64,
limit: usize,
) -> Result<Vec<(i64, Uuid, Vec<f32>, String)>>
pub fn indexable_page( &self, after: i64, limit: usize, ) -> Result<Vec<(i64, Uuid, Vec<f32>, String)>>
Up to limit hot rows after rowid after, in rowid order, so a
rebuild never holds more than one page and indexes rows in the order
they were written, which is how ties between equal vectors fall.
pub fn outbox_page(&self, seq: i64, limit: usize) -> Result<Vec<OutboxRow>>
Sourcepub fn vector_indexable_count(&self, dim: usize) -> Result<usize>
pub fn vector_indexable_count(&self, dim: usize) -> Result<usize>
Hot rows whose stored embedding has exactly dim components: the
only rows the vector index can hold, so a row still waiting for an
embedding does not read as index drift.
pub fn indexable_count(&self) -> Result<usize>
Sourcepub fn supersede_memory(&self, memory_id: Uuid, by: Uuid) -> Result<()>
pub fn supersede_memory(&self, memory_id: Uuid, by: Uuid) -> Result<()>
Zep-style soft invalidation: the row stays, the indexes drop it via the outbox, and peers learn of it through a sync Update carrying the row.
Sourcepub fn archive_memory(&self, memory_id: Uuid) -> Result<()>
pub fn archive_memory(&self, memory_id: Uuid) -> Result<()>
Archive tier: the row keeps its content and embedding but leaves
both retrieval indexes and every recall predicate. archived_segment
stays NULL until the cold pass moves an old raw into a segment.
Replicated as an Update so peers retire the same row instead of
keeping it hot beside the distillate.
Sourcepub fn retire_memory(
&self,
memory_id: Uuid,
reason: &str,
) -> Result<RetireOutcome>
pub fn retire_memory( &self, memory_id: Uuid, reason: &str, ) -> Result<RetireOutcome>
forget’s default: archives the row as archive_memory does and
records why, so the memory leaves recall on every peer while its
content stays recoverable. Nothing is tombstoned, and an id this store
does not hold changes nothing.
Trait Implementations§
Source§impl Store for SqliteStore
impl Store for SqliteStore
Source§fn traverse(
&self,
start_id: Uuid,
depth: u32,
) -> Result<Vec<(Memory, Vec<Relation>)>>
fn traverse( &self, start_id: Uuid, depth: u32, ) -> Result<Vec<(Memory, Vec<Relation>)>>
Live memories within depth hops of start_id, newest first, capped
at TRAVERSE_MAX_RESULTS. Ingest writes no memory-to-memory edges
(only mentions, derived_from and distilled_from), so a hop is any of:
a memory-to-memory relation in either direction, a shared mentioned
entity, or a shared conversation.
fn store_memory(&self, memory: &Memory) -> Result<()>
fn get_memory(&self, id: Uuid) -> Result<Option<Memory>>
fn get_memory_with_embedding(&self, id: Uuid) -> Result<Option<Memory>>
fn delete_memory(&self, id: Uuid) -> Result<()>
Source§fn remove_memory(&self, id: Uuid) -> Result<bool>
fn remove_memory(&self, id: Uuid) -> Result<bool>
delete_memory that also reports whether a row was there to remove,
so a forget of an unknown id can be answered as such instead of
silently succeeding.fn store_entity(&self, entity: &Entity) -> Result<()>
fn get_entity(&self, id: Uuid) -> Result<Option<Entity>>
fn find_entity_by_name(&self, name: &str) -> Result<Option<Entity>>
fn store_conversation(&self, conversation: &Conversation) -> Result<()>
fn store_relation(&self, relation: &Relation) -> Result<()>
fn get_relations( &self, node_id: Uuid, relation_type: Option<RelationType>, ) -> Result<Vec<Relation>>
fn vector_search( &self, embedding: &[f32], limit: usize, ) -> Result<Vec<(Memory, f32)>>
Source§fn filtered_vector_search(
&self,
embedding: &[f32],
source: Option<&str>,
memory_type: Option<MemoryType>,
project_path: Option<&str>,
limit: usize,
) -> Result<Vec<(Memory, f32)>>
fn filtered_vector_search( &self, embedding: &[f32], source: Option<&str>, memory_type: Option<MemoryType>, project_path: Option<&str>, limit: usize, ) -> Result<Vec<(Memory, f32)>>
source, memory_type,
and/or project_path, scanned exhaustively over that subset. Read morefn memories_by_source(&self, source: &str) -> Result<Vec<Memory>>
Source§fn source_admits(&self, memory: &Memory, source: &str) -> Result<bool>
fn source_admits(&self, memory: &Memory, source: &str) -> Result<bool>
memory answers a recall scoped to source. Consolidation
leaves the raws archived and the distillate tagged ‘consolidation’, so
a store that tracks distillation must let a distillate answer for the
sources of its raws, or a source filter finds nothing once its raws
are consolidated. The default is the plain column comparison for
stores that never consolidate.fn memories_by_type(&self, memory_type: MemoryType) -> Result<Vec<Memory>>
Source§fn chunk_window(&self, memory_id: Uuid, ord: usize) -> Result<Option<String>>
fn chunk_window(&self, memory_id: Uuid, ord: usize) -> Result<Option<String>>
ord: that chunk joined with one
neighbour on each side. None for a store that keeps no chunks.fn update_memory(&self, memory: &Memory) -> Result<()>
fn record_access(&self, memory: &Memory) -> Result<()>
Source§fn record_accesses(&self, ids: &[Uuid]) -> Result<()>
fn record_accesses(&self, ids: &[Uuid]) -> Result<()>
ids and stamp them with the current
time; confidence is left alone. A recall touches every result it
returns, so an implementation should batch these into one write
rather than take the writer lock per row. Ids the store does not
hold are ignored.fn bm25_search(&self, query: &str, limit: usize) -> Result<Vec<Memory>>
fn memory_count(&self) -> Result<usize>
fn all_memory_ids(&self) -> Result<Vec<Uuid>>
fn all_relations(&self) -> Result<Vec<Relation>>
Source§impl StoreAdmin for SqliteStore
impl StoreAdmin for SqliteStore
Source§fn session_deleted(&self, path: &str) -> Result<bool>
fn session_deleted(&self, path: &str) -> Result<bool>
path belongs to
was deleted, so nothing of it may be captured again. The default
knows of no deletes.fn register_machine(&self, identity: &MachineIdentity) -> Result<()>
fn get_all_machines(&self) -> Result<HashMap<String, String>>
fn diagnostic(&self) -> Result<String>
fn find_or_create_entity(&self, name: &str, entity_type: &str) -> Result<Entity>
fn memory_content_exists(&self, content_prefix: &str) -> Result<bool>
Source§fn store_memory_if_absent(&self, memory: &Memory) -> Result<bool>
fn store_memory_if_absent(&self, memory: &Memory) -> Result<bool>
memory only when no memory holds its id in any state and the
id is not tombstoned, checked in the insert’s own transaction so two
concurrent writers cannot both pass. True when it wrote. The default
cannot check and always writes.Source§fn ingest_memory_if_absent(&self, memory: &Memory) -> Result<bool>
fn ingest_memory_if_absent(&self, memory: &Memory) -> Result<bool>
store_memory_if_absent for ingest, which may also refuse text a
delete removed from the same source. The default refuses nothing more.Source§fn ingest_blocked(&self, memory: &Memory) -> Result<bool>
fn ingest_blocked(&self, memory: &Memory) -> Result<bool>
memory because a delete removed its text
from its source. A read outside any write, so it only spares work
ahead of ingest_memory_if_absent. The default knows of no deletes.Source§fn store_conversation_if_absent(
&self,
conversation: &Conversation,
) -> Result<bool>
fn store_conversation_if_absent( &self, conversation: &Conversation, ) -> Result<bool>
store_memory_if_absent for conversations: an existing row keeps its
fields and nothing is logged for sync.Source§fn memory_id_taken(&self, id: Uuid) -> Result<bool>
fn memory_id_taken(&self, id: Uuid) -> Result<bool>
id in any state or the id is tombstoned. A
read outside any write, so it can only spare work ahead of
store_memory_if_absent, never replace it. The default knows nothing.fn is_file_changed(&self, file_path: &str, file_hash: &str) -> Result<bool>
fn mark_ingested( &self, file_path: &str, file_hash: &str, memory_count: usize, source: &str, ) -> Result<()>
fn ingested_file_count(&self) -> Result<usize>
fn clear_ingest_log(&self) -> Result<usize>
fn ingest_log_entry(&self, file_path: &str) -> Result<Option<IngestLogEntry>>
Source§fn ingested_session(
&self,
session_key: &str,
content_hash: &str,
) -> Result<Option<IngestLogEntry>>
fn ingested_session( &self, session_key: &str, content_hash: &str, ) -> Result<Option<IngestLogEntry>>
Source§fn legacy_ingest_entries_with_stem(
&self,
stem: &str,
) -> Result<Vec<IngestLogEntry>>
fn legacy_ingest_entries_with_stem( &self, stem: &str, ) -> Result<Vec<IngestLogEntry>>
stem.Source§fn upgrade_ingest_hash(
&self,
file_path: &str,
content_hash: &str,
session_key: Option<&str>,
) -> Result<()>
fn upgrade_ingest_hash( &self, file_path: &str, content_hash: &str, session_key: Option<&str>, ) -> Result<()>
fn record_ingested(&self, record: &IngestRecord<'_>) -> Result<()>
Source§fn clear_reparseable_ingest_log(&self) -> Result<usize>
fn clear_reparseable_ingest_log(&self) -> Result<usize>
fn delete_memories_by_source(&self, source: &str) -> Result<usize>
fn delete_memories_by_source_id(&self, source_id: &str) -> Result<usize>
fn rebuild_vector_index(&self) -> Result<()>
fn backfill_project_paths(&self) -> Result<u64>
fn backfill_sync_log(&self) -> Result<u64>
fn backfill_tombstones(&self) -> Result<u64>
fn prune_dangling_relations(&self) -> Result<u64>
Source§fn compact_sync_log(
&self,
ops: &[SyncOp],
dry_run: bool,
) -> Result<CompactStats>
fn compact_sync_log( &self, ops: &[SyncOp], dry_run: bool, ) -> Result<CompactStats>
sync_log rows down to one per
(node_type, node_id, op), keeping the highest local_seq in each
group.fn memories_by_project_path(&self, project_path: &str) -> Result<Vec<Memory>>
Source§fn distinct_project_paths(&self) -> Result<Vec<(String, u64)>>
fn distinct_project_paths(&self) -> Result<Vec<(String, u64)>>
project_path value with its live memory
count, so a caller can discover the real slug recall’s project
scope expects instead of guessing.fn all_memories_with_embeddings(&self) -> Result<Vec<Memory>>
fn consolidation_stats(&self) -> Result<ConsolidationStats>
Source§fn unconsolidated_memories(&self, limit: usize) -> Result<Vec<Memory>>
fn unconsolidated_memories(&self, limit: usize) -> Result<Vec<Memory>>
fn mark_consolidated( &self, raw_id: Uuid, distilled_id: Uuid, model: &str, ) -> Result<()>
Source§fn retire_consolidated_raws(&self) -> Result<usize>
fn retire_consolidated_raws(&self) -> Result<usize>
fn memories_created_between( &self, start: &DateTime<Utc>, end: &DateTime<Utc>, ) -> Result<Vec<Memory>>
fn sync_log_since(&self, after_seq: u64) -> Result<Vec<SyncEntry>>
fn sync_log_page( &self, after_seq: u64, limit: Option<usize>, ) -> Result<Vec<SyncEntry>>
Source§fn sync_log_export_page(
&self,
after_seq: u64,
limit: Option<usize>,
) -> Result<Vec<SyncEntry>>
fn sync_log_export_page( &self, after_seq: u64, limit: Option<usize>, ) -> Result<Vec<SyncEntry>>
fn max_sync_seq(&self) -> Result<u64>
fn get_sync_state(&self, peer_id: &str) -> Result<Option<SyncState>>
fn set_sync_state(&self, state: &SyncState) -> Result<()>
fn get_all_sync_states(&self) -> Result<Vec<SyncState>>
fn tombstone_exists(&self, id: Uuid) -> Result<bool>
Source§fn apply_record(&self, record: &SyncRecord) -> Result<ApplyOutcome>
fn apply_record(&self, record: &SyncRecord) -> Result<ApplyOutcome>
Source§fn apply_batch(&self, records: &[SyncRecord]) -> Result<Vec<ApplyOutcome>>
fn apply_batch(&self, records: &[SyncRecord]) -> Result<Vec<ApplyOutcome>>
Auto Trait Implementations§
impl !Freeze for SqliteStore
impl RefUnwindSafe for SqliteStore
impl Send for SqliteStore
impl Sync for SqliteStore
impl Unpin for SqliteStore
impl UnsafeUnpin for SqliteStore
impl UnwindSafe for SqliteStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more