feat(meeting): ground AI transcript correction in learned vocabulary

AI polishing of a recorded or pasted transcript was a generic rewrite: it
cleaned fillers but left names and in-house terms mangled even when the app
already knew them. Polishing now corrects dictionary pronunciations and
typed identifiers deterministically before and after the model, and hands
the model the learned term list plus the user's own expressions with
explicit rules: rewrite a misheard name, product or in-house term to the
learned spelling, and never swap an ordinary noun or ending on similarity
alone. Dictation output is re-checked the same way after the model runs.
This commit is contained in:
Yun Chan 2026-11-06 17:22:54 +09:00
parent 1f5372bfcc
commit e2d17601a4
8 changed files with 120 additions and 23 deletions

View file

@ -95,6 +95,26 @@ const TRANSCRIPTION_FAILED_MESSAGE = 'Transcription failed during recording'
/** 자막 인식 실패를 렌더러에 다시 알리는 최소 간격 */
const CAPTION_FAILURE_NOTICE_INTERVAL_MS = 30_000
/**
* 전사 AI 교열(다듬기) 지시문.
*
* 사용자가 학습시킨 용어로 「잘못 들은 단어」를 반드시 고치게 하되, 근거 없는 일반 단어 교체는 금지한다.
* 한글 어절을 1자모 거리로 기계적으로 바꾸면 정상 문장이 망가지는 것을 실측했으므로(MTG-14),
* 단어 교체 판단은 문맥을 보는 모델에게 맡기고 근거(용어·표현 목록)를 함께 준다.
*/
const POLISH_TRANSCRIPT_PROMPT = [
'다음 음성 전사 텍스트를 회의록으로 다듬습니다.',
'',
'## 반드시 지킬 것',
'- 필러(음, 어, 그, 아, 뭐 등)·말 바꾸기(A 아니 A가 아니라 B → B)·불필요한 어절·의미 중복을 제거하세요.',
'- 아래 [사용자 용어]·[사용자가 자주 쓰는 용어]와 같은 이름·제품명·사내 용어가 전사에서 비슷하게 다르게 적혀 있고 문맥상 그것이 확실하면, **반드시 그 표기로 고치세요.**',
'- 이미 맞게 적힌 용어는 그대로 두세요.',
'- 반대로, 근거가 없는 일반 명사·부사·조사·어미는 절대 다른 단어로 바꾸지 마세요. 비슷하게 들린다는 이유만으로 단어를 바꾸면 문장이 망가집니다.',
'- 확실하지 않으면 원문을 그대로 두세요.',
'- 화자의 말투(반말/존댓말)와 의미·내용은 바꾸지 마세요. 타임스탬프 [MM:SS]와 화자 표기([화자 N] 등)는 그대로 유지하세요.',
'- [사용자가 실제로 쓰는 표현]은 말투·용어 참고용입니다. 그 문장을 그대로 옮겨 쓰지 마세요.',
].join('\n')
/**
* 회의 기능이 쓰는 LLM 포트 — 백엔드 선택(local/online, 폴백)은 LlmGateway 한 곳이 정한다.
* 문서 생성·요약 입력은 이 한도(프록시 메시지 한도) 안으로 맞춘다.
@ -1429,21 +1449,30 @@ class MeetingModeService extends EventEmitter {
if (!transcript) throw new D3ROError(ErrorCode.MeetingPolishFailed, '전사 텍스트가 없습니다')
const llm = await this._resolveMeetingLlm()
// 사용자가 학습시킨 용어·표현을 교열 지시에 넘긴다 — 예전엔 일반 프롬프트만 받아
// 고유명사·사내 용어가 매번 다르게 교정됐다.
const glossary = getTranscriptGlossaryService().promptSection()
// 1) 결정적 교정 먼저 — 사전 발음·학습 식별자는 LLM 없이도 확실히 고친다(모델이 놓쳐도 남는다).
const glossaryService = getTranscriptGlossaryService()
const preCorrected = glossaryService.correct(transcript)
if (preCorrected.corrections.length > 0) {
logger.info(`전사 교열: 학습 어휘로 ${preCorrected.corrections.length}건 먼저 교정`)
}
// 2) 사용자가 학습시킨 용어·표현을 교열 지시에 넘긴다 — 고유명사·사내 용어를 문맥으로 판단해
// 반드시 학습 표기로 고치되, 근거 없는 일반 단어는 바꾸지 말라고 명시한다.
const glossary = glossaryService.promptSection()
const polished = await this._rewriteTranscriptInChunks(
llm,
transcript,
'다음 음성 전사 텍스트를 다듬어주세요. 필러 단어(음, 어, 그, 아, 뭐 등), 말 바꾸기(A 아니 A가 아니라 B → B), 불필요한 어절·의미 중복을 제거하고 문장 구조를 자연스럽게 교정하되, 화자의 원래 말투(반말/존댓말)와 의미·내용은 절대 변경하지 마세요. 타임스탬프 형식 [MM:SS]과 화자 표기([화자 N] 등)는 그대로 유지하세요.' +
(glossary ? `\n\n${glossary}` : ''),
preCorrected.text,
POLISH_TRANSCRIPT_PROMPT + (glossary ? `\n\n${glossary}` : ''),
ErrorCode.MeetingPolishFailed,
)
this._writeRewrite(sessionId, polished, base, ErrorCode.MeetingPolishFailed)
// 3) 모델이 용어를 다른 표기로 되돌렸을 수 있다 — 정본 표기를 마지막에 다시 강제한다.
const finalText = glossaryService.correct(polished).text
this._writeRewrite(sessionId, finalText, base, ErrorCode.MeetingPolishFailed)
logger.info(`Auto Polish 완료: sessionId=${sessionId}`)
return polished
return finalText
}
/**

View file

@ -1068,8 +1068,9 @@ class VoiceModeService extends EventEmitter {
const { getChainService } = await import('./ChainService')
const chainResult = await getChainService().execute(route.chainId, userText)
if (!this._isCurrent(run)) return
if (this._session) this._session.processedText = chainResult.finalText
await this._completeSession(run, chainResult.finalText)
const learnedChain = getTranscriptGlossaryService().correct(chainResult.finalText).text
if (this._session) this._session.processedText = learnedChain
await this._completeSession(run, learnedChain)
} catch (error) {
if (!this._isCurrent(run)) return
logger.warn(`Chain execution failed: ${describe(error)}`)
@ -1090,11 +1091,14 @@ class VoiceModeService extends EventEmitter {
if (!this._isCurrent(run)) return
// 모델이 고유명사·식별자를 다른 표기로 바꿔 놓았을 수 있다 — 학습 표기를 마지막에 다시 강제한다.
const learnedText = getTranscriptGlossaryService().correct(processedText).text
if (this._session) {
this._session.processedText = processedText
this._session.processedText = learnedText
}
await this._completeSession(run, processedText)
await this._completeSession(run, learnedText)
} catch (error) {
if (!this._isCurrent(run)) return
this._handleError(

View file

@ -4,6 +4,7 @@ import { getMeetingModeService } from '../../src/main/services/MeetingModeServic
import { getDatabase } from '../../src/main/db'
import { meetingSessions } from '../../src/main/db/schema'
import { configSet } from '../../src/main/services/ConfigService'
import { getDictionaryService } from '../../src/main/services/DictionaryService'
import { useRedHarness } from './harness'
import { FX, USER_TEXT } from './fixtures'
@ -81,6 +82,21 @@ describe('유스케이스: 회의 문서/폴리시가 로컬 LLM 을 탄다', ()
expect(premiumGenerate).not.toHaveBeenCalled()
})
it('polish 는 모델이 되돌린 사전 표기를 학습 표기로 다시 강제한다', async () => {
configSet('llmBackend', 'local')
getDictionaryService().add({ word: 'D3RO', pronunciation: '디에로' })
insertSession('meet-polish-dict')
localGenerate.mockClear()
// 모델이 사전 표기를 무시하고 발음 그대로 돌려준 상황
localGenerate.mockResolvedValueOnce({ text: '[00:01] 디에로 보이스 설정 확인해 주세요', model: 'fx-local-model' })
const polished = await getMeetingModeService().polishTranscript('meet-polish-dict')
expect(polished).toBe('[00:01] D3RO 보이스 설정 확인해 주세요')
const systemPrompt = String(localGenerate.mock.calls.at(-1)?.[1]?.systemPrompt ?? '')
expect(systemPrompt).toContain('[사용자 용어')
expect(systemPrompt).toContain('D3RO')
})
it('없는 세션 polish 는 MeetingSessionNotFound 다', async () => {
configSet('llmBackend', 'local')
await expect(getMeetingModeService().polishTranscript('missing')).rejects.toMatchObject({