diff --git a/pageindex/storage/sqlite.py b/pageindex/storage/sqlite.py index bcd9d81..945eec5 100644 --- a/pageindex/storage/sqlite.py +++ b/pageindex/storage/sqlite.py @@ -210,7 +210,9 @@ class SQLiteStorage: def list_documents(self, collection: str) -> list[dict]: conn = self._get_conn() rows = conn.execute( - "SELECT doc_id, doc_name, doc_description, doc_type FROM documents WHERE collection_name = ? ORDER BY created_at", + # Newest first, matching the cloud API's createdAt DESC order; + # rowid breaks same-second ties by insertion order. + "SELECT doc_id, doc_name, doc_description, doc_type FROM documents WHERE collection_name = ? ORDER BY created_at DESC, rowid DESC", (collection,), ).fetchall() return [{"doc_id": r[0], "doc_name": r[1], "doc_description": r[2] or "", "doc_type": r[3]} for r in rows]