dashVectorSpace / src /active_learning.py
justmotes's picture
Deploy dashVectorspace v1 (Full)
b92d96d
raw
history blame
1.13 kB
import json
import os
from datetime import datetime
from typing import List, Any
from config import ACTIVE_LEARNING_LOG
def log_for_retraining(query: str, confidence: float, results: List[Any]):
"""
Logs queries that have low confidence or zero results for active learning (retraining).
Logic:
- If confidence < 0.6 OR len(results) == 0:
Append to logs/active_learning_queue.jsonl
"""
should_log = False
reason = []
if confidence < 0.6:
should_log = True
reason.append("low_confidence")
if len(results) == 0:
should_log = True
reason.append("zero_results")
if should_log:
entry = {
"timestamp": datetime.now().isoformat(),
"query": query,
"confidence": float(confidence),
"result_count": len(results),
"reasons": reason
}
try:
with open(ACTIVE_LEARNING_LOG, "a") as f:
f.write(json.dumps(entry) + "\n")
except Exception as e:
print(f"Error logging for active learning: {e}")