--- id: 20b22fc6-bf36-420d-ae9d-a67beba3a209 type: code_pattern title: "embed --if-changed pattern: compare ID sets to skip unnecessary work" tags: [cognitive-memory, python, pattern, optimization] importance: 0.5 confidence: 0.8 created: "2026-02-19T20:53:28.365333+00:00" updated: "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.