Korely

Core operations

Forget a user

Erase everything Korely stores about one end user, for good.

One HTTP request erases every memory and fact of one end user in one project. It erases them from the live database; backups are under Details.

It is the technical step when an end user asks you to erase their data. The rest of your response to that request is up to you.

Terms

The Glossary defines the words used across the docs. This page adds three.

  • Pseudonym: a code like erased:3f9a... that Korely writes in its logs instead of the user id after an erasure. Korely can compute it from the id with its own secret key, so it is personal data.
  • Receipt (audit_id): your erasure receipt, aud_ and 32 hex characters. It comes once, in the response. Save it at once: no call gives it back. The audit log keeps a row of the erasure without it (see Details).
  • Audit log: the record of actions on your account, such as erasing an end user. You list it with GET /v1/audit. It is not the receipt.

Quick start

This call deletes for good. Try it on a test end user first.

You need Python 3.9 or later. Install the Python SDK: pip install korely-memory.

You also need an API key with two permissions: memories:write for the erasure and memories:read for the counts in the script. Get a free one in the Quickstart. Set it as an environment variable, which Korely() reads:

Terminal window
export KORELY_API_KEY=kor_live_...

For Node.js 18 or later, see the Node.js tab under Example.

The code writes one memory for test-user-1, counts the end user's memories, erases that end user, and counts again.

from korely_memory import Korely
korely = Korely()
korely.add("I prefer email over phone calls.", user_id="test-user-1")
print(korely.get_all(user_id="test-user-1").total) # before: live memories only
result = korely.delete_all(user_id="test-user-1")
print(result.memories_deleted, result.facts_deleted, result.audit_id)
print(korely.get_all(user_id="test-user-1").total) # after: 0

You see three lines like:

1
1 0 aud_5f0c2d9e8b7a4c1d9e3f6a2b1c0d4e8f
0

The first line is the end user's memories before the erasure. The second holds the memories and the facts erased (0 facts if none were extracted yet), then the audit_id: save it. The third line is the count after.

Check the id before you erase. If the id matches nothing, the call still answers 200 with 0 0 and a new audit_id, so a typo looks like success. Match the user_id exactly, case and spaces included, and look for it in the list of end users (korely.users()). An end user appears there as soon as Korely holds anything of theirs, even when every count is 0. This holds from Korely 1.0.23. Memories sent in a batch whose job has not finished are not read for that list.

Use the list, not the count, to know if the id exists. A count of 0 in the first line does not prove the id is wrong. It counts live memories only, so it leaves out forgotten memories and end users who only have facts written with POST /v1/facts. The erasure takes both. If the list shows the id, erase.

A count of 0 after the call is not proof on its own. The proof is the audit_id you saved.

Stop writing for that id first. A write after the call creates the end user again.

Reference

Request

DELETE /v1/users/{end_user}/memories, with the header Authorization: Bearer <key> and a key with memories:write from the project that holds the end user. end_user is the exact user_id, up to 255 characters; in curl, write a space as %20 and / as %2F (the SDKs do it).

Example

from korely_memory import Korely
korely = Korely()
result = korely.delete_all(user_id="customer-4812")
print(result.memories_deleted, result.facts_deleted, result.audit_id)
# 47 12 aud_5f0c2d9e8b7a4c1d9e3f6a2b1c0d4e8f

Without --yes the CLI exits with code 2 and erases nothing.

Response

{
"user_id": "customer-4812",
"memories_deleted": 47,
"facts_deleted": 12,
"erasure": "permanent",
"audit_id": "aud_5f0c2d9e8b7a4c1d9e3f6a2b1c0d4e8f"
}

These counts also include what list calls leave out:

Errors

On every error below, nothing was erased. Branch on code; message is for a person.

StatusCodeWhen it happens
401 invalid_key The key is missing, malformed, unknown, revoked or expired. Send a valid key.
403 forbidden The key lacks memories:write, or it is a confined key that does not cover this end user.
422 invalid_request The id is empty, longer than 255 characters, contains a NUL byte, or is an already-erased pseudonym (erased: followed by 32 lowercase hex characters).
429 rate_limit_exceeded Your account hit its rate limit for this minute, hour or day. Retry after Retry-After seconds.
503 unavailable The database is busy with another change to the same data. Retry after Retry-After seconds.

Details

Skip this section on a first try.

  • Also erased. In the same database transaction, the call erases the other names you declared for the user in this project, such as Maria Rossi for the id maria. It also erases the relation words (predicates) Korely learned from their facts, such as lives in.
  • Not erased. Memories without a user_id, or under another id, stay even if they name the person. Copies outside Korely are yours: your logs and databases, and the model provider that read the text to extract facts.
  • What Korely keeps. A record of the erasure with the counts and the pseudonym, never the content. Encrypted nightly backups keep a copy for up to 35 days.
  • Projects and agents. One call per project, with that project's key; the same id in another project stays intact. The call covers every agent_id, and so does korely delete-all.
  • Timeouts. Repeat the call. If the first one succeeded, you get zeros and a new audit_id, and the first audit_id cannot be read back.
  • Keep your receipt. Store the audit_id and the call time. If you lose the audit_id, the audit log still has a row for the call. Read it with GET /v1/audit?user_id=, the same id and a memories:read key. The row has action erase, the counts and the pseudonym, but no audit_id. Erasing one memory (Delete a memory) writes an erase row too; yours has endpoint set to users:delete in meta. One row, with some fields left out:
    {"action": "erase", "user_id": "erased:3f9a...", "target_id": null,
    "meta": {"endpoint": "users:delete", "memories": 47, "facts": 12}}

Related

  • List users: it does not list writes made without a user_id or the end users of a batch not imported yet, and it returns one page at a time, so build your deletion list from the ids you wrote.
  • Declare a name: give an end user another name, such as a full name for the id.
  • Delete the account: the whole account, with an admin key that is not confined to some end users, so read the warning there first.