File size: 1,511 Bytes
43e7de8 | 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 | from src.rag.context_grader import grade_context
from src.rag.retrieval_pipeline_simple import analyze_query
def test_context_grader_explicit_reference_requires_matching_metadata():
question = "Điểm a khoản 3 Điều 6 quy định gì?"
profile = analyze_query(question)
wrong_passages = [
{
"text": "Một quy định liên quan.",
"metadata": {"article": "Điều 5", "clause": "Khoản 3", "point": "Điểm a"},
}
]
assert grade_context(question, profile, wrong_passages)["status"] == "insufficient"
right_passages = [
{
"text": "Điểm a khoản 3 Điều 6 quy định về việc không chấp hành tín hiệu giao thông.",
"metadata": {"article": "Điều 6", "clause": "Khoản 3", "point": "Điểm a"},
}
]
assert grade_context(question, profile, right_passages)["status"] == "sufficient"
def test_context_grader_needs_reasoning_for_fault_question_with_relevant_rules():
question = "Xe A vượt đèn đỏ va chạm xe B, ai có lỗi?"
profile = analyze_query(question)
passages = [
{
"text": "Người điều khiển phương tiện phải chấp hành tín hiệu giao thông; không được vượt đèn đỏ.",
"metadata": {"article": "Điều 6"},
}
]
result = grade_context(question, profile, passages)
assert result["status"] == "needs_reasoning"
assert result["allow_reasoning"] is True
|