Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public class CreateChatbotResponseDto {
private String graphId;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime createdAt;
private List<String> retrievedChunks;
private List<String> sourceNodes;
private Map<String, String> ragMeta;
private List<String> retrievedTriples; //관계 μ€‘μ‹¬μ˜ 3μš”μ†Œ ν‘œν˜„ ("λ¬Ό -μƒνƒœλ³€ν™”β†’ 응고")
private List<String> sourceNodes; //μ§ˆμ˜μ— μ‚¬μš©λœ 핡심 λ…Έλ“œλ“€ ("λ¬Ό", "응고" λ“±)
private List<String> μ¦κ°•ν• λ•Œμ“΄μžλ£Œ; //LLM에 λ„˜κΈ΄ context λ¬Έμž₯λ“€ (이름은 `augmentedSentences` λ“±μœΌλ‘œ λ³€κ²½ ꢌμž₯)

private Map<String, String> ragMeta; //(ex: μ‚¬μš©ν•œ 쿼리문 λ“±)

public static CreateChatbotResponseDto of(
String chatContent,
Expand All @@ -30,7 +32,7 @@ public static CreateChatbotResponseDto of(
.chatContent(chatContent)
.graphId(graphId)
.createdAt(createdAt)
.retrievedChunks(retrievedChunks)
.retrievedTriples(retrievedChunks)
.sourceNodes(sourceNodes)
.ragMeta(Map.of("chunkCount", String.valueOf(retrievedChunks.size())))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public CreateChatbotResponseDto createAnswerWithRAG(String graphStrId, CreateCha
Long dbId = graphRepository.findDbIdByGraphId(Long.valueOf(graphStrId));
Graph graph = graphRepository.getByGraph(dbId);

// μƒˆλ‘œμš΄ μ±„νŒ…μΈ 경우
if (requestDto.isNewChat()) {
deletePreviousChat(dbId);
}

// μƒˆλ‘œμš΄ 질문 μΆ”κ°€
Chatting userChat = Chatting.builder()
.graph(graph)
.content(requestDto.getChatContent())
Expand All @@ -89,6 +91,7 @@ public CreateChatbotResponseDto createAnswerWithRAG(String graphStrId, CreateCha
.build();
chattingRepository.save(userChat);

// μ±„νŒ… λ‚΄μ—­ 쑰회
List<Chatting> chatHistory = chattingRepository.findAllByGraphId(dbId);

// RAG 응닡 생성 (응닡 + 메타 포함)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class GraphRAGService {
/**
* μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•΄ Cypher 쿼리 β†’ κ·Έλž˜ν”„ 정보 검색 β†’ ν”„λ‘¬ν”„νŠΈ 생성 β†’ LLM 응닡 생성
* λ³Έ λ©”μ„œλ“œλŠ” LangChain 없이 κ΅¬ν˜„ν•œ Spring 기반 GraphRAG의 핡심 νλ¦„μž…λ‹ˆλ‹€.
*
* private LocalDateTime createdAt;
* private List<String> retrievedTriples; //관계 μ€‘μ‹¬μ˜ 3μš”μ†Œ ν‘œν˜„ ("λ¬Ό -μƒνƒœλ³€ν™”β†’ 응고")
* private List<String> sourceNodes; //μ§ˆμ˜μ— μ‚¬μš©λœ 핡심 λ…Έλ“œλ“€ ("λ¬Ό", "응고" λ“±)
* private List<String> μ¦κ°•ν• λ•Œμ“΄μžλ£Œ; //LLM에 λ„˜κΈ΄ context λ¬Έμž₯λ“€ (이름은 `augmentedSentences` λ“±μœΌλ‘œ λ³€κ²½ ꢌμž₯)
* -> μ΄λ ‡κ²Œ κ²°κ³Ό λ‚˜μ˜€λ„λ‘ 정리
*/
public CreateChatbotResponseDto createAnswerWithGraphRAG(
Long dbId,
Expand Down Expand Up @@ -74,11 +80,20 @@ public CreateChatbotResponseDto createAnswerWithGraphRAG(
chattingRepository.save(answer);
log.info("[GraphRAG] Response saved to DB");

// μž„μ‹œ retrievedTriples μ„€μ •
List<String> retrievedTriples = List.of(
"(λ¬Ό)-[:RELATED {label: 'μƒνƒœλ³€ν™”'}]->(κΈ°ν™”)",
"(κΈ°ν™”)-[:RELATED {label: '쑰건'}]->(높은 μ˜¨λ„)",
"(수증기)-[:RELATED {label: '응결'}]->(물방울)",
"(λ¬Ό)-[:RELATED {label: '응고'}]->(μ–ΌμŒ)",
"(응고)-[:RELATED {label: 'μ˜ˆμ‹œ'}]->(겨울철 얼어뢙은 κΈΈ)"
);

return CreateChatbotResponseDto.of(
response,
dbId.toString(),
answer.getCreatedAt(),
contextChunks,
retrievedTriples,
sourceNodes
);
}
Expand Down