Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Memory

Memory.Remember / Memory.Forget

using Memory; … bool Memory.Remember(FileAsset file, Entity about); int Memory.Forget(FileAsset file)

Put a file's text into the app's searchable memory, filed against the record it is about — and take it back out again. Uploading a file does not do this; somebody has to say so, and the memory records who.

stable2 examples compiled by CIstoragesearchsemanticrag

Summary#

Memory.Remember(file, about: record) reads a stored file's text, splits it up, and adds it to the app's searchable memory as memory about that record — so Memory.Search can answer from a document the way it answers from a [Searchable] field. Memory.Forget(file) takes it back out. Both are available under using Osyrin.Memory;.

Signature#

using Osyrin.Memory;
using Osyrin.Storage;

bool Memory.Remember(
    FileAsset file,       // the stored file whose text to index
    Entity about)         // the record this file is about — its memory is found through that record

int Memory.Forget(FileAsset file)   // how many memory entries were removed

Description#

Storing a file and remembering it are two different acts, and this verb is the second one. An app can hold attachments it never wants answered from — a signed copy, a scan kept for the record — and uploading is not a decision about recall. So nothing is indexed until someone asks for it.

about: is what makes it findable at all#

Memory is reached through the record it belongs to: you can find a file's text exactly when you can read the record it was filed against. That is the whole of its access control, and it is why about: is required rather than inferred. A file remembered about nothing would be memory nobody could ever read.

Filing the same file against a different record is a different claim, and you make it by calling the verb again with that record.

It records who asked#

Whoever calls Memory.Remember is the author of the memory it creates, so Memory.Search(by: someone) can answer "what did they put in front of us", and origin: tells a document somebody filed apart from text that simply followed the data. Because that authorship is the point, the call refuses when nobody is authenticated rather than storing entries that claim to have appeared on their own.

The work is queued, not awaited#

Reading a document, splitting it and embedding it is real work, so Memory.Remember returns once the work is queuedtrue when it was, false when this host has no worker to do it. The file becomes searchable shortly afterwards. Remembering the same file twice is safe: the second call replaces that file's entries rather than adding a second copy, which is also how a re-uploaded file stops answering with its old text.

Forgetting#

Memory.Forget(file) removes the file's entries from memory and returns how many there were, so "forgot it" and "there was nothing to forget" are distinguishable without a second query. The file itself is untouched — forgetting is about recall, not storage. A file you still hold is not a file you must still be answering from.

Examples#

using Osyrin.Memory;
using Osyrin.Storage;

entity Order {
  [MaxLength(80)] string Reference;
  [Searchable(Memory)] string Notes;
}

bool Keep(Order o, FileAsset contract) {
  // from now on, searching this order can answer from the contract's text
  return Memory.Remember(contract, about: o);
}
using Osyrin.Memory;
using Osyrin.Storage;

int Drop(FileAsset contract) {
  return Memory.Forget(contract);   // the file stays; only its memory goes
}

See also#

Related

using Memory (semantic search)

Opt into semantic (vector) search over your app's content. `using Memory;` adds a searchable store to the app…

[Searchable]

Mark a text field searchable. `[Searchable]` gives a String or Markdown property the best relevance search the app can…

SearchHit

One result of a semantic search — the matched text, how relevant it was, where it came from, when it was learned, and…

Memory.Link / Memory.Unlink

State that two records are related, in your app's own words — "supersedes, because it was renegotiated after the Q2…