Этап 4 / Волна 16: добивка остаточных ошибок и устранение шаблонных ответов

This commit is contained in:
2026-03-28 16:23:41 +03:00
parent 014ff65188
commit 6123fafd5b
8 changed files with 787 additions and 51 deletions
+29 -13
View File
@@ -1078,7 +1078,7 @@ function isProblemUnitAlignedWithNarrativeDomain(unit, domain) {
if (accounts.some((item) => isVatAccountToken(item))) {
return true;
}
return /(vat|ндс|invoice|book_entry|register|книг|счет[\s-]?фактур|сч[её]т[\s-]?фактур)/i.test(corpus);
return /(vat|ндс|invoice|book_entry|register|книг|сч[её]т(?:а|у|ом|е)?[\s-]?фактур(?:а|ы|е|у|ой)?|вычет|налогов(?:ый|ого)?\s+эффект)/i.test(corpus);
}
if (domain === "month_close_costs_20_44") {
const foreignMonthCloseDomain = ["vat_flow", "bank_settlement", "customer_settlement", "fixed_asset"].includes(String(unit.lifecycle_domain ?? ""));
@@ -2030,11 +2030,11 @@ function hasStrongNarrativeDomainSignalInText(userMessage, domain) {
const accountTokens = extractAccountNumbersFromNarrativeText(text);
if (domain === "settlements_60_62") {
return (accountTokens.some((item) => isSettlementAccountToken(item)) ||
/(60\.0[12]|62\.0[12]|долг|аванс|зач[её]т|взаимозач|расч[её]т)/i.test(text));
/(60\.0[12]|62\.0[12]|долг|аванс|зач[её]т|взаимозач|расч[её]т|оплат|плат[её]ж|деньг[аи])/i.test(text));
}
if (domain === "vat_document_register_book") {
return (accountTokens.some((item) => isVatAccountToken(item)) ||
/(ндс|vat|счет[-\s]?фактур|сч[её]т[-\s]?фактур|книг[аи]|регистр)/i.test(text));
/(ндс|vat|сч[её]т(?:а|у|ом|е)?[-\s]?фактур(?:а|ы|е|у|ой)?|книг[аи]|регистр|вычет|налогов(?:ый|ого)?\s+эффект)/i.test(text));
}
if (domain === "month_close_costs_20_44") {
return (accountTokens.some((item) => isCloseCostsAccountToken(item)) ||
@@ -2401,7 +2401,7 @@ function buildProblemCentricAnswerStructure(input) {
}
function limitationReasonToUserText(code) {
if (code === "snapshot_only")
return "Вывод сделан по snapshot и может не включать самые свежие изменения.";
return "Оценка построена на snapshot-срезе и может не включать самые свежие изменения.";
if (code === "heuristic_inference")
return "Часть вывода построена эвристически и требует проверки в базе.";
if (code === "missing_mechanism")
@@ -2430,7 +2430,10 @@ function inferNarrativeDomainFromText(value) {
if (/(долг|аванс|взаимозач|зачет|зачёт|62\.01|62\.02|60\.01|60\.02|не\s+сход)/i.test(text)) {
settlementScore += 2;
}
if (/(ндс|vat|счет[-\s]?фактур|сч[её]т[-\s]?фактур|книг[аи]|регистр)/i.test(text)) {
if (/(расч[её]т|оплат|плат[её]ж|деньг[аи]|закрыти[ея]\s+расч)/i.test(text)) {
settlementScore += 2;
}
if (/(ндс|vat|сч[её]т(?:а|у|ом|е)?[-\s]?фактур(?:а|ы|е|у|ой)?|книг[аи]|регистр|вычет|налогов(?:ый|ого)?\s+эффект)/i.test(text)) {
vatScore += 3;
}
if (/(закрыти[ея]\s+месяц|закрытие\s+счетов|регламентн|косвенн|затрат|распределени|рбп|амортиз|финансовых\s+результат|month\s*close|period\s*close|close\s+operation)/i.test(text)) {
@@ -2595,8 +2598,8 @@ function buildEvidenceSectionLines(structure, questionType = "unknown") {
function buildDefaultChecksByDomain(domain) {
if (domain === "settlements_60_62") {
return [
"Проверьте договор, объект расчетов, регистр расчетов и документ закрытия (зачет аванса или взаимозачет).",
"Сверьте связку платеж -> расчетный документ -> проводки по 60/62/76 и подтверждение закрытия хвоста."
"Сверьте договор и объект расчетов, затем подтвердите запись в регистре расчетов и документ зачета.",
"Проверьте связку платеж -> расчетный документ -> проводки по 60/62/76 и факт закрытия хвоста."
];
}
if (domain === "vat_document_register_book") {
@@ -2753,11 +2756,12 @@ function buildChecksSectionLines(structure, context) {
lines.push(...domainFallback.slice(0, 2));
lines.push(...actionLines.slice(0, 2));
}
else if (actionLines.length > 0) {
lines.push(...actionLines.slice(0, 2));
}
else {
lines.push(...domainFallback.slice(0, 2));
lines.push(...domainFallback.slice(0, 1));
lines.push(...actionLines.slice(0, 2));
if (lines.length < 2) {
lines.push(...domainFallback.slice(1, 2));
}
}
}
if (hasMissingPeriod) {
@@ -2795,7 +2799,7 @@ function humanizeLimitationToken(value) {
if (normalized === "settlement_primary_evidence_not_confirmed")
return "Опора по расчетному контуру не подтверждена: в приоритете были сигналы из смежных доменов.";
if (normalized.includes("snapshot"))
return "Вывод сделан по snapshot и может не включать часть цепочки.";
return "Оценка сделана на snapshot-срезе и может не включать часть цепочки.";
if (normalized.includes("heuristic"))
return "Часть вывода основана на эвристике.";
if (normalized.includes("weak_source_mapping"))
@@ -2823,7 +2827,7 @@ function humanizeLimitationToken(value) {
if (/weak mechanism evidence/i.test(raw))
return "Доказательность механизма слабая, нужен ручной контроль.";
if (/evidence is snapshot-only/i.test(raw))
return "Вывод сделан по snapshot и может не включать самые свежие изменения.";
return "Оценка сделана на snapshot-срезе и может не включать самые свежие изменения.";
if (/source-of-record/i.test(raw))
return "Часть цепочки нужно подтвердить в исходной учетной базе.";
if (/[a-z]/i.test(raw) && !/[а-яё]/iu.test(raw))
@@ -2881,6 +2885,18 @@ function buildQuestionTypeShortLine(context) {
if (context.questionType === "what_to_check_first") {
return `\u041a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 ${domainName}.`;
}
if (context.questionType === "why_breaks") {
if (context.focusDomain === "settlements_60_62") {
return "Наиболее вероятная причина: переход от оплаты к закрытию расчета подтвержден не полностью.";
}
if (context.focusDomain === "vat_document_register_book") {
return "Наиболее вероятная причина: переход документа НДС к регистру и книге подтвержден частично.";
}
if (context.focusDomain === "month_close_costs_20_44") {
return "Наиболее вероятная причина: цепочка распределения затрат и закрытия месяца подтверждена не полностью.";
}
return "Наиболее вероятный механизм проблемы подтвержден частично и требует первичной проверки.";
}
return null;
}
function buildQuestionTypeBrokenLine(context) {
+122 -13
View File
@@ -245,10 +245,11 @@ const P0_DOMAIN_CARDS = [
symptom_markers: [
/\bvat\b/i,
/\u043d\u0434\u0441/i,
/\u0441\u0447[её]т.?фактур/i,
/\u0441\u0447[её]т(?:а|у|ом|е)?.?фактур/i,
/\u043a\u043d\u0438\u0433[аи]\s+\u043f\u043e\u043a\u0443\u043f/i,
/\u043a\u043d\u0438\u0433[аи]\s+\u043f\u0440\u043e\u0434\u0430\u0436/i,
/\u0432\u044b\u0447\u0435\u0442/i
/\u0432\u044b\u0447\u0435\u0442/i,
/\u043d\u0430\u043b\u043e\u0433\u043e\u0432(?:\u044b\u0439|\u043e\u0433\u043e)?\s+\u044d\u0444\u0444\u0435\u043a\u0442/i
]
},
{
@@ -857,6 +858,35 @@ function collectDateLikeSpans(text) {
}
return spans;
}
function collectAmountLikeSpans(text) {
const spans = [];
const patterns = [
/\b\d{1,3}(?:[ \u00A0]\d{3})+(?:[.,]\d{2})?\b/g,
/\b\d+[.,]\d{2}\b/g
];
for (const pattern of patterns) {
let match = null;
while ((match = pattern.exec(text)) !== null) {
spans.push({
start: match.index,
end: match.index + match[0].length
});
}
}
return spans;
}
function collectPercentLikeSpans(text) {
const spans = [];
const pattern = /\b\d{1,3}(?:[.,]\d+)?\s*%/g;
let match = null;
while ((match = pattern.exec(text)) !== null) {
spans.push({
start: match.index,
end: match.index + match[0].length
});
}
return spans;
}
function intersectsSpan(start, end, spans) {
return spans.some((span) => start < span.end && end > span.start);
}
@@ -867,7 +897,11 @@ function hasAccountContextAround(text, start, end) {
}
function extractAccountScopeFromText(text) {
const lower = String(text ?? "").toLowerCase();
const dateSpans = collectDateLikeSpans(lower);
const blockedSpans = [
...collectDateLikeSpans(lower),
...collectAmountLikeSpans(lower),
...collectPercentLikeSpans(lower)
];
const accounts = [];
const pushAccount = (raw) => {
const prefix = String(raw ?? "").trim().match(/^(\d{2})/)?.[1];
@@ -912,7 +946,7 @@ function extractAccountScopeFromText(text) {
const token = suffixAnchorMatch[0];
const start = suffixAnchorMatch.index;
const end = start + token.length;
if (intersectsSpan(start, end, dateSpans)) {
if (intersectsSpan(start, end, blockedSpans)) {
continue;
}
pushAccount(token);
@@ -924,7 +958,7 @@ function extractAccountScopeFromText(text) {
const token = explicitMatch[0];
const start = explicitMatch.index;
const end = start + token.length;
if (intersectsSpan(start, end, dateSpans)) {
if (intersectsSpan(start, end, blockedSpans)) {
continue;
}
const prefix = token.match(/^(\d{2})/)?.[1];
@@ -1090,7 +1124,7 @@ function buildSemanticRetrievalProfile(fragmentText) {
pushMany(entityTypes, ["counterparty", "contract", "document", "posting"]);
pushMany(relationPatterns, ["payment_to_settlement", "contract_to_documents"]);
}
if (/РЅРґСЃ|ндс|vat|РєРЅРёРіР° РїРѕРєСѓРїРѕРє|РєРЅРёРіР° продаж|счет.?фактур|книг[аи]\s+покуп|книг[аи]\s+продаж|сч[её]т.?фактур/i.test(lower) ||
if (/РЅРґСЃ|ндс|vat|РєРЅРёРіР° РїРѕРєСѓРїРѕРє|РєРЅРёРіР° продаж|счет.?фактур|книг[аи]\s+покуп|книг[аи]\s+продаж|сч[её]т(?:а|у|ом|е)?[-\s]?фактур(?:а|ы|е|у|ой)?|вычет|налогов(?:ый|ого)?\s+эффект/i.test(lower) ||
hasVatAccountScope) {
pushMany(domainScope, ["vat", "taxes"]);
pushMany(documentTypes, ["invoice", "vat_document"]);
@@ -1207,12 +1241,24 @@ function cardResolutionScore(card, fragmentText, profile) {
if (hasExplicitAccountScope && accountMatches.length === 0) {
return 0;
}
const hasHardAnchor = accountMatches.length > 0 || markerHit;
const hasVatSoftAnchor = card.id === "vat_document_register_book" && hasStrongVatDomainSignal(fragmentText, profile);
const hasHardAnchor = accountMatches.length > 0 || markerHit || hasVatSoftAnchor;
if (!hasHardAnchor) {
return 0;
}
return accountMatches.length * 4 + domainMatches.length * 3 + (markerHit ? 2 : 0);
}
function hasStrongVatDomainSignal(fragmentText, profile) {
const text = String(fragmentText ?? "");
const hasVatLexicalAnchor = /(?:ндс|vat|сч[её]т(?:а|у|ом|е)?[-\s]?фактур(?:а|ы|е|у|ой)?|книг[аи]\s+(?:покуп|продаж)|вычет|налогов(?:ый|ого)?\s+эффект)/iu.test(text);
return (hasVatLexicalAnchor ||
profile.account_scope.some((account) => account === "19" || account === "68") ||
profile.domain_scope.some((domain) => domain === "vat" || domain === "taxes") ||
profile.relation_patterns.some((pattern) => ["invoice_to_vat", "register_to_book", "book_entry_generated", "deduction_posted"].includes(pattern)));
}
function hasStrongSettlementAccountSignal(profile) {
return profile.account_scope.some((account) => account === "51" || account === "60" || account === "62" || account === "76");
}
function resolveP0DomainCard(fragmentText, profile) {
const resolved = P0_DOMAIN_CARDS.map((card) => ({
card,
@@ -1225,6 +1271,11 @@ function resolveP0DomainCard(fragmentText, profile) {
}
const [first, second] = resolved;
if (second && second.score === first.score) {
const pair = new Set([first.card.id, second.card.id]);
const hasVatSettlementTie = pair.has("vat_document_register_book") && pair.has("settlements_60_62");
if (hasVatSettlementTie && hasStrongVatDomainSignal(fragmentText, profile) && !hasStrongSettlementAccountSignal(profile)) {
return resolved.find((item) => item.card.id === "vat_document_register_book") ?? null;
}
return null;
}
return first;
@@ -2823,7 +2874,39 @@ class AssistantDataLayer {
}
executeBatch(fragmentText, data) {
const semanticProfile = buildSemanticRetrievalProfile(fragmentText);
const source = [...data.problemCases, ...data.keyFields, ...data.docs];
const resolvedDomain = resolveP0DomainCard(fragmentText, semanticProfile);
const domainCard = resolvedDomain?.card ?? null;
const fallbackSources = ["problemCases", "keyFields", "docs"];
const sourceScope = domainCard
? uniqueStrings([...domainCard.allowed_evidence_sources.risk, ...domainCard.allowed_evidence_sources.canonical])
: fallbackSources;
const sourcePool = collectSourceRecords(data, sourceScope);
const strictForbidden = Boolean(domainCard);
let sourceGate = domainCard
? applyDomainPuritySourceGate(sourcePool, domainCard, semanticProfile, { strict_forbidden: strictForbidden })
: {
accepted: sourcePool.map((item) => ({
...item,
signals: inferRecordSignals(item.record),
purity: {
allowed: true,
account_match: true,
domain_match: true,
entity_match: true,
edge_match: true,
forbidden_domains: [],
cross_domain_overlap: []
}
})),
rejected_total: 0,
rejected_forbidden: 0
};
let sourceStrictFallbackUsed = false;
if (domainCard && strictForbidden && sourceGate.accepted.length === 0 && sourcePool.length > 0) {
sourceGate = applyDomainPuritySourceGate(sourcePool, domainCard, semanticProfile, { strict_forbidden: false });
sourceStrictFallbackUsed = true;
}
const source = sourceGate.accepted.map((item) => item.record);
const byEntity = new Map();
for (const record of source) {
byEntity.set(record.source_entity, (byEntity.get(record.source_entity) ?? 0) + 1);
@@ -2836,29 +2919,55 @@ class AssistantDataLayer {
entity,
records_count: count
}));
const puritySummary = {
enabled: Boolean(domainCard),
domain_card_id: domainCard?.id ?? null,
domain_card_title: domainCard?.title ?? null,
source_scope: sourceScope,
source_pool_records: sourcePool.length,
source_selection_allowed: sourceGate.accepted.length,
source_selection_rejected: sourceGate.rejected_total,
source_selection_rejected_forbidden: sourceGate.rejected_forbidden,
top1_pure: domainCard ? topOnePurityHolds(sourceGate.accepted) : true,
top3_pure: domainCard ? topThreePurityHolds(sourceGate.accepted) : true,
strict_forbidden_mode: strictForbidden,
strict_forbidden_fallback_source: sourceStrictFallbackUsed
};
return {
status: items.length > 0 ? "ok" : "empty",
result_type: "ranking",
items,
summary: {
checked_records: source.length,
checked_records: sourcePool.length,
ranked_entities: items.length,
query_subject: semanticProfile.query_subject,
semantic_profile: semanticProfile,
ranking_basis: semanticProfile.ranking_basis
ranking_basis: semanticProfile.ranking_basis,
domain_purity_guard: puritySummary
},
evidence: items.slice(0, 5).map((item) => ({
entity: item.entity,
records_count: item.records_count
})),
why_included: items.length > 0 ? ["Показаны сущности с максимальным количеством записей."] : [],
selection_reason: ["Ранжирование выполнено по records_count по убыванию."],
why_included: items.length > 0
? [
"Показаны сущности с максимальным количеством записей.",
domainCard ? `P0 domain purity enforced for ${domainCard.id}.` : "P0 domain purity was not enforced."
]
: [],
selection_reason: [
"Ранжирование выполнено по records_count по убыванию.",
domainCard ? `Domain gate source scope: ${sourceScope.join(", ")}.` : "Domain gate source scope not applied."
],
risk_factors: uniqueStrings(["entity_volume_spike", ...semanticProfile.anomaly_patterns]),
business_interpretation: [
"Top entities by volume highlight where lifecycle-focused review should start first."
],
confidence: "medium",
limitations: ["Ранжирование по объему не всегда эквивалентно бизнес-риску."],
limitations: [
"Ранжирование по объему не всегда эквивалентно бизнес-риску.",
domainCard ? "Domain purity guardrail может исключить cross-domain записи на batch-слое." : "Domain purity guardrail не применялся."
],
errors: []
};
}
@@ -64,11 +64,24 @@ function countRuleHits(text, rule) {
}
return hits;
}
function hasProofIntent(text) {
return /(?:\bprove\b|\bguess\b|доказан|доказано|доказуем|гипотез|догад|связан\s+ли|зач[её]л(?:ся|ось)\s+ли)/iu.test(text);
}
function hasExplicitChainSplitIntent(text) {
return /(?:какие(?:\s+\S+){0,4}\s+цепочк[аи]|which\s+chains?|complete\s+vs\s+incomplete|что\s+закрыто.*что\s+нет)/iu.test(text);
}
function hasGroundingIntent(text) {
return /(?:на\s+ч(?:е|ё)м[^?!.]{0,40}основан|чем\s+подтвержда|какие\s+основани|what\s+evidence|grounded\s+on|based\s+on)/iu.test(text);
}
function resolveQuestionType(input) {
const text = String(input ?? "").trim();
if (!text) {
return "unknown";
}
// Guard against collapsing proof-intent questions into chain classification.
if (hasProofIntent(text) && !hasExplicitChainSplitIntent(text) && !hasGroundingIntent(text)) {
return "prove_or_guess";
}
let bestType = "unknown";
let bestHits = 0;
let bestPriority = Number.POSITIVE_INFINITY;