> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tensorpro.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing memory

> Learn how to list, read, edit, confirm, trace and delete memories stored in EDN.

EDN provides API endpoints to manage the memories it holds. You can list and inspect memories, edit their content, confirm AI memories, review their history and delete memories that are no longer needed.

### 1. List memories

Use **List memories** to retrieve your stored memories, newest first.

You can filter the results using:

* `provenance`: Filter by the memory's provenance class.
* `domain`: Filter by memory category.
* `q`: Search for text in the memory's summary, without case sensitivity.
* `days`: Only return memories created in the last N days.
* `order`: Use `desc` for newest first (the default) or `asc` for oldest first.
* `project_id`: Filter by project. Without `project_id`, the list covers all memory. With `project_id`, it includes that project's memory and general memory.

Use `limit` and `offset` to paginate the results. The default `limit` is 50, with a maximum of 200. The response includes `total`, the number of matching memories across all pages.

Each memory includes:

* `id`: The memory's identifier.
* `content_summary`: The memory's summary, up to 500 characters.
* `provenance`: The memory's provenance class.
* `domain`: The memory's category.
* `created_at`: When the memory was created.
* `status`: The memory's current status.
* `superseded_by`: The identifier of the newer version, when replaced.

Deleted memories are not listed. Memories replaced by an edit or correction remain in the list with `status` set to `replaced` and `superseded_by` pointing to the newer version.

```bash cURL theme={"theme":"github-light"}
# EDN_API_KEY: your API key (see the Quickstart).
curl -s -G https://api.tensorpro.ai/api/v1/memory/records \
  -H "Authorization: Bearer $EDN_API_KEY" \
  --data-urlencode "provenance=USER_STATED" \
  --data-urlencode "q=website" \
  --data-urlencode "days=30" \
  --data-urlencode "limit=50" \
  --data-urlencode "offset=0" \
  | jq -r '"total: \(.total)", (.records[] | "\(.id) \(.status) \(.provenance): \(.content_summary)")'
```

```python Python theme={"theme":"github-light"}
import os
import requests

EDN = "https://api.tensorpro.ai/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['EDN_API_KEY']}"}

page = requests.get(
    f"{EDN}/memory/records",
    headers=HEADERS,
    params={
        "provenance": "USER_STATED",
        "q": "website",
        "days": 30,
        "limit": 50,
        "offset": 0,
    },
).json()

print(page["total"])
for record in page["records"]:
    print(record["id"], record["status"], record["provenance"], record["content_summary"])

record_id = page["records"][0]["id"]
```

```typescript TypeScript theme={"theme":"github-light"}
const EDN = "https://api.tensorpro.ai/api/v1";
const HEADERS = {
  Authorization: `Bearer ${process.env.EDN_API_KEY}`,
  "Content-Type": "application/json",
};

const params = new URLSearchParams({
  provenance: "USER_STATED",
  q: "website",
  days: "30",
  limit: "50",
  offset: "0",
});
const page = await (
  await fetch(`${EDN}/memory/records?${params}`, { headers: HEADERS })
).json();

console.log(page.total);
for (const record of page.records) {
  console.log(record.id, record.status, record.provenance, record.content_summary);
}

const recordId = page.records[0].id;
```

### 2. Get one memory

Use **Get a memory** to retrieve a memory by its `record_id`, including its full text, source and status.

The `full_text` field contains the complete memory text. For a saved exchange (`ROUND`), it contains the full user-assistant exchange.

The response also includes:

* `project_id`: The project associated with the memory.
* `session_id`: The conversation session associated with the memory.
* `source_id`: The project document the memory came from, or null.
* `supersedes`: The identifier of the earlier version, or null.
* `superseded_by`: The identifier of the newer version, or null.

You can also retrieve a replaced memory. Its `superseded_by` field points to the newer version.

```bash cURL theme={"theme":"github-light"}
# YOUR_RECORD_ID: a memory id, for example from step 1.
curl -s https://api.tensorpro.ai/api/v1/memory/records/YOUR_RECORD_ID \
  -H "Authorization: Bearer $EDN_API_KEY"
```

```python Python theme={"theme":"github-light"}
# EDN, HEADERS and record_id: from step 1.
memory = requests.get(
    f"{EDN}/memory/records/{record_id}",
    headers=HEADERS,
).json()

print(memory["status"], memory["provenance"])
print(memory["full_text"])
print(memory["supersedes"], memory["superseded_by"])
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN, HEADERS and recordId: from step 1.
const memory = await (
  await fetch(`${EDN}/memory/records/${recordId}`, { headers: HEADERS })
).json();

console.log(memory.status, memory.provenance);
console.log(memory.full_text);
console.log(memory.supersedes, memory.superseded_by);
```

### 3. Edit a memory

Use **Edit a memory** to change the content of an existing memory.

Send the corrected text in the `content` field, up to 1,000 characters.

EDN saves the new text as a new `USER_CONFIRMED` memory and keeps the previous version in the memory's history. The response contains the new memory. Use its `id` for subsequent operations.

You can edit memories with these provenance classes:

* `USER_STATED`
* `USER_CONFIRMED`
* `AI_INFERRED`
* `AI_GENERATED`

Documents (`DOCUMENT_VERIFIED`) and saved exchanges (`ROUND`) cannot be edited. EDN returns `409` for these memories.

```bash cURL theme={"theme":"github-light"}
# YOUR_RECORD_ID: the memory to edit, for example from step 1.
curl -s -X PATCH https://api.tensorpro.ai/api/v1/memory/records/YOUR_RECORD_ID \
  -H "Authorization: Bearer $EDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "Priya manages the website project."}' \
  | jq -r '.id'
```

```python Python theme={"theme":"github-light"}
# EDN, HEADERS and record_id: from step 1.
resp = requests.patch(
    f"{EDN}/memory/records/{record_id}",
    headers=HEADERS,
    json={"content": "Priya manages the website project."},
)
if resp.status_code == 409:
    print("This memory cannot be edited (a document or a saved exchange).")
else:
    edited = resp.json()
    record_id = edited["id"]  # use the new id from now on
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN, HEADERS and recordId: from step 1.
const editResp = await fetch(`${EDN}/memory/records/${recordId}`, {
  method: "PATCH",
  headers: HEADERS,
  body: JSON.stringify({ content: "Priya manages the website project." }),
});
let currentId = recordId;
if (editResp.status === 409) {
  console.log("This memory cannot be edited (a document or a saved exchange).");
} else {
  const edited = await editResp.json();
  currentId = edited.id; // use the new id from now on
}
```

### 4. Confirm an AI memory

Use **Confirm a memory** when the user agrees with an `AI_INFERRED` or `AI_GENERATED` memory.

Send the `record_id` returned by **Classify an AI response** or **Save a generated statement**.

EDN creates a new `USER_CONFIRMED` memory, which is used in Session Initialization Packages (SIPs) from then on.

The response includes:

* `record_id`: The identifier of the new `USER_CONFIRMED` memory.
* `replaces`: The identifier of the original AI memory that was confirmed.

The original memory no longer appears in memory lists or SIPs. Use the new `record_id` for subsequent operations.

EDN returns `409` if the memory does not need confirming.

```bash cURL theme={"theme":"github-light"}
# YOUR_AI_RECORD_ID: the record_id returned by memory/infer or memory/generated.
curl -s https://api.tensorpro.ai/api/v1/memory/confirm \
  -H "Authorization: Bearer $EDN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"record_id": "YOUR_AI_RECORD_ID"}'
```

```python Python theme={"theme":"github-light"}
# EDN and HEADERS: from step 1.
# ai_record_id: the record_id returned by memory/infer or memory/generated.
ai_record_id = "YOUR_AI_RECORD_ID"

resp = requests.post(
    f"{EDN}/memory/confirm",
    headers=HEADERS,
    json={"record_id": ai_record_id},
)
if resp.status_code == 409:
    print("This memory does not need confirming.")
else:
    confirmed = resp.json()
    print(confirmed["record_id"], "replaces", confirmed["replaces"])
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN and HEADERS: from step 1.
// aiRecordId: the record_id returned by memory/infer or memory/generated.
const aiRecordId = "YOUR_AI_RECORD_ID";

const confirmResp = await fetch(`${EDN}/memory/confirm`, {
  method: "POST",
  headers: HEADERS,
  body: JSON.stringify({ record_id: aiRecordId }),
});
if (confirmResp.status === 409) {
  console.log("This memory does not need confirming.");
} else {
  const confirmed = await confirmResp.json();
  console.log(confirmed.record_id, "replaces", confirmed.replaces);
}
```

### 5. See a memory's history

Use **Get a memory's history** to retrieve every version of a memory.

EDN links versions created through edits, corrections and confirmations. You can pass the `record_id` of any version to retrieve its complete history.

The response contains a `versions` array, ordered from oldest to newest. The final entry is the latest version.

```bash cURL theme={"theme":"github-light"}
# YOUR_RECORD_ID: the id of any version of the memory.
curl -s https://api.tensorpro.ai/api/v1/memory/records/YOUR_RECORD_ID/history \
  -H "Authorization: Bearer $EDN_API_KEY"
```

```python Python theme={"theme":"github-light"}
# EDN, HEADERS and record_id: from step 1 (any version's id works).
history = requests.get(
    f"{EDN}/memory/records/{record_id}/history",
    headers=HEADERS,
).json()

versions = history["versions"]  # oldest first
latest = versions[-1]
print(len(versions), latest["id"], latest["content_summary"])
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN, HEADERS and recordId: from step 1 (any version's id works).
const history = await (
  await fetch(`${EDN}/memory/records/${recordId}/history`, { headers: HEADERS })
).json();

const versions = history.versions; // oldest first
const latest = versions[versions.length - 1];
console.log(versions.length, latest.id, latest.content_summary);
```

### 6. Delete a memory

Use **Delete a memory** to remove a memory by its `record_id`.

Once deleted, the memory is no longer used in SIPs or search and does not appear in memory lists.

The endpoint returns `204` with no response body.

```bash cURL theme={"theme":"github-light"}
# YOUR_RECORD_ID: the memory to delete. Prints 204 on success.
curl -s -o /dev/null -w "%{http_code}\n" -X DELETE \
  https://api.tensorpro.ai/api/v1/memory/records/YOUR_RECORD_ID \
  -H "Authorization: Bearer $EDN_API_KEY"
```

```python Python theme={"theme":"github-light"}
# EDN, HEADERS and record_id: from step 1.
resp = requests.delete(
    f"{EDN}/memory/records/{record_id}",
    headers=HEADERS,
)
print(resp.status_code)  # 204, no response body
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN, HEADERS and recordId: from step 1.
const deleteResp = await fetch(`${EDN}/memory/records/${recordId}`, {
  method: "DELETE",
  headers: HEADERS,
});
console.log(deleteResp.status); // 204, no response body
```

### 7. Replaced, confirmed and deleted memories

EDN handles replaced, confirmed and deleted memories differently.

| State | What happens |
| - | - |
| **Replaced** | An edit or correction creates a newer version. The original remains listed with `status` set to `replaced`, but is no longer used in SIPs. |
| **Confirmed** | Confirming an AI memory creates a new `USER_CONFIRMED` memory. The original no longer appears in memory lists or SIPs. |
| **Deleted** | The memory is no longer listed, searched or used in SIPs. In a memory's history, a deleted version has `status` set to `deleted`. |

Use **Get a memory's history** to trace changes across versions created by edits, corrections and confirmations.

```bash cURL theme={"theme":"github-light"}
# YOUR_RECORD_ID: the id of any version of the memory.
curl -s https://api.tensorpro.ai/api/v1/memory/records/YOUR_RECORD_ID/history \
  -H "Authorization: Bearer $EDN_API_KEY" \
  | jq -r '.versions[] | "\(.created_at) \(.id) \(.status) \(.provenance) supersedes=\(.supersedes // "-")"'
```

```python Python theme={"theme":"github-light"}
# EDN, HEADERS and record_id: from step 1 (any version's id works).
versions = requests.get(
    f"{EDN}/memory/records/{record_id}/history",
    headers=HEADERS,
).json()["versions"]

for v in versions:
    print(v["created_at"], v["id"], v["status"], v["provenance"], v["supersedes"])

current = [v for v in versions if v["status"] == "current"]
deleted = [v for v in versions if v["status"] == "deleted"]
```

```typescript TypeScript theme={"theme":"github-light"}
// EDN, HEADERS and recordId: from step 1 (any version's id works).
const { versions: allVersions } = await (
  await fetch(`${EDN}/memory/records/${recordId}/history`, { headers: HEADERS })
).json();

for (const v of allVersions) {
  console.log(v.created_at, v.id, v.status, v.provenance, v.supersedes);
}

const current = allVersions.filter((v) => v.status === "current");
const deleted = allVersions.filter((v) => v.status === "deleted");
```

***

**Next steps:** See [List memories](https://docs.tensorpro.ai/api-reference/list-memory-records.md) and [Edit a memory](https://docs.tensorpro.ai/api-reference/edit-memory-record.md) for the API reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.