|
36 | 36 | from time import perf_counter, perf_counter_ns |
37 | 37 |
|
38 | 38 | 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 | +) |
40 | 44 | from databend_aiserver.config import DEFAULT_EMBED_MODEL, DEFAULT_CHUNK_SIZE |
41 | 45 |
|
42 | 46 | try: |
@@ -234,22 +238,25 @@ def ai_parse_document(stage_location: StageLocation, path: str) -> Dict[str, Any |
234 | 238 |
|
235 | 239 | # Output shape: |
236 | 240 | # { "chunks": [...], "metadata": {...}, "error_information": [...] } |
| 241 | + resolved_path = resolve_stage_subpath(stage_location, path) |
| 242 | + |
| 243 | + # Keep metadata first for predictable JSON ordering. |
237 | 244 | payload: Dict[str, Any] = { |
238 | | - "chunks": pages, |
239 | 245 | "metadata": { |
240 | 246 | "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, |
244 | 248 | "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, |
245 | 252 | "timings_ms": { |
246 | 253 | "convert": (t_convert_end_ns - t_convert_start_ns) / 1_000_000.0, |
247 | 254 | "chunk": (t_chunk_end_ns - t_convert_end_ns) / 1_000_000.0, |
248 | 255 | "total": duration_ms, |
249 | 256 | }, |
250 | | - "chunk_size": DEFAULT_CHUNK_SIZE, |
251 | 257 | "version": 1, |
252 | 258 | }, |
| 259 | + "chunks": pages, |
253 | 260 | } |
254 | 261 | if fallback: |
255 | 262 | payload["error_information"] = [ |
|
0 commit comments