Spaces:
Sleeping
Sleeping
Doanh Van Vu commited on
Commit ·
ff5d801
1
Parent(s): 6a14fa9
Enhance logging in PineconeService for query results and statistics
Browse files- Updated the logging mechanism in the PineconeService to provide detailed information about each mentor result, including metadata when available.
- Added statistics logging for score metrics (min, max, avg) after query completion to improve performance monitoring and analysis.
- services/pinecone_service.py +31 -3
services/pinecone_service.py
CHANGED
|
@@ -120,14 +120,42 @@ class PineconeService:
|
|
| 120 |
query_time = time.perf_counter() - start_time
|
| 121 |
|
| 122 |
results = []
|
| 123 |
-
for match in query_response.matches:
|
| 124 |
-
|
| 125 |
"mentor_id": match.id,
|
| 126 |
"score": match.score,
|
| 127 |
"metadata": match.metadata if include_metadata else None
|
| 128 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
logger.info(f"[PINECONE] Query completed in {query_time:.3f}s: found {len(results)} results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
return results
|
| 132 |
except Exception as e:
|
| 133 |
logger.error(f"[PINECONE] Failed to query similar mentors: {str(e)}", exc_info=True)
|
|
|
|
| 120 |
query_time = time.perf_counter() - start_time
|
| 121 |
|
| 122 |
results = []
|
| 123 |
+
for idx, match in enumerate(query_response.matches, 1):
|
| 124 |
+
mentor_data = {
|
| 125 |
"mentor_id": match.id,
|
| 126 |
"score": match.score,
|
| 127 |
"metadata": match.metadata if include_metadata else None
|
| 128 |
+
}
|
| 129 |
+
results.append(mentor_data)
|
| 130 |
+
|
| 131 |
+
if include_metadata and match.metadata:
|
| 132 |
+
metadata = match.metadata
|
| 133 |
+
logger.info(
|
| 134 |
+
f"[PINECONE] Result #{idx}: mentor_id={match.id}, "
|
| 135 |
+
f"score={match.score:.4f}, "
|
| 136 |
+
f"rating={metadata.get('rating', 'N/A')}, "
|
| 137 |
+
f"total_ratings={metadata.get('total_ratings', 0)}, "
|
| 138 |
+
f"available_slots={metadata.get('available_slots', 0)}, "
|
| 139 |
+
f"session_count={metadata.get('session_count', 0)}, "
|
| 140 |
+
f"has_availability={metadata.get('has_availability', False)}, "
|
| 141 |
+
f"status={metadata.get('status', 'N/A')}, "
|
| 142 |
+
f"career_id={metadata.get('career_id', 'N/A')}, "
|
| 143 |
+
f"skill_ids={metadata.get('skill_ids', [])}, "
|
| 144 |
+
f"domain_ids={metadata.get('domain_ids', [])}, "
|
| 145 |
+
f"has_mentor_text={'mentor_text' in metadata}"
|
| 146 |
+
)
|
| 147 |
+
else:
|
| 148 |
+
logger.info(f"[PINECONE] Result #{idx}: mentor_id={match.id}, score={match.score:.4f}")
|
| 149 |
|
| 150 |
logger.info(f"[PINECONE] Query completed in {query_time:.3f}s: found {len(results)} results")
|
| 151 |
+
|
| 152 |
+
if results:
|
| 153 |
+
scores = [r["score"] for r in results]
|
| 154 |
+
logger.info(
|
| 155 |
+
f"[PINECONE] Score statistics: min={min(scores):.4f}, "
|
| 156 |
+
f"max={max(scores):.4f}, avg={sum(scores)/len(scores):.4f}"
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
return results
|
| 160 |
except Exception as e:
|
| 161 |
logger.error(f"[PINECONE] Failed to query similar mentors: {str(e)}", exc_info=True)
|