Skip to content

Commit dd089c4

Browse files
committed
Order ai_parse_document metadata first and use resolved path
1 parent c3e6091 commit dd089c4

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

databend_aiserver/udfs/docparse.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
from time import perf_counter, perf_counter_ns
3737

3838
from databend_aiserver.runtime import DeviceRequest, choose_device, get_runtime
39-
from databend_aiserver.stages.operator import load_stage_file, stage_file_suffix
39+
from databend_aiserver.stages.operator import (
40+
load_stage_file,
41+
stage_file_suffix,
42+
resolve_stage_subpath,
43+
)
4044
from databend_aiserver.config import DEFAULT_EMBED_MODEL, DEFAULT_CHUNK_SIZE
4145

4246
try:
@@ -234,22 +238,25 @@ def ai_parse_document(stage_location: StageLocation, path: str) -> Dict[str, Any
234238

235239
# Output shape:
236240
# { "chunks": [...], "metadata": {...}, "error_information": [...] }
241+
resolved_path = resolve_stage_subpath(stage_location, path)
242+
243+
# Keep metadata first for predictable JSON ordering.
237244
payload: Dict[str, Any] = {
238-
"chunks": pages,
239245
"metadata": {
240246
"chunk_count": chunk_count,
241-
"path": path,
242-
"filename": Path(path).name,
243-
"file_size": file_size if file_size is not None else 0,
247+
"chunk_size": DEFAULT_CHUNK_SIZE,
244248
"duration_ms": duration_ms,
249+
"file_size": file_size if file_size is not None else 0,
250+
"filename": Path(path).name,
251+
"path": resolved_path or path,
245252
"timings_ms": {
246253
"convert": (t_convert_end_ns - t_convert_start_ns) / 1_000_000.0,
247254
"chunk": (t_chunk_end_ns - t_convert_end_ns) / 1_000_000.0,
248255
"total": duration_ms,
249256
},
250-
"chunk_size": DEFAULT_CHUNK_SIZE,
251257
"version": 1,
252258
},
259+
"chunks": pages,
253260
}
254261
if fallback:
255262
payload["error_information"] = [

0 commit comments

Comments
 (0)