MCPcopy Create free account
hub / github.com/MemTensor/MemOS / chunkExistsByContent

Method chunkExistsByContent

packages/memos-core/src/storage/sqlite.ts:1705–1711  ·  view source on GitHub ↗

* Check if a chunk with the same (session_key, role, content_hash) already exists. * Uses indexed content_hash for O(1) lookup to prevent duplicate ingestion * when agent_end sends the full conversation history every turn.

(sessionKey: string, role: string, content: string)

Source from the content-addressed store, hash-verified

1703 * when agent_end sends the full conversation history every turn.
1704 */
1705 chunkExistsByContent(sessionKey: string, role: string, content: string): boolean {
1706 const hash = contentHash(content);
1707 const row = this.db.prepare(
1708 "SELECT 1 FROM chunks WHERE session_key = ? AND role = ? AND content_hash = ? LIMIT 1",
1709 ).get(sessionKey, role, hash);
1710 return !!row;
1711 }
1712
1713 /**
1714 * Find an active chunk with the same content_hash within the same owner (agent dimension).

Callers 2

runMigrationMethod · 0.45
importAgentMethod · 0.45

Calls 3

prepareMethod · 0.80
contentHashFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected