How can I fix the duplicate key value error in AI summaries?

AI-generated summary

In a bug report titled ‘How can I fix the duplicate key value error in AI summaries?’, Don reported an issue where AI topic summarization fails due to a PostgreSQL unique constraint violation: duplicate key value violates unique constraint "ai_summaries_pkey". The error causes summarization to hang and prevents saving or caching summaries, forcing Don to disable the feature. Initially, Don suspected the model name claude-3-5-sonnet, but switching to claude-3-5-sonnet-20240620 (as suggested in Anthropic’s docs) didn’t resolve it — the issue persisted across models and appeared tied to topic summarization logic. Don noted similar behavior occurred on Meta after merging the ‘Add the summarization logic from core’ commit, but not currently. In post 2, Don confirmed that a fix resolved the issue, and subsequent tests succeeded, expressing gratitude with :heart_eyes:. The issue was tagged ‘ai’ and ‘fixed’, indicating resolution.

Thanks for the update! Unfortunately it seems the summary is sometimes broke with the following error for me. :confused:

Job exception: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "ai_summaries_pkey"
DETAIL:  Key (id)=(7) already exists.

Ah ok it seems fixed by change the model name from claude-3-5-sonnet to claude-3-5-sonnet-20240620. Found here: Models overview - Claude API Docs

Nope it happened again :confused:


Any idea to solve it? The problem is the topic summarization is not finishing. It generation is stuck on the end of the summary so it can’t save. So it can’t comes from cache when I open the topic again and every time the summary generate again. Now I have to disable the topic summaries. I have no idea why this happens. I experienced the same on Meta after merged the (Add the summarization logic from core) commit but not anymore happens here.

However it isn’t seems to related with Claude 3.5 Sonnet (I tried it with others too) but the topic summarization. So maybe would be better to move to other topic… Thanks :slightly_smiling_face:

2 Likes

Thanks @Falco, This fix seems solved my issue :point_up:
I did a few test summarization now and works great. :heart_eyes:

5 Likes