https://arxiv.org/abs/2606.28344. The end of web parsing. The beginning of scalable pixel-native search. link: https://pixelrag.ai/
feat(serve): distinguish search vs chat in query log via X-Source header (#127)
Yichuan Wang7a3c3041bd37
diff --git a/serve/src/pixelrag_serve/api.py b/serve/src/pixelrag_serve/api.pyindex 5a78c2d..9e9e2a6 100644--- a/serve/src/pixelrag_serve/api.py+++ b/serve/src/pixelrag_serve/api.py@@ -102,12 +102,13 @@ def _init_query_log():_query_log_path = log_dir / "queries.jsonl"-def _log_query(req: "SearchRequest", request_id: str):+def _log_query(req: "SearchRequest", request_id: str, source: str | None = None):if _query_log_path is None:returnrecord = {"ts": datetime.now(timezone.utc).isoformat(),"request_id": request_id,+ "source": source,"queries": [q.text for q in req.queries],"has_image": [q.image is not None for q in req.queries],"n_docs": req.n_docs,@@ -461,7 +462,7 @@ def _resolve_url(article_id: int) -> str:@app.post("/search", response_model=SearchResponse)-async def search(req: SearchRequest):+async def search(req: SearchRequest, request: Request):t0 = time.time()# Encode queries@@ -570,7 +571,7 @@ async def search(req: SearchRequest):time.time() - t0,)- _log_query(req, _request_id_ctx.get())+ _log_query(req, _request_id_ctx.get(), request.headers.get("X-Source"))return SearchResponse(results=results)diff --git a/web/agent-server.mjs b/web/agent-server.mjsindex 18f2507..e0c9c68 100644--- a/web/agent-server.mjs+++ b/web/agent-server.mjs@@ -98,7 +98,7 @@ function createTools(onEvent, uploadedImage) {onEvent("searching", { query: label })const resp = await fetch(`${SEARCH_URL}/search`, {method: "POST",- headers: { "Content-Type": "application/json" },+ headers: { "Content-Type": "application/json", "X-Source": "chat" },body: JSON.stringify({ queries: [queryObj], n_docs: args.n_results ?? 5, articles_only: true }),signal: AbortSignal.timeout(30000),})diff --git a/web/app/api/chat/route.ts b/web/app/api/chat/route.tsindex 80e131a..9c70e15 100644--- a/web/app/api/chat/route.ts+++ b/web/app/api/chat/route.ts@@ -99,7 +99,7 @@ function createTools(const resp = await fetch(`${SEARCH_URL}/search`, {method: "POST",- headers: { "Content-Type": "application/json" },+ headers: { "Content-Type": "application/json", "X-Source": "chat" },body: JSON.stringify({queries: [queryObj],n_docs: args.n_results ?? 5,diff --git a/web/lib/api.ts b/web/lib/api.tsindex f998ba5..0cedf03 100644--- a/web/lib/api.ts+++ b/web/lib/api.ts@@ -14,7 +14,7 @@ async function fetchApi<T>(path: string, init?: RequestInit): Promise<T> {export async function search(req: SearchRequest): Promise<SearchResponse> {return fetchApi<SearchResponse>("/search", {method: "POST",- headers: { "Content-Type": "application/json" },+ headers: { "Content-Type": "application/json", "X-Source": "search" },// NOTE: the visual grid intentionally does NOT set articles_only — the// Portal/Featured-picture pages it would drop are often the most visually// striking tiles (panoramas, paintings), which is the point of this view.