claude-memory/graph/code-patterns/embed-if-changed-pattern-compare-id-sets-to-skip-unnecessary-20b22f.md

853 B

id type title tags importance confidence created updated
20b22fc6-bf36-420d-ae9d-a67beba3a209 code_pattern embed --if-changed pattern: compare ID sets to skip unnecessary work
cognitive-memory
python
pattern
optimization
0.5 0.8 2026-02-19T20:53:28.365333+00:00 2026-02-19T20:53:28.365333+00:00

The --if-changed flag on claude-memory embed compares the set of memory UUIDs in _index.json against _embeddings.json. If the sets match (no new or deleted memories), it returns immediately with {"skipped": true} in ~0.1s. Also checks for provider changes (which force a full re-embed due to dimension mismatch). Pattern: load both files, compare set(index_entries.keys()) == set(embedding_entries.keys()). Simple, fast, and avoids unnecessary Ollama API calls. Useful for any timer-driven task that should be idempotent.