# What Data Is Deleted and Preserved with Asset-Level `clearChatMemory` in TencentDB Agent Memory

> Understand what data is deleted and preserved with TencentDB Agent Memory asset-level clearChatMemory. Learn how it removes conversational content while retaining essential metadata.

- Repository: [Tencent Cloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
- Tags: how-to-guide
- Published: 2026-08-31

---

**Asset-level `clearChatMemory` deletes all conversational content layers (L0-L3, vectors, and storage files) while preserving asset metadata including `memory_id`, ownership, ACLs, and bindings.**

The TencentDB Agent Memory system implements a precise separation between **content** and **asset identity** when clearing chat memory. This design allows agents to perform a clean-slate operation without losing their memory configuration or requiring re-registration. The clear operation is implemented in [`MemoryCore/src/gateway/chat-memory-handlers.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/gateway/chat-memory-handlers.ts) and follows a strict "content-only deletion" policy.

## What Gets Deleted: All Content Layers

The `clearChatMemory` operation removes every piece of conversational data through the `clearChatMemoryContent` → `clearProfileStorage` pipeline. According to the source code at lines 66-70, the following content is permanently erased:

### Layered Memory Contents (L0-L3)

- **L0 raw dialogue** — Original conversation transcripts and messages
- **L1 extracted facts** — Structured factual extractions from conversations
- **L2 scene blocks** — Contextual scene summaries and narrative segments  
- **L3 profile records** — Generated persona and behavioral profiles

### Associated Storage and Vectors

The `clearProfileStorage` function (lines 45-63) enumerates and deletes the entire scoped storage prefix under `profiles/<team>:<agent>/...`. These files include:

```text
profiles/<team>:<agent>/<memory_id>/
├── persona.md
├── scene_blocks/
└── .metadata/scene_index.json

```

The function uses `createScopedStorageAdapter` to achieve scoped deletion of all profile-associated files.

### Audit Trail Records

For each cleared layer, the system records a **delete audit event** via `recordClearAudit` (lines 112-115). These events log *that* deletion occurred without retaining the original content, ensuring compliance and traceability.

## What Gets Preserved: Asset Metadata and Identity

The top-level comment at lines 4-7 explicitly states the design principle: **"`clear` 只删**内容**，不删资产"** ("clear only deletes content, not the asset"). The following remains intact:

| Preserved Element | Purpose |
|-------------------|---------|
| **`asset_id` / `memory_id`** | Stable identifier for memory addressability |
| **Team/Agent ownership** | Organizational binding and attribution |
| **ACL rules** | Access control permissions (who can read/write) |
| **Bindings** | Agent-to-memory associations |
| **Owner, name, visibility flags** | Administrative metadata |

This preservation means subsequent agent writes will **reuse the original `memory_id`** without requiring asset recreation. The asset record continues to exist in the metadata service and remains fully addressable.

## How to Invoke the Clear Operation

### REST API Endpoint

```typescript
import fetch from "node-fetch";

async function clearChatMemory(memoryIds: string[]) {
  const resp = await fetch("https://your-memory-hub/v3/chat-memory/clear", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      // Admin credentials required (see handler lines 13-16)
      Authorization: "Bearer <admin-token>",
      "x-tdai-service-id": "<service-id>",
    },
    body: JSON.stringify({ memory_ids: memoryIds }),
  });

  const data = await resp.json();
  console.log(data);
}

// Clear multiple assets in one call
clearChatMemory(["team1/agentA/memory123", "team2/agentB/memory456"]);

```

### TypeScript SDK

```typescript
import { MemoryClient } from "@tencentdb/agent-memory-core";

const client = new MemoryClient({ baseUrl: "https://your-memory-hub" });

await client.chatMemory.clear({
  memory_ids: ["team1/agentA/memory123"],
});

```

Both approaches invoke `handleChatMemoryClear` (lines 50-58), which orchestrates the deletion pipeline while respecting the content-only policy.

## Request Flow and Validation

The clear request passes through multiple layers before reaching the core handler:

1. **MemoryPanel route validation** — [`MemoryPanel/src/panel/http/routes/chat-memory.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/src/panel/http/routes/chat-memory.ts) performs owner validation and permission checks
2. **Target resolution** — `resolveChatMemoryTargets` (from [`metadata-service.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/metadata-service.ts)) maps `memory_id`s to their team/agent context
3. **Core execution** — [`chat-memory-handlers.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/chat-memory-handlers.ts) executes `clearChatMemoryContent` and `clearProfileStorage`

This architecture ensures that only authorized callers can trigger asset-level clears, while the core implementation guarantees consistent behavior across all entry points.

## Summary

- **Deleted:** All conversational content (L0-L3), vectors, profile storage files, and associated vectors — achieving a complete memory wipe
- **Preserved:** Asset identity (`memory_id`), ownership, ACLs, bindings, and administrative metadata — enabling seamless continuation
- **Key benefit:** Agents can reset their memory state without reconfiguration or asset re-registration
- **Implementation:** `clearChatMemory` in [`MemoryCore/src/gateway/chat-memory-handlers.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/gateway/chat-memory-handlers.ts) enforces this separation through `clearChatMemoryContent` and `clearProfileStorage`

## Frequently Asked Questions

### What happens to the `memory_id` after a clear operation?

The **`memory_id` remains unchanged and valid**. Because asset-level `clearChatMemory` preserves the metadata record, the same identifier can be used for subsequent read and write operations. The agent does not need to create a new memory asset or update any references.

### Can I recover data after calling `clearChatMemory`?

**No recovery is possible.** The deletion of L0-L3 content and profile storage files is permanent. While audit events record *that* the clear occurred, they do not retain the original content. Treat `clearChatMemory` as an irreversible operation.

### What's the difference between asset-level clear and content-level clear?

Asset-level clear (the `clearChatMemory` endpoint) operates on the **entire memory asset** and its associated storage, removing all layers while preserving metadata. Content-level operations would target specific layers or time ranges. The asset-level operation is atomic and comprehensive, designed for complete memory reset scenarios.

### Which credentials are required to call `clearChatMemory`?

The handler at lines 13-16 indicates that **admin-level credentials** are required: a Bearer token in the `Authorization` header and an `x-tdai-service-id` header. The MemoryPanel route performs additional owner validation before forwarding to the core handler, ensuring only authorized principals can trigger data deletion.