fix: exact full code match (28-01-067-11) + test_accuracy.py
- Regex: ищет полный код (XX-XX-XXX-XX) перед prefix match - Конкретная норма ставится ПЕРВОЙ в контексте LLM - test_accuracy.py: 20 итераций × 50 вопросов, русский текст Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -149,7 +149,11 @@ class SmetaAssistant:
|
||||
|
||||
# 1. Exact code match (always works, no API call)
|
||||
import re
|
||||
code_match = re.search(r'(\d{2}-\d{2}-\d{3})', query)
|
||||
# Match full code (28-01-067-11) or table prefix (28-01-067)
|
||||
full_match = re.search(r'(\d{2}-\d{2}-\d{3}-\d{2})', query)
|
||||
prefix_match = re.search(r'(\d{2}-\d{2}-\d{3})', query)
|
||||
code_match = prefix_match # for backward compat
|
||||
|
||||
if code_match:
|
||||
prefix = code_match.group(1)
|
||||
prefixes = [prefix]
|
||||
@@ -157,14 +161,27 @@ class SmetaAssistant:
|
||||
for delta in [-1, 1, -2, 2]:
|
||||
prefixes.append(f"{prefix[:6]}{table_num + delta:03d}")
|
||||
|
||||
# Exact match for the specific full code first
|
||||
if full_match:
|
||||
exact_code = full_match.group(1)
|
||||
specific = [n for n in search.norms if n["code"] == exact_code]
|
||||
if specific:
|
||||
n = specific[0]
|
||||
lines.append(f"\n\n## НОРМА ГЭСН {n['code']}:")
|
||||
lines.append(
|
||||
f"Название: {n['name']}. "
|
||||
f"Единица измерения: {n['unit']}."
|
||||
)
|
||||
|
||||
# Also show related norms from same table
|
||||
exact = [n for n in search.norms
|
||||
if any(n["code"].startswith(p) for p in prefixes)]
|
||||
if exact:
|
||||
lines.append("\n\n## НОРМЫ ГЭСН (по коду):")
|
||||
for n in exact[:10]:
|
||||
lines.append("\n\n## СВЯЗАННЫЕ НОРМЫ ГЭСН:")
|
||||
for n in exact[:8]:
|
||||
lines.append(
|
||||
f"- ГЭСН {n['code']}: {n['name']}. "
|
||||
f"Единица измерения: {n['unit']}."
|
||||
f"- ГЭСН {n['code']}: {n['name'][:60]}. "
|
||||
f"Ед.: {n['unit']}."
|
||||
)
|
||||
|
||||
# 2. Semantic search (may fail on API timeout — non-critical)
|
||||
|
||||
Reference in New Issue
Block a user