...
This commit is contained in:
parent
dd1f961d57
commit
68a7a05961
@ -19,6 +19,7 @@ import dev.langchain4j.model.openai.OpenAiEmbeddingModel
|
||||
import dev.langchain4j.service.AiServices
|
||||
import dev.langchain4j.service.SystemMessage
|
||||
import dev.langchain4j.store.embedding.EmbeddingSearchRequest
|
||||
import dev.langchain4j.store.embedding.EmbeddingSearchResult
|
||||
import dev.langchain4j.store.embedding.filter.MetadataFilterBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
@ -298,20 +299,23 @@ object RagService {
|
||||
|
||||
val question = "$stockName 실적 및 향후 전망"
|
||||
val questionEmbedding = embeddingModel.embed(question).content()
|
||||
var finalSearchResult : EmbeddingSearchResult<TextSegment>? = null
|
||||
try {
|
||||
finalSearchResult = embeddingStore.search(
|
||||
EmbeddingSearchRequest.builder()
|
||||
.queryEmbedding(questionEmbedding)
|
||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||
.maxResults(10) // 최신 뉴스 3개 적정
|
||||
.minScore(0.2)
|
||||
.build()
|
||||
)
|
||||
} catch (e: Exception) {}
|
||||
|
||||
val finalSearchResult = embeddingStore.search(
|
||||
EmbeddingSearchRequest.builder()
|
||||
.queryEmbedding(questionEmbedding)
|
||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||
.maxResults(10) // 최신 뉴스 3개 적정
|
||||
.minScore(0.2)
|
||||
.build()
|
||||
)
|
||||
|
||||
// 3. 검색된 내용을 하나의 문자열로 합쳐서 전달
|
||||
tradingDecision.newsContext = finalSearchResult.matches().distinct() // 중복 제거
|
||||
.take(4) // 10개에서 4개로 축소
|
||||
.joinToString("\n\n") {
|
||||
tradingDecision.newsContext = finalSearchResult?.matches()?.distinct() // 중복 제거
|
||||
?.take(4) // 10개에서 4개로 축소
|
||||
?.joinToString("\n\n") {
|
||||
it.embedded().text()
|
||||
}
|
||||
|
||||
@ -336,20 +340,25 @@ object RagService {
|
||||
val questionEmbedding = embeddingModel.embed(question).content()
|
||||
|
||||
// 1. 벡터 DB에서 해당 종목의 뉴스 검색
|
||||
val searchResult = embeddingStore.search(
|
||||
EmbeddingSearchRequest.builder()
|
||||
.queryEmbedding(questionEmbedding)
|
||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||
.maxResults(10)
|
||||
.minScore(0.2)
|
||||
.build()
|
||||
)
|
||||
var searchResult : EmbeddingSearchResult<TextSegment>? = null
|
||||
try {
|
||||
searchResult = embeddingStore.search(
|
||||
EmbeddingSearchRequest.builder()
|
||||
.queryEmbedding(questionEmbedding)
|
||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||
.maxResults(10)
|
||||
.minScore(0.2)
|
||||
.build()
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
|
||||
// 2. 검색된 뉴스 중 1시간 이내(Very Recent) 데이터가 있는지 확인
|
||||
val hasHotNews = searchResult.matches().any { match ->
|
||||
val hasHotNews = searchResult?.matches()?.any { match ->
|
||||
val pubDate = match.embedded().metadata().getString("date")
|
||||
isVeryRecentNews(pubDate, maxHours = 1)
|
||||
}
|
||||
} ?: false
|
||||
|
||||
// 3. 최신 뉴스가 없다면 네이버 API 및 Playwright 스크래핑 가동
|
||||
if (!hasHotNews) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user