# How TencentDB Agent Memory Measures and Improves Long-Term Memory Capabilities

> Measure and improve TencentDB Agent Memory long-term capabilities with automated scoring, end-to-end testing, and pipeline tuning for enhanced extraction accuracy.

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

---

**TencentDB Agent Memory implements a four-layer pipeline with automated relevance scoring, end-to-end testing, and telemetry logging to measure extraction accuracy, while enabling continuous improvement through configurable pipeline tuning and vector store optimization.**

The open-source TencentDB-Agent-Memory repository provides a production-grade long-term memory system for conversational AI agents. At its core, the architecture transforms raw conversation data into durable persona knowledge through a structured L0-to-L3 pipeline, embedding measurement hooks at every stage to ensure retrieval accuracy and system reliability.

## Four-Layer Memory Architecture

The foundation of long-term memory capabilities rests on a **four-layer pipeline** defined in [`MemoryCore/hermes-plugin/memory/memory_tencentdb/README.md`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/hermes-plugin/memory/memory_tencentdb/README.md). This architecture progressively refines ephemeral conversation data into persistent knowledge:

- **L0 (Conversation Capture):** Raw user turns are stored in SQLite or Tencent Cloud VectorDB (TCVDB), serving as the immutable event log.
- **L1 (Episodic Extraction):** An LLM-driven summarizer processes L0 data to generate structured memory records with relevance metadata.
- **L2 (Scene Blocks):** Related episodic memories are aggregated into contextual scene blocks for efficient retrieval.
- **L3 (Persona Synthesis):** High-level persona summaries are derived from scene blocks, creating stable long-term profile data stored in the `"memory"` region declared in [`MemoryProxy/src/injection/types.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/injection/types.ts) at line 196.

## How Long-Term Memory Capabilities Are Measured

### Relevance Scoring via Search Tools

The system exposes a `memory_tencentdb_memory_search` tool registered in [`MemoryCore/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/index.ts) (line 384) that returns **relevance scores** for retrieved memories. When an LLM queries long-term storage, each returned record includes a numerical `score` field indicating semantic similarity to the query. This enables quantitative ranking of memory relevance and direct measurement of retrieval precision.

```python

# Example: Searching long-term memory with relevance scoring

result = memory_tencentdb_memory_search(
    query="What is the user's preferred database version?",
    limit=5,
    type="persona"  # Options: persona, episodic, instruction

)

# Results include relevance scores for measurement

for rec in result:
    print(f"[score={rec['score']:.2f}] {rec['content']}")

```

### Automated Evaluation Tests

The repository includes an end-to-end validation script at [`MemoryCore/scripts/e2e-memory-prompt-vdb-cos.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/scripts/e2e-memory-prompt-vdb-cos.ts) (line 352) that asserts specific project codes or entities appear in generated memories. This provides a binary pass/fail metric for the L1 extraction stage, ensuring that the long-term memory pipeline correctly persists critical information from raw conversations.

```bash

# Run automated evaluation to verify extraction accuracy

npm run test:e2e-memory-prompt-vdb-cos

```

### Telemetry and Observability

Long-term memory operations are instrumented in [`MemoryCore/src/core/storage/adapter.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/core/storage/adapter.ts) (line 214), where the storage adapter logs persona backup rotations and other durability events. These logs integrate with external observability pipelines for SLA tracking and performance monitoring, providing operational metrics on memory system health.

## How Long-Term Memory Capabilities Are Improved

### Pipeline Tuning and Prompt Optimization

Improvement begins at the **L1 extraction layer**, where developers can adjust LLM prompts, temperature settings, and deduplication thresholds to increase extraction fidelity. The L3 persona synthesis prompts can be refined to generate higher-quality, stabler knowledge artifacts that better represent user preferences over time.

### Vector Store Backend Upgrades

The architecture supports swapping the default `sqlite-vec` backend for **Tencent VectorDB** to enhance similarity search performance. This upgrade improves the relevance scoring accuracy and reduces latency for `memory_tencentdb_memory_search` operations, directly enhancing the measured quality of long-term retrieval.

### Circuit Breakers and Back-Pressure

To maintain consistent performance under load, the provider enforces runtime safeguards documented in the README: a maximum of **4 in-flight capture threads** and a **60-second circuit-breaker pause**. These mechanisms prevent pipeline overload, ensuring that long-term memory ingestion remains reliable during traffic spikes and protecting the measurement integrity of the system.

```typescript
// Example: Capturing a turn that feeds the long-term pipeline
import { sync_turn } from "MemoryProxy/src/turnSeq";

await sync_turn({
  user: "I started a new project called AlphaX.",
  assistant: "Got it! I'll remember AlphaX for future references."
});
// Background capture eventually persists to L1 vector store

```

## Key Files for Long-Term Memory Implementation

- **[`MemoryCore/hermes-plugin/memory/memory_tencentdb/README.md`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/hermes-plugin/memory/memory_tencentdb/README.md)** – Documents the four-layer pipeline, gateway interaction patterns, and LLM tool schemas.
- **[`MemoryCore/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/index.ts)** – Registers the `memory_tencentdb_memory_search` tool and exposes relevance scoring APIs.
- **[`MemoryProxy/src/injection/types.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/injection/types.ts)** – Declares the `"memory"` region type used for long-term profile slots (line 196).
- **[`MemoryCore/scripts/e2e-memory-prompt-vdb-cos.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/scripts/e2e-memory-prompt-vdb-cos.ts)** – Contains automated tests that validate long-term extraction accuracy (line 352).
- **[`MemoryCore/src/core/storage/adapter.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/core/storage/adapter.ts)** – Handles telemetry logging for long-term work events and persona backups (line 214).
- **[`MemoryProxy/src/tdai/capabilities.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/tdai/capabilities.ts)** – Lists `"long-term-memory"` as a supported capability for feature gating.
- **[`MemoryProxy/src/turnSeq.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/turnSeq.ts)** – Entry point for turn-level capture that feeds raw data into the L0→L3 pipeline.

## Summary

- **Four-layer pipeline:** TencentDB Agent Memory structures long-term storage as L0 (raw) → L1 (episodic) → L2 (scene) → L3 (persona) for progressive refinement.
- **Quantitative measurement:** Relevance scores from `memory_tencentdb_memory_search`, automated pass/fail assertions in the E2E test suite, and storage adapter telemetry provide multi-dimensional accuracy metrics.
- **Continuous improvement:** Pipeline tuning, vector store upgrades (sqlite-vec to Tencent VectorDB), and runtime safeguards (4-thread limit, 60s circuit breaker) enable iterative enhancement of memory fidelity.
- **Production reliability:** Capability declarations in [`capabilities.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/capabilities.ts) and back-pressure mechanisms ensure the long-term memory system scales reliably in production environments.

## Frequently Asked Questions

### How does TencentDB Agent Memory calculate relevance scores for long-term memories?

The `memory_tencentdb_memory_search` tool, implemented in [`MemoryCore/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/index.ts), returns records with a `score` field representing the semantic similarity between the query vector and stored memory vectors. These scores are computed by the underlying vector store (sqlite-vec or Tencent VectorDB) using cosine similarity or equivalent distance metrics, allowing the LLM to rank memories by relevance.

### What is the purpose of the e2e-memory-prompt-vdb-cos.ts test script?

This script serves as an automated regression test for the L1 extraction layer. It feeds known prompts into the memory pipeline and asserts that specific entities (like project codes) appear in the generated L1 structured memories. A passing test confirms that the long-term extraction stage correctly persists critical information, providing a binary quality gate for the system.

### Can the long-term memory pipeline handle high-concurrency workloads?

Yes. The system includes back-pressure mechanisms that limit concurrent capture to four threads and implements a 60-second circuit breaker to prevent overload. These safeguards are documented in the Hermes plugin README and ensure that long-term memory ingestion remains stable even during traffic spikes, protecting both measurement accuracy and system reliability.

### Where is long-term persona data physically stored?

Long-term persona data resides in the `"memory"` region, declared in [`MemoryProxy/src/injection/types.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryProxy/src/injection/types.ts) (line 196). Physically, this data is stored in either SQLite with the sqlite-vec extension or Tencent Cloud VectorDB (TCVDB), depending on the deployment configuration. The storage adapter in [`MemoryCore/src/core/storage/adapter.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/core/storage/adapter.ts) manages backup rotation and durability guarantees for this data.