feat: ConnectAI structural hardening and retrieval precision improvements
This commit is contained in:
+35
-4
@@ -48,6 +48,27 @@ export class AgentDataValidator {
|
||||
|
||||
return { score, conflictRisk };
|
||||
}
|
||||
|
||||
/**
|
||||
* [New] 오류 발생 시 안전하게 데이터를 진단합니다 (에러를 던지지 않음).
|
||||
*/
|
||||
public static audit(stage: string, data: string): { score: number, conflictRisk: number, issues: string[] } {
|
||||
const issues: string[] = [];
|
||||
if (!data || data.trim().length === 0) {
|
||||
issues.push('데이터가 완전히 비어 있음');
|
||||
return { score: 0, conflictRisk: 100, issues };
|
||||
}
|
||||
|
||||
if (data.length < 50) issues.push('데이터 길이가 너무 짧음 (잠재적 누락)');
|
||||
|
||||
const score = QualityScorer.evaluate(data);
|
||||
const conflictRisk = ConflictDetector.analyzeSemanticDivergence(data);
|
||||
|
||||
if (score < 40) issues.push('품질 점수 매우 낮음');
|
||||
if (conflictRisk > 60) issues.push('심각한 지식 충돌 감지');
|
||||
|
||||
return { score, conflictRisk, issues };
|
||||
}
|
||||
}
|
||||
|
||||
export class QualityScorer {
|
||||
@@ -132,17 +153,27 @@ export class ConflictDetector {
|
||||
|
||||
for (const [pos, neg] of conflictTerms) {
|
||||
if (data.includes(pos) && data.includes(neg)) {
|
||||
// 두 상충 용어가 너무 가까운 거리(예: 200자 이내)에 있으면 충돌 확률 높음
|
||||
const posIdx = data.indexOf(pos);
|
||||
const negIdx = data.indexOf(neg);
|
||||
if (Math.abs(posIdx - negIdx) < 300) {
|
||||
if (Math.abs(posIdx - negIdx) < 400) {
|
||||
riskScore += 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 명시적 경고 태그 확인
|
||||
if (data.includes('[CONFLICT WARNING]')) riskScore += 30;
|
||||
// 3. 기술적 상충 (Technical Divergence)
|
||||
const technicalConflicts = [
|
||||
/동기(식)?.*비동기(식)?/g,
|
||||
/로컬.*클라우드/g,
|
||||
/정적.*동적/g,
|
||||
/Success.*Fail/i
|
||||
];
|
||||
for (const pattern of technicalConflicts) {
|
||||
if (pattern.test(data)) riskScore += 10;
|
||||
}
|
||||
|
||||
// 4. 명시적 경고 태그 확인
|
||||
if (data.includes('[CONFLICT WARNING]') || data.includes('[ERROR]')) riskScore += 30;
|
||||
|
||||
return Math.min(100, riskScore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user