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

# Delete Memories

> Remove individual memories or clear entire sessions from Cognis

Cognis provides two deletion methods: `delete()` removes a single memory by ID, and `delete_session()` clears all messages and memories from an entire session.

## Delete a Single Memory

<Tabs>
  <Tab title="Hosted (lyzr-adk)">
    ```python theme={null}
    from lyzr import Cognis

    cog = Cognis(api_key="sk-your-api-key")

    success = cog.delete(memory_id="mem_abc123")
    print(success)  # True
    ```
  </Tab>

  <Tab title="Open Source (lyzr-cognis)">
    ```python theme={null}
    from cognis import Cognis

    m = Cognis(owner_id="user_alice")

    resp = m.delete(memory_id="mem_abc123")
    print(resp)  # {"success": True, "message": "Memory mem_abc123 deleted"}

    m.close()
    ```
  </Tab>
</Tabs>

### `delete()` Method Signature

```python theme={null}
cog.delete(
    memory_id: str,
    owner_id: str | None = None,
) -> bool
```

### `delete()` Parameters

| Parameter   | Type  | Required | Description                              |
| ----------- | ----- | -------- | ---------------------------------------- |
| `memory_id` | `str` | Yes      | The ID of the memory to delete.          |
| `owner_id`  | `str` | No       | Owner identifier for additional scoping. |

### Response

Returns `True` if the memory was successfully deleted.

## Delete an Entire Session

Remove all messages and memories associated with a session:

```python theme={null}
success = cog.delete_session(
    owner_id="user_alice",
    session_id="sess_001",
)
print(success)  # True
```

### `delete_session()` Method Signature

```python theme={null}
cog.delete_session(
    owner_id: str,
    session_id: str,
    agent_id: str | None = None,
) -> bool
```

### `delete_session()` Parameters

| Parameter    | Type  | Required | Description                                     |
| ------------ | ----- | -------- | ----------------------------------------------- |
| `owner_id`   | `str` | Yes      | Owner/user identifier.                          |
| `session_id` | `str` | Yes      | Session identifier to clear.                    |
| `agent_id`   | `str` | No       | Agent identifier to further scope the deletion. |

### Response

Returns `True` if the session was successfully cleared.

## Search and Delete Workflow

A common pattern is to search for a memory, then delete it:

```python theme={null}
# Find the memory
results = cog.search(query="outdated preference", owner_id="user_alice")

if results:
    memory_id = results[0].id
    print(f"Deleting: {results[0].content}")

    # Delete it
    cog.delete(memory_id=memory_id, owner_id="user_alice")
    print("Deleted successfully")
```

## Async Usage

```python theme={null}
import asyncio
from lyzr import Cognis

async def main():
    async with Cognis(api_key="sk-your-api-key") as cog:
        # Delete a single memory
        await cog.adelete(memory_id="mem_abc123")

        # Clear an entire session
        await cog.adelete_session(
            owner_id="user_alice",
            session_id="sess_001",
        )

asyncio.run(main())
```

<Warning>
  Deletion is irreversible. Once a memory or session is deleted, it cannot be recovered. Consider searching and reviewing memories before deleting them.
</Warning>
