fix(rag): don't carry a query, upload or indexing run across an account switch
The chunk store reads whatever database is open at call time, so a query that was awaiting the model returned an answer built from the previous account's documents, and a large file being read was inserted into the new account's knowledge base and synced there. Each operation now remembers the account scope it started in and stops if it changed.
This commit is contained in:
parent
3e6cfd1ba8
commit
6fef05a39f
2 changed files with 79 additions and 1 deletions
|
|
@ -453,3 +453,59 @@ describe('RAGService 색인 실행 겹침', () => {
|
|||
expect(h.store.getDocument(doc.id)?.indexed).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('RAGService 계정 전환', () => {
|
||||
it('질의 중에 계정이 바뀌면 이전 계정 문서로 만든 답을 돌려주지 않는다', async () => {
|
||||
let scope = 'user-a'
|
||||
let generated = 0
|
||||
const h = harness({
|
||||
accountScope: () => scope,
|
||||
answerer: () => ({
|
||||
generate: async () => {
|
||||
generated++
|
||||
scope = 'user-b'
|
||||
return { text: 'answer from user-a documents' }
|
||||
},
|
||||
}),
|
||||
})
|
||||
await h.service.addDocument(writeTemp('a.txt', LONG_TEXT))
|
||||
await settle()
|
||||
|
||||
await expect(h.service.query('planning')).rejects.toMatchObject({ code: ErrorCode.RAGQueryFailed })
|
||||
expect(generated).toBe(1)
|
||||
})
|
||||
|
||||
it('파일을 읽는 사이 계정이 바뀌면 새 계정 지식베이스에 문서를 넣지 않는다', async () => {
|
||||
let scope = 'user-a'
|
||||
const h = harness({
|
||||
accountScope: () => scope,
|
||||
readFile: async (filePath) => {
|
||||
scope = 'user-b'
|
||||
return fs.promises.readFile(filePath)
|
||||
},
|
||||
})
|
||||
|
||||
await expect(h.service.addDocument(writeTemp('a.txt', LONG_TEXT))).rejects.toMatchObject({
|
||||
code: ErrorCode.RAGIndexingFailed,
|
||||
})
|
||||
expect(h.store.listDocuments()).toEqual([])
|
||||
expect(h.pushed).toEqual([])
|
||||
})
|
||||
|
||||
it('색인 중에 계정이 바뀌면 남은 청크를 임베딩하지 않는다', async () => {
|
||||
let scope = 'user-a'
|
||||
const h = harness({ accountScope: () => scope })
|
||||
let release: () => void = () => undefined
|
||||
h.embedder.gate = new Promise<void>((r) => {
|
||||
release = r
|
||||
})
|
||||
await h.service.addDocument(writeTemp('a.txt', LONG_TEXT))
|
||||
await settle()
|
||||
scope = 'user-b'
|
||||
h.embedder.gate = null
|
||||
release()
|
||||
await settle()
|
||||
|
||||
expect(h.embedder.embedCalls).toBe(1)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue