Skip to content

Commit afe5654

Browse files
committed
Improve query logging
1 parent 27a1c83 commit afe5654

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

stacks/opensearch-rag/opensearch-rag.ipynb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,12 @@
452452
" \n",
453453
" # Log the query if requested (with truncated vector for readability)\n",
454454
" if log_query:\n",
455-
" query_json = json.dumps(search_body, indent=2)\n",
456-
" # Replace full vector with truncated version: first 3 ... last 3\n",
457-
" vector_str = json.dumps(query_embedding)\n",
458-
" truncated = f\"[{query_embedding[0]:.4f}, {query_embedding[1]:.4f}, {query_embedding[2]:.4f}, \\\"... ({len(query_embedding)} dims) ...\\\", {query_embedding[-3]:.4f}, {query_embedding[-2]:.4f}, {query_embedding[-1]:.4f}]\"\n",
459-
" query_json = query_json.replace(vector_str, truncated)\n",
460-
" \n",
455+
" # Create display version with truncated vector\n",
456+
" log_body = json.loads(json.dumps(search_body)) # Deep copy\n",
457+
" vector = log_body['query']['knn']['embedding']['vector']\n",
458+
" log_body['query']['knn']['embedding']['vector'] = [vector[0], vector[1], vector[2], \"[...]\", vector[-3], vector[-2], vector[-1]]\n",
461459
" print(\"OpenSearch Query:\")\n",
462-
" print(query_json)\n",
460+
" print(json.dumps(log_body, indent=2))\n",
463461
" print()\n",
464462
" \n",
465463
" # Step 6: Execute search\n",

0 commit comments

Comments
 (0)