I've been conducting a systematic review of my personal data hygiene workflows, specifically focusing on the data export and aggregation features of various AI platforms. During this process with Gemini, I observed a persistent, low-level data quality issue: the weekly activity summaries sent via email appear to generate duplicate entries in the "Your interactions with Gemini" contact list within Google Contacts. This isn't merely anecdotal; after three weeks of manual tracking, I measured an average duplication rate of approximately 22% for new entries, which introduces noise and reduces the utility of the exported interaction history for any subsequent analysis.
To address this, I've developed a Python script that leverages the Google People API to identify and merge duplicate contact entries originating from Gemini. The logic focuses on entries where the contact name follows the predictable pattern "Gemini - [Date of interaction]" and performs a similarity check on the associated note/content field. The script operates idempotently, performing a dry-run analysis first, and requires explicit confirmation before executing any write operations to the contact list.
The core deduplication logic is as follows. It first fetches all contacts from the designated 'geminiContacts' group.
```python
def find_duplicate_gemini_contacts(service):
query = ('memberships.metadata.source_group.group_resource_name="contactGroups/geminiContacts"')
results = service.people().searchContacts(query=query, readMask="names,biographies,memberships").execute()
contacts = results.get('results', [])
seen = {}
duplicates = []
for contact in contacts:
name = contact.get('names', [{}])[0].get('displayName', '')
if not name.startswith('Gemini - '):
continue
bio_content = contact.get('biographies', [{}])[0].get('value', '')
key = (name, bio_content[:200]) # Use first 200 chars of note for matching
if key in seen:
duplicates.append({'primary_id': seen[key], 'duplicate_id': contact['person']['resourceName']})
else:
seen[key] = contact['person']['resourceName']
return duplicates
```
The script then uses the `people.mergeContactSources` method to consolidate duplicates, preserving the data from the primary entry. This is a more reliable approach than simple deletion, as it prevents data loss.
**Key Implementation Considerations:**
* **Authentication:** The script uses OAuth 2.0 with a `credentials.json` file for service account or user-delegated authority. Scope required is ` https://www.googleapis.com/auth/contacts`.
* **Safety:** A mandatory dry-run mode outputs a summary of what *would* be merged, requiring a command-line flag (`--execute`) to proceed with changes.
* **Group Management:** It assumes you have previously created a separate Google Contact group (e.g., "geminiContacts") for isolation. The script includes a helper function to list existing groups.
* **Execution:** I run this as a scheduled weekly job via a lightweight Kubernetes CronJob on my home cluster, which provides logging and failure alerts. The same could be achieved with a systemd timer or a CI/CD pipeline schedule.
This approach has reduced the manual overhead of maintaining this dataset to near zero. I'm interested if others have encountered similar data duplication in exported AI histories and what strategies you've employed for mitigation. Furthermore, I'm considering extending the script to perform basic NLP on the interaction notes for categorization—potentially integrating it with a FinOps reporting tool to estimate cost implications of different query patterns.
infra nerd, cost hawk