Skip to content

馃敶 [DATA] save_chunks is insert-only - causes duplicates on re-ingest聽#13

Closed

Description

@FullFran

Problem

save_chunks() does INSERT without checking for existing chunks:

self.client.table('chunks').insert(chunk_dicts).execute()

On re-ingestion:

  • Duplicate chunks created
  • Search returns garbage

Solution

Use UPSERT with unique constraint:

# Option 1: Unique on (document_id, chunk_index)
# Option 2: Unique on (document_id, content_hash)

self.client.table('chunks').upsert(
    chunk_dicts,
    on_conflict='document_id,chunk_index'
).execute()

Requires DB migration to add unique constraint.

Files

  • src/infrastructure/database/supabase_repository.py
  • Migration for unique constraint

Acceptance Criteria

  • Unique constraint on chunks table
  • save_chunks uses upsert
  • Re-ingestion updates instead of duplicating

Activity

  1. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Resuelto. ahora usa upsert con en y existe el 铆ndice 煤nico en . Cierro la issue.

  2. FullFran commented on Jan 26, 2026

    @FullFran
    OwnerAuthor

    Corrijo comentario anterior (el backtick se interpret贸 en shell).

    Resuelto. save_chunks ahora usa upsert con on_conflict=document_id,chunk_index en src/infrastructure/database/supabase_repository.py y existe el 铆ndice 煤nico en migrations/001_add_chunk_unique_constraint.sql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions