17
17
package ai.tock.bot.admin.model
18
18
19
19
import ai.tock.bot.admin.bot.rag.BotRAGConfiguration
20
+ import ai.tock.bot.admin.service.VectorStoreService
20
21
import ai.tock.genai.orchestratorcore.mappers.EMSettingMapper
21
22
import ai.tock.genai.orchestratorcore.mappers.LLMSettingMapper
22
23
import ai.tock.genai.orchestratorcore.models.Constants
23
24
import ai.tock.genai.orchestratorcore.models.em.EMSettingDTO
25
+ import ai.tock.genai.orchestratorcore.models.em.toDTO
24
26
import ai.tock.genai.orchestratorcore.models.llm.LLMSettingDTO
25
- import ai.tock.genai.orchestratorcore.utils.SecurityUtils
27
+ import ai.tock.genai.orchestratorcore.models.llm.toDTO
26
28
import org.litote.kmongo.newId
27
29
import org.litote.kmongo.toId
28
30
@@ -34,44 +36,54 @@ data class BotRAGConfigurationDTO(
34
36
val llmSetting : LLMSettingDTO ,
35
37
val emSetting : EMSettingDTO ,
36
38
val indexSessionId : String? = null ,
39
+ val indexName : String? = null ,
37
40
val noAnswerSentence : String ,
38
41
val noAnswerStoryId : String? = null ,
39
42
) {
40
43
constructor (configuration: BotRAGConfiguration ) : this (
41
- configuration._id .toString(),
42
- configuration.namespace,
43
- configuration.botId,
44
- configuration.enabled,
45
- LLMSettingMapper .toDTO(configuration.llmSetting),
46
- EMSettingMapper .toDTO(configuration.emSetting),
47
- configuration.indexSessionId,
48
- configuration.noAnswerSentence,
49
- configuration.noAnswerStoryId
44
+ id = configuration._id .toString(),
45
+ namespace = configuration.namespace,
46
+ botId = configuration.botId,
47
+ enabled = configuration.enabled,
48
+ llmSetting = configuration.llmSetting.toDTO(),
49
+ emSetting = configuration.emSetting.toDTO(),
50
+ indexSessionId = configuration.indexSessionId,
51
+ indexName = configuration.generateIndexName(),
52
+ noAnswerSentence = configuration.noAnswerSentence,
53
+ noAnswerStoryId = configuration.noAnswerStoryId
50
54
)
51
55
52
56
fun toBotRAGConfiguration (): BotRAGConfiguration =
53
57
BotRAGConfiguration (
54
- id?.toId() ? : newId(),
55
- namespace,
56
- botId,
57
- enabled,
58
- LLMSettingMapper .toEntity(
59
- namespace,
60
- botId,
61
- Constants .GEN_AI_RAG_QUESTION_ANSWERING ,
62
- llmSetting
58
+ _id = id?.toId() ? : newId(),
59
+ namespace = namespace ,
60
+ botId = botId ,
61
+ enabled = enabled ,
62
+ llmSetting = LLMSettingMapper .toEntity(
63
+ namespace = namespace ,
64
+ botId = botId ,
65
+ feature = Constants .GEN_AI_RAG_QUESTION_ANSWERING ,
66
+ dto = llmSetting
63
67
),
64
- EMSettingMapper .toEntity(
65
- namespace,
66
- botId,
67
- Constants .GEN_AI_RAG_EMBEDDING_QUESTION ,
68
- emSetting
68
+ emSetting = EMSettingMapper .toEntity(
69
+ namespace = namespace ,
70
+ botId = botId ,
71
+ feature = Constants .GEN_AI_RAG_EMBEDDING_QUESTION ,
72
+ dto = emSetting
69
73
),
70
74
indexSessionId = indexSessionId,
71
75
noAnswerSentence = noAnswerSentence,
72
76
noAnswerStoryId = noAnswerStoryId
73
77
)
74
78
}
75
79
80
+ private fun BotRAGConfiguration.generateIndexName (): String? {
81
+ return indexSessionId?.takeIf { it.isNotBlank() }?.let {
82
+ VectorStoreService .getVectorStoreConfiguration(namespace, botId, enabled = true )
83
+ ?.setting
84
+ ?.normalizeDocumentIndexName(namespace, botId, it)
85
+ }
86
+ }
87
+
76
88
77
89
0 commit comments