What Information Is Stored in the L0 Memory Layer in TencentDB Agent Memory
The L0 (Layer 0) memory layer serves as the foundational storage tier in TencentDB Agent Memory, persisting raw conversation records including session keys, message content, timestamps, roles, optional embedding vectors, and metadata—serving as the immutable source of truth for higher-level processing layers.
The L0 memory layer acts as the primary ingestion and persistence tier for the TencentCloud/TencentDB-Agent-Memory repository. Unlike higher abstraction layers, L0 deliberately avoids summarization, capturing unprocessed conversation data that downstream components (L1-L3) later refine. Understanding what data resides in L0 is essential for debugging memory flows, optimizing retrieval performance, and implementing custom memory skills.
Core Data Elements Stored in L0
Session Identification and Grouping
Every L0 record contains a sessionKey field that groups messages belonging to the same conversation context. According to MemoryCore/src/core/store/tcvdb.ts, this identifier enables session-scoped queries and ensures temporal continuity across multi-turn dialogues. The session key acts as the primary clustering mechanism, allowing the system to retrieve complete conversation histories for specific users or interaction threads.
Raw Message Content and Role Metadata
The layer stores the original content (or text) of user and assistant utterances without transformation or compression. The role field indicates the message origin—normalized to values like user, assistant, tool_call, or tool_result as implemented in MemoryCore/src/core/skill/skill-extractor.ts. This raw preservation ensures that higher layers can reprocess historical data with updated algorithms while maintaining an immutable audit trail of the exact inputs received.
High-Resolution Temporal Data
Each entry includes a recordedAtMs timestamp (millisecond resolution) as defined in the storage schema. This field supports time-based retention policies, chronological replay, and expiration logic implemented in MemoryCore/src/utils/memory-cleaner.ts. The high precision enables accurate ordering of messages that arrive within the same second and supports sliding-window queries used by short-term memory processing.
Vector Embeddings for Similarity Search
L0 optionally stores pre-computed embedding vectors—Float32Array representations of message content. As seen in MemoryCore/src/core/store/sqlite.ts, these vectors populate dedicated columns (e.g., vec) to enable fast similarity searches directly against raw records. The MemoryCore/src/core/store/embedding.ts module handles local generation of these vectors, which are then persisted alongside the original text to support semantic retrieval without requiring reconstruction from higher abstraction layers.
Auxiliary Metadata and Lifecycle Flags
Additional key-value pairs supplied by clients—including message id, custom tags, or tool identifiers—are stored verbatim in metadata fields. The layer also maintains internal deletion markers such as expired or minRetain flags used by the memory cleaner to identify candidates for pruning. These flags enable soft-deletion workflows where L0 records can be marked for removal without immediate physical deletion, preserving referential integrity with downstream processing pipelines.
L0 Architecture and Relationship to Higher Layers
Unlike L1-L3, which generate chunks, summaries, and skill-specific extracts, L0 deliberately functions as an append-only log (with soft deletes). It serves three primary architectural purposes: source of truth for downstream processing, audit trail for debugging memory decisions, and replay buffer for reconstructing conversation states. The MemoryCore/src/core/store/tcvdb.ts implementation exposes methods like upsert() and queryForL1() that explicitly bridge raw L0 data to the L1 chunking pipeline, ensuring a clear data lineage from raw ingestion to processed memory.
Practical Code Examples for L0 Operations
Inserting raw messages into L0:
import { L0Store } from '@/core/store/tcvdb';
const message = {
sessionKey: 'session-12345',
role: 'user',
content: 'How does the memory service index messages?',
recordedAtMs: Date.now(),
// Optional: pre-computed embedding vector
// embedding: Float32Array.from([0.1, 0.2, ...]),
};
await L0Store.upsert(message);
Querying L0 records for L1 processing:
import { L0Store } from '@/core/store/tcvdb';
const records = await L0Store.queryForL1({
sessionKey: 'session-12345',
afterRecordedAtMs: Date.now() - 24 * 60 * 60 * 1000, // last 24 hours
});
// Returns array of raw messages with embeddings for L1 chunking
Performing vector similarity search on L0:
import { L0Store } from '@/core/store/tcvdb';
const queryVec = await embed('memory indexing');
const results = await L0Store.search({
queryEmbedding: queryVec,
topK: 5,
});
// Returns most relevant raw messages based on embedding similarity
Key Implementation Files
MemoryCore/src/core/store/tcvdb.ts: Primary L0 implementation containingupsert(), batch operations, session queries, and expiration handling logic.MemoryCore/src/core/store/sqlite.ts: SQLite-backed persistence layer defining the physical schema withv(raw text) andvec(embedding) columns.MemoryCore/src/utils/memory-cleaner.ts: Retention policy enforcement and soft-deletion logic for L0 records based on age and flags.MemoryCore/src/core/skill/skill-extractor.ts: Role normalization pipeline ensuring standardizeduser,assistant, and tool-related role values before L0 insertion.MemoryCore/src/core/store/embedding.ts: Local embedding generation service that produces vectors stored alongside raw messages in L0.
Summary
- The L0 memory layer stores raw, unprocessed conversation data including complete message text, session identifiers, and high-resolution timestamps.
- Each record contains normalized role metadata (
user,assistant,tool_call,tool_result) and optional embedding vectors for similarity retrieval. - Millisecond-precision timestamps (
recordedAtMs) enable time-based queries and automated expiration viaMemoryCore/src/utils/memory-cleaner.ts. - L0 serves as the immutable source of truth for higher layers (L1-L3), supporting debugging, replay, and audit capabilities without abstraction overhead.
- Data persistence is handled through both vector database interfaces (
tcvdb.ts) and SQLite storage (sqlite.ts), ensuring deployment flexibility across environments.
Frequently Asked Questions
Does L0 store processed summaries or only raw text?
L0 exclusively stores raw message content and metadata. Summaries and abstractions are generated by L1 and L2 layers which consume L0 records as input. This architectural separation ensures L0 remains an immutable audit trail while allowing higher layers to evolve their processing logic independently without invalidating historical storage.
How are embeddings managed in the L0 layer?
Embedding vectors are stored as optional Float32Array data alongside raw text in the vec column (SQLite) or equivalent vector database fields. The MemoryCore/src/core/store/embedding.ts module handles generation logic, while tcvdb.ts manages persistence, indexing, and similarity search operations against these vectors.
What determines when data is deleted from L0?
Deletion is governed by retention policies implemented in MemoryCore/src/utils/memory-cleaner.ts. Records are marked for removal based on age thresholds, session expiration, or manual deletion flags (expired, minRetain). L0 typically uses soft deletion to maintain referential integrity with downstream layers that may still reference raw record IDs.
Can I query L0 directly for my application, or must I go through L1-L3?
While the architecture permits direct L0 queries via L0Store.queryForL1() or L0Store.search(), production applications should typically interact with higher layers that provide filtered, summarized, or skill-specific views. Direct L0 access is recommended primarily for debugging, data migration, or custom skill development requiring unprocessed historical data.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →