From 11ba63debe70e05aef3a9a9029b61635f6058f60 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 24 Jul 2026 00:36:28 +0800 Subject: [PATCH] fix: drop unrecognized stream_metadata, align sort and page_count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove stream_metadata from chat/completions payloads — the server's ChatCompletionRequest model has no such field; it was silently ignored. - Local list_documents tie-breaker: rowid DESC → doc_id ASC, matching the server's "createdAt" DESC, "id" ASC ordering. - Cloud get_document: skip page_count when pageNum is 0 (server returns 0 for NULL, meaning "not yet computed", not "zero pages"). --- pageindex/backend/cloud.py | 3 +-- pageindex/cloud_api.py | 7 ------- pageindex/storage/sqlite.py | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/pageindex/backend/cloud.py b/pageindex/backend/cloud.py index ddf6b93..9f37da1 100644 --- a/pageindex/backend/cloud.py +++ b/pageindex/backend/cloud.py @@ -307,7 +307,7 @@ class CloudBackend: "status": resp.get("status", ""), "structure": self._normalize_tree(raw_tree, max_page=page_num), } - if page_num is not None: + if page_num: result["page_count"] = page_num return result @@ -508,7 +508,6 @@ class CloudBackend: "messages": [{"role": "user", "content": question}], "doc_id": doc_id, "stream": True, - "stream_metadata": True, }, stream=True, timeout=120, diff --git a/pageindex/cloud_api.py b/pageindex/cloud_api.py index 36767e3..a81a522 100644 --- a/pageindex/cloud_api.py +++ b/pageindex/cloud_api.py @@ -169,13 +169,6 @@ class LegacyCloudAPI: payload["temperature"] = temperature if enable_citations: payload["enable_citations"] = enable_citations - # Forward stream_metadata so the wire request matches the caller's intent - # (and stays correct if the server ever gates metadata chunks behind it), - # mirroring the modern CloudBackend which always sends it. It only affects - # streaming responses, where it selects the raw dict-chunk parser below. - if stream_metadata: - payload["stream_metadata"] = stream_metadata - # Non-streaming completions return no bytes until server-side # generation finishes — far longer than the default 30s read timeout. response = self._request( diff --git a/pageindex/storage/sqlite.py b/pageindex/storage/sqlite.py index c65d683..c253ef3 100644 --- a/pageindex/storage/sqlite.py +++ b/pageindex/storage/sqlite.py @@ -265,7 +265,7 @@ 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 DESC, rowid DESC", + "SELECT doc_id, doc_name, doc_description, doc_type FROM documents WHERE collection_name = ? ORDER BY created_at DESC, doc_id ASC", (collection,), ).fetchall() return [{"doc_id": r[0], "doc_name": r[1], "doc_description": r[2] or "", "doc_type": r[3]} for r in rows]