Files
MathApp/rag/services/config.py
Zareian 4839123698 remove dead RAG tutor module and stale config notes
rag/services/tutor.py
  - deleted: answer_question() had no callers (AskAIView calls
    retrieve_context + generate_answer directly) and carried an unused
    import.
rag/services/config.py
  - docstring: drop the claim that the lesson-filter key is settings-driven
    (it is auto-selected per subject in known_collections.py).
.env.example
  - drop the leftover note about the removed RAG_QDRANT_LESSON_FILTER_KEY.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-31 13:02:43 +03:30

45 lines
1.8 KiB
Python

"""
تنظیماتِ RAG و هم‌خوانیِ نامِ collection با دادهٔ موجودِ تیمِ دیگر.
در Rag_backend نامِ collection این‌طور ساخته می‌شه:
f"{subject.name} {subject.grade.title}".lower()
قالبِ نام و نگاشتِ گرید از settings قابلِ تنظیم‌ان چون اسمِ دقیقِ گرید حساسه
(کاربر قبلاً با اسمِ نادرست به مشکل خورده بود). کلیدِ فیلترِ درس/فصل خودکار
از روی subject انتخاب می‌شه — نگاه کنید به rag/services/known_collections.py.
"""
from django.conf import settings
def rag_is_configured() -> bool:
return bool(
settings.OPENAI_API_KEY
and settings.QDRANT_API_KEY
and not settings.RAG_FORCE_MOCK
)
def resolve_grade_title(grade_id, fallback: str = '') -> str:
"""gradeId → عنوانِ گرید همان‌طور که در نامِ collectionِ تیمِ دیگه اومده."""
overrides = getattr(settings, 'RAG_GRADE_TITLE_OVERRIDES', {}) or {}
if grade_id in overrides:
return str(overrides[grade_id])
if grade_id is not None:
try:
from content.models import Grade
grade = Grade.objects.filter(pk=grade_id).only('title').first()
if grade is not None:
return grade.title
except Exception:
pass
return fallback
def build_collection_name(subject: str, grade_title: str) -> str:
template = getattr(settings, 'RAG_COLLECTION_NAME_TEMPLATE', '{subject} {grade}')
return template.format(subject=(subject or '').strip(), grade=(grade_title or '').strip()).lower()
def retrieval_top_k() -> int:
return int(getattr(settings, 'RAG_RETRIEVAL_TOP_K', 4))