Skip to content

Commit 49050b0

Browse files
authored
feat: 新增Graph RAG能力与知识图谱可视化功能 (#251)
* feat: integrate Graph RAG client and enhance knowledge base with RAG type support * feat: implement RAG management module with knowledge base and file models, and add processing endpoint * feat: enhance RAG service with background processing for unprocessed files and improve file handling logic * feat: update GraphRagClient API endpoint and enhance error handling in rag_service * feat: enhance knowledge base management with new types and custom entity support * feat: add query endpoint for knowledge graph and enhance RAG service with async processing * feat: enhance RAG service with async file processing and improve logging * feat: implement KnowledgeGraphView component and integrate knowledge graph fetching in detail view * feat: enhance KnowledgeGraphView with improved link handling and dynamic styling * feat: enhance KnowledgeGraphView with improved link handling and dynamic styling * feat: enhance KnowledgeGraphView with improved link handling and dynamic styling * feat: improve text rendering and dynamic distance calculation in KnowledgeGraphView * feat: improve text rendering and dynamic distance calculation in KnowledgeGraphView * feat: enhance lighting and dynamic distance calculation in KnowledgeGraphView
1 parent fdba441 commit 49050b0

29 files changed

Lines changed: 1450 additions & 52 deletions

File tree

backend/services/data-management-service/src/main/java/com/datamate/datamanagement/DataManagementServiceConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.datamate.datamanagement;
22

3-
import org.springframework.cloud.openfeign.EnableFeignClients;
43
import org.springframework.context.annotation.ComponentScan;
54
import org.springframework.context.annotation.Configuration;
65
import org.springframework.scheduling.annotation.EnableAsync;
@@ -10,7 +9,6 @@
109
* 数据管理服务配置类 - 多源接入、元数据、血缘治理
1110
*/
1211
@Configuration
13-
@EnableFeignClients(basePackages = "com.datamate.datamanagement.infrastructure.client")
1412
@EnableAsync
1513
@ComponentScan(basePackages = {
1614
"com.datamate.datamanagement",

backend/services/main-application/src/main/java/com/datamate/main/DataMateApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66
import org.springframework.cache.annotation.EnableCaching;
7+
import org.springframework.cloud.openfeign.EnableFeignClients;
78
import org.springframework.context.annotation.ComponentScan;
89
import org.springframework.scheduling.annotation.EnableAsync;
910
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -23,6 +24,7 @@
2324
@EnableAsync
2425
@EnableScheduling
2526
@EnableCaching
27+
@EnableFeignClients(basePackages = "com.datamate.*")
2628
public class DataMateApplication {
2729
public static void main(String[] args) {
2830
SpringApplication.run(DataMateApplication.class, args);

backend/services/rag-indexer-service/src/main/java/com/datamate/rag/indexer/domain/model/KnowledgeBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.baomidou.mybatisplus.annotation.TableName;
44
import com.datamate.common.domain.model.base.BaseEntity;
5+
import com.datamate.rag.indexer.interfaces.dto.RagType;
56
import lombok.Getter;
67
import lombok.Setter;
78

@@ -25,6 +26,11 @@ public class KnowledgeBase extends BaseEntity<String> {
2526
*/
2627
private String description;
2728

29+
/**
30+
* RAG 类型
31+
*/
32+
private RagType type;
33+
2834
/**
2935
* 嵌入模型
3036
*/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.datamate.rag.indexer.infrastructure.client;
2+
3+
import com.datamate.common.infrastructure.common.Response;
4+
import org.springframework.cloud.openfeign.FeignClient;
5+
import org.springframework.web.bind.annotation.PathVariable;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
8+
/**
9+
* 知识图谱RAG客户端
10+
*
11+
* @author dallas
12+
* @since 2026-01-15
13+
*/
14+
@FeignClient(name = "rag-service", url = "${collection.service.url:http://datamate-backend-python:18000}")
15+
public interface GraphRagClient {
16+
/**
17+
* 启动知识图谱RAG任务
18+
* @param knowledgeBaseId 知识库ID
19+
* @return 任务详情
20+
*/
21+
@PostMapping("/api/rag/process/{id}")
22+
Response<?> startGraphRagTask(@PathVariable("id") String knowledgeBaseId);
23+
}

backend/services/rag-indexer-service/src/main/java/com/datamate/rag/indexer/infrastructure/event/RagEtlService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import com.datamate.rag.indexer.domain.model.FileStatus;
99
import com.datamate.rag.indexer.domain.model.RagFile;
1010
import com.datamate.rag.indexer.domain.repository.RagFileRepository;
11+
import com.datamate.rag.indexer.infrastructure.client.GraphRagClient;
1112
import com.datamate.rag.indexer.infrastructure.milvus.MilvusService;
1213
import com.datamate.rag.indexer.interfaces.dto.AddFilesReq;
14+
import com.datamate.rag.indexer.interfaces.dto.RagType;
1315
import com.google.common.collect.Lists;
1416
import dev.langchain4j.data.document.Document;
1517
import dev.langchain4j.data.document.DocumentParser;
@@ -58,13 +60,20 @@ public class RagEtlService {
5860

5961
private final ModelConfigRepository modelConfigRepository;
6062

63+
private final GraphRagClient graphRagClient;
64+
6165
private final ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
6266

6367
@Async
6468
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
6569
public void processAfterCommit(DataInsertedEvent event) {
6670
// 执行 RAG 处理流水线
6771
List<RagFile> ragFiles = ragFileRepository.findNotSuccessByKnowledgeBaseId(event.knowledgeBase().getId());
72+
if (RagType.GRAPH.equals(event.knowledgeBase().getType())){
73+
log.info("Knowledge base {} is of type GRAPH. Skipping RAG ETL processing.", event.knowledgeBase().getName());
74+
graphRagClient.startGraphRagTask(event.knowledgeBase().getId());
75+
return;
76+
}
6877

6978
ragFiles.forEach(ragFile -> {
7079
try {

backend/services/rag-indexer-service/src/main/java/com/datamate/rag/indexer/interfaces/dto/KnowledgeBaseCreateReq.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class KnowledgeBaseCreateReq {
2828
@Size(max = 512, message = "知识库描述长度必须在 0 到 512 之间")
2929
private String description;
3030

31+
private RagType type = RagType.DOCUMENT;
32+
3133
/**
3234
* 嵌入模型
3335
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.datamate.rag.indexer.interfaces.dto;
2+
3+
/**
4+
* RAG 类型
5+
*
6+
* @author dallas
7+
* @since 2026-01-15
8+
*/
9+
public enum RagType {
10+
/**
11+
* 文档
12+
*/
13+
DOCUMENT,
14+
15+
/**
16+
* 知识图谱
17+
*/
18+
GRAPH,
19+
}

0 commit comments

Comments
 (0)