File size: 1,128 Bytes
b92d96d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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}")