Items
What you add to memory - messages, documents and notes - and what each field of an item means.
An item is one thing you add for an end user: a chat message, a document or a note. You send items to
/v1/memory/add, up to 500 at a time.
Three kinds
| Kind | What it is | How it is filed |
|---|---|---|
message | One turn of a conversation. The default. | With its session's other messages that day, as one conversation. |
document | A whole text with a title, such as a file or a page. | As a thread of its own, cut into passages headed by its title. |
note | One statement to keep, standing alone. | As a thread of its own, read like a document. |
Use message for what people said to each other or to your assistant. Use document for longer text you want
searchable in pieces. Use note for a fact your backend already knows, such as a preference from your CRM.
The id is the item's identity
Give every item an id that is stable in your system, such as your message id.
- The same
idagain is the same item. Sending it again with the same content changes nothing. A retry is always safe. - The same
idwith changed content is an edit. The stored copy is replaced and the conversation it is in is filed again. Earlier versions are kept for your backend; see Versions & edits. - An edit fixes; a change is a new item. Reuse an
idonly to fix the same statement, such as a typo or a mistake. When something changes, such as a new address or a new plan, add a new item with a newid: memory keeps both, each with its date, and shows them newest first. An edit replaces the old words, and the new words keep the old item's date, so an edit used for a change loses the earlier value and misdates the new one. - A field you leave out is kept. Sending an
idagain replaces its text and keeps itsabout,metadata,expiresandauthorunless the request sends them. Sendnullto clear one. - The time is fixed once memory holds the item. An edit keeps the
atthe item first had, even if you send a new one. To move an item in time, forget it, then add it again.
An item without an id is named for you:
- With an
at, it is named by its kind, session, author, role, text and time. Sending the same words at the same time again is the same item. - Without an
at, it gets a random id. Sending it twice adds it twice.
So send an id, or send an Idempotency-Key header with the request.
Sessions
session groups messages into conversations. Use your conversation or chat id.
- The messages of one session on one day are one conversation, called a thread. A session that runs for months is many threads, one a day. This keeps the cost of each add to the size of that day, not of the whole session.
- The session as a whole is still one thing you can forget by name, across all its days.
- Messages with no
sessionare cut into conversations by time, the way a chat channel's loose messages are.
session applies to messages. Documents and notes are each a thread of their own.
Who said it
author is a name, or an object that says who the person is:
{
"author": { "id": "u_42", "name": "Alice Chen", "email": "alice@example.com", "self": true }
}idis your stable id for the person. It is the strongest thing memory can be told: two spellings of one name with oneidare one person, and one name with two ids is two people.emailandhandlejoin the person to themselves where the same person appears elsewhere.self: truemarks the end user whose memory this is.
role says what kind of speaker it is:
"user"marks the end user, whenauthor.selfis not given."assistant","agent","bot","tool"and"system"mark a machine. A machine's turns are read for what they offer, and a machine is never the subject of what is known about the person.
Title, about and metadata
titlenames a document or a note. It heads every passage cut from it.aboutlists the pieces of work an item belongs to, askind:name, such asproject:lisbon-triporticket:4512. A bare name is filed as a topic. Up to 20 per item. Memory gathers the sessions about one piece of work by these.metadatais any JSON object. It is stored with the item and returned byread. Nothing filters on it yet Soon.
Expiry
expires is a date or time after which the item is forgotten, with everything learned from it. See
Expiry.
Fields
| Field | Type | Bound | Default |
|---|---|---|---|
text | string | at least 1 character; the 1 MB body limit bounds it | required |
kind | "message", "document" or "note" | "message" | |
id | string | up to 512 characters | named for you, see above |
at | ISO date or time | must begin YYYY-MM-DD, a real day; up to 40 characters | now |
author | string, or {id, name, email, handle, self} | each string up to 512 characters | none |
role | string | up to 512 characters | none |
session | string | up to 512 characters | none |
title | string | up to 512 characters | none |
about | string[] | up to 20, each up to 512 characters | [] |
expires | ISO date or time | as at | never |
metadata | object | the 1 MB body limit | {} |
A time without an offset is taken as UTC.
Related
- Add reference: the request and response.
- Records & reading: what happens to an item after it lands.
- Documents & notes: when to use each kind.