Repository: phidatahq/phidata
Issue category: Bug Report

Issue:
Duplicate key value violates unique constraint with recursive chunking
When use `RecursiveChunking` with large files, some errors happen:

```
ERROR    Error with batch starting at index 0: (psycopg.errors.UniqueViolation) duplicate key value violates unique constraint "recipes_agentic_recursive_chunking_pkey"
         DETAIL:  Key (id)=(relativity_1) already exists.
```



Hints:

Patch:
diff --git a/phi/document/chunking/recursive.py b/phi/document/chunking/recursive.py
index 662a9218c..47c552294 100644
--- a/phi/document/chunking/recursive.py
+++ b/phi/document/chunking/recursive.py
@@ -38,6 +38,7 @@ def chunk(self, document: Document) -> List[Document]:
             chunk_id = None
             if document.id:
                 chunk_id = f"{document.id}_{chunk_number}"
+            chunk_number += 1
             meta_data["chunk_size"] = len(chunk)
             chunks.append(Document(id=chunk_id, name=document.name, meta_data=meta_data, content=chunk))
 


Test patch: