mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-13 03:45:14 +00:00
fix(billing): 当 knowledge.graph.enabled=false 时:所有知识图谱相关的 Bean 都不会被创建Neo4j 配置不会被加载即使没有配置 Neo4j 连接信息,默认禁用了知识图谱功能
This commit is contained in:
@@ -16,7 +16,7 @@ spring:
|
|||||||
master:
|
master:
|
||||||
type: ${spring.datasource.type}
|
type: ${spring.datasource.type}
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/ruoyi-ai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
|
url: jdbc:mysql://117.72.192.162:2369/ruoyi-ai2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
|
|
||||||
@@ -44,12 +44,13 @@ spring:
|
|||||||
spring.data:
|
spring.data:
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: 127.0.0.1
|
host: 117.72.192.162
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6380
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 2
|
database: 2
|
||||||
# 密码(如没有密码请注释掉)
|
# 密码(如没有密码请注释掉)
|
||||||
|
password: wt123
|
||||||
# password: 123456
|
# password: 123456
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10S
|
timeout: 10S
|
||||||
@@ -114,54 +115,5 @@ local:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- # Neo4j 知识图谱配置
|
|
||||||
neo4j:
|
|
||||||
uri: bolt://127.0.0.1:7687
|
|
||||||
username: neo4j
|
|
||||||
password: MySecurePass123!
|
|
||||||
database: neo4j
|
|
||||||
max-connection-pool-size: 50
|
|
||||||
connection-timeout-seconds: 30
|
|
||||||
|
|
||||||
# 知识图谱配置
|
|
||||||
knowledge:
|
|
||||||
graph:
|
|
||||||
# 是否启用知识图谱功能
|
|
||||||
enabled: true
|
|
||||||
# 图数据库类型: neo4j 或 apache-age
|
|
||||||
database-type: neo4j
|
|
||||||
# 是否自动创建索引
|
|
||||||
auto-create-index: true
|
|
||||||
# 批量处理大小
|
|
||||||
batch-size: 1000
|
|
||||||
# 最大重试次数
|
|
||||||
max-retry-count: 3
|
|
||||||
|
|
||||||
# 实体抽取配置
|
|
||||||
extraction:
|
|
||||||
# 置信度阈值(低于此值的实体将被过滤)
|
|
||||||
confidence-threshold: 0.7
|
|
||||||
# 最大实体数量(每个文档)
|
|
||||||
max-entities-per-doc: 100
|
|
||||||
# 最大关系数量(每个文档)
|
|
||||||
max-relations-per-doc: 200
|
|
||||||
# 文本分片大小(用于长文档)
|
|
||||||
chunk-size: 2000
|
|
||||||
# 分片重叠大小
|
|
||||||
chunk-overlap: 200
|
|
||||||
|
|
||||||
# 查询配置
|
|
||||||
query:
|
|
||||||
# 默认查询限制数量
|
|
||||||
default-limit: 100
|
|
||||||
# 最大查询限制数量
|
|
||||||
max-limit: 1000
|
|
||||||
# 路径查询最大深度
|
|
||||||
max-path-depth: 5
|
|
||||||
# 查询超时时间(秒)
|
|
||||||
timeout-seconds: 30
|
|
||||||
# 是否启用查询缓存
|
|
||||||
cache-enabled: true
|
|
||||||
# 缓存过期时间(分钟)
|
|
||||||
cache-expire-minutes: 60
|
|
||||||
|
|
||||||
|
|||||||
@@ -303,6 +303,10 @@ management:
|
|||||||
show-details: ALWAYS
|
show-details: ALWAYS
|
||||||
logfile:
|
logfile:
|
||||||
external-file: ./logs/sys-console.log
|
external-file: ./logs/sys-console.log
|
||||||
|
health:
|
||||||
|
# 禁用 Neo4j 健康检查(当知识图谱功能未启用时)
|
||||||
|
neo4j:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
# websocket
|
# websocket
|
||||||
# websocket
|
# websocket
|
||||||
@@ -346,3 +350,55 @@ vector-store:
|
|||||||
url: http://localhost:19530
|
url: http://localhost:19530
|
||||||
collectionname: LocalKnowledge
|
collectionname: LocalKnowledge
|
||||||
|
|
||||||
|
|
||||||
|
--- # Neo4j 知识图谱配置
|
||||||
|
#neo4j:
|
||||||
|
# uri: bolt://117.72.192.162:7687
|
||||||
|
# username: neo4j
|
||||||
|
# password: MySecurePass123!
|
||||||
|
# database: neo4j
|
||||||
|
# max-connection-pool-size: 50
|
||||||
|
# connection-timeout-seconds: 30
|
||||||
|
|
||||||
|
# 知识图谱配置
|
||||||
|
knowledge:
|
||||||
|
graph:
|
||||||
|
# 是否启用知识图谱功能
|
||||||
|
enabled: false
|
||||||
|
# 图数据库类型: neo4j 或 apache-age
|
||||||
|
database-type: neo4j
|
||||||
|
# 是否自动创建索引
|
||||||
|
auto-create-index: true
|
||||||
|
# 批量处理大小
|
||||||
|
batch-size: 1000
|
||||||
|
# 最大重试次数
|
||||||
|
max-retry-count: 3
|
||||||
|
|
||||||
|
# 实体抽取配置
|
||||||
|
extraction:
|
||||||
|
# 置信度阈值(低于此值的实体将被过滤)
|
||||||
|
confidence-threshold: 0.7
|
||||||
|
# 最大实体数量(每个文档)
|
||||||
|
max-entities-per-doc: 100
|
||||||
|
# 最大关系数量(每个文档)
|
||||||
|
max-relations-per-doc: 200
|
||||||
|
# 文本分片大小(用于长文档)
|
||||||
|
chunk-size: 2000
|
||||||
|
# 分片重叠大小
|
||||||
|
chunk-overlap: 200
|
||||||
|
|
||||||
|
# 查询配置
|
||||||
|
query:
|
||||||
|
# 默认查询限制数量
|
||||||
|
default-limit: 100
|
||||||
|
# 最大查询限制数量
|
||||||
|
max-limit: 1000
|
||||||
|
# 路径查询最大深度
|
||||||
|
max-path-depth: 5
|
||||||
|
# 查询超时时间(秒)
|
||||||
|
timeout-seconds: 30
|
||||||
|
# 是否启用查询缓存
|
||||||
|
cache-enabled: true
|
||||||
|
# 缓存过期时间(分钟)
|
||||||
|
cache-expire-minutes: 60
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.ruoyi.graph.config;
|
package org.ruoyi.graph.config;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
@@ -18,6 +19,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphAsyncConfig {
|
public class GraphAsyncConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lombok.Data;
|
|||||||
import org.neo4j.driver.AuthTokens;
|
import org.neo4j.driver.AuthTokens;
|
||||||
import org.neo4j.driver.Driver;
|
import org.neo4j.driver.Driver;
|
||||||
import org.neo4j.driver.GraphDatabase;
|
import org.neo4j.driver.GraphDatabase;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -16,6 +17,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
@ConfigurationProperties(prefix = "neo4j")
|
@ConfigurationProperties(prefix = "neo4j")
|
||||||
public class Neo4jConfig {
|
public class Neo4jConfig {
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.ruoyi.graph.domain.GraphInstance;
|
|||||||
import org.ruoyi.graph.enums.GraphStatusEnum;
|
import org.ruoyi.graph.enums.GraphStatusEnum;
|
||||||
import org.ruoyi.graph.service.IGraphBuildTaskService;
|
import org.ruoyi.graph.service.IGraphBuildTaskService;
|
||||||
import org.ruoyi.graph.service.IGraphInstanceService;
|
import org.ruoyi.graph.service.IGraphInstanceService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ import java.util.Map;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/graph/instance")
|
@RequestMapping("/graph/instance")
|
||||||
@Tag(name = "图谱实例管理", description = "知识图谱实例的创建、查询、更新、删除")
|
@Tag(name = "图谱实例管理", description = "知识图谱实例的创建、查询、更新、删除")
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphInstanceController extends BaseController {
|
public class GraphInstanceController extends BaseController {
|
||||||
|
|
||||||
private final IGraphInstanceService graphInstanceService;
|
private final IGraphInstanceService graphInstanceService;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.ruoyi.graph.dto.GraphExtractionResult;
|
|||||||
import org.ruoyi.graph.service.IGraphExtractionService;
|
import org.ruoyi.graph.service.IGraphExtractionService;
|
||||||
import org.ruoyi.graph.service.IGraphRAGService;
|
import org.ruoyi.graph.service.IGraphRAGService;
|
||||||
import org.ruoyi.graph.service.IGraphStoreService;
|
import org.ruoyi.graph.service.IGraphStoreService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ import java.util.Map;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/graph/query")
|
@RequestMapping("/graph/query")
|
||||||
@Tag(name = "图谱查询", description = "知识图谱查询相关接口")
|
@Tag(name = "图谱查询", description = "知识图谱查询相关接口")
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphQueryController extends BaseController {
|
public class GraphQueryController extends BaseController {
|
||||||
|
|
||||||
private final IGraphStoreService graphStoreService;
|
private final IGraphStoreService graphStoreService;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.ruoyi.graph.service.IGraphBuildTaskService;
|
|||||||
import org.ruoyi.graph.service.IGraphInstanceService;
|
import org.ruoyi.graph.service.IGraphInstanceService;
|
||||||
import org.ruoyi.graph.service.IGraphRAGService;
|
import org.ruoyi.graph.service.IGraphRAGService;
|
||||||
import org.ruoyi.service.IKnowledgeAttachService;
|
import org.ruoyi.service.IKnowledgeAttachService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -36,6 +37,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphBuildTaskServiceImpl implements IGraphBuildTaskService {
|
public class GraphBuildTaskServiceImpl implements IGraphBuildTaskService {
|
||||||
|
|
||||||
private final GraphBuildTaskMapper taskMapper;
|
private final GraphBuildTaskMapper taskMapper;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.ruoyi.graph.prompt.GraphExtractPrompt;
|
|||||||
import org.ruoyi.graph.service.IGraphExtractionService;
|
import org.ruoyi.graph.service.IGraphExtractionService;
|
||||||
import org.ruoyi.graph.service.llm.IGraphLLMService;
|
import org.ruoyi.graph.service.llm.IGraphLLMService;
|
||||||
import org.ruoyi.service.IChatModelService;
|
import org.ruoyi.service.IChatModelService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -31,6 +32,7 @@ import java.util.regex.Pattern;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphExtractionServiceImpl implements IGraphExtractionService {
|
public class GraphExtractionServiceImpl implements IGraphExtractionService {
|
||||||
|
|
||||||
private final IChatModelService chatModelService;
|
private final IChatModelService chatModelService;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.ruoyi.graph.domain.GraphInstance;
|
|||||||
import org.ruoyi.graph.mapper.GraphInstanceMapper;
|
import org.ruoyi.graph.mapper.GraphInstanceMapper;
|
||||||
import org.ruoyi.graph.service.IGraphInstanceService;
|
import org.ruoyi.graph.service.IGraphInstanceService;
|
||||||
import org.ruoyi.graph.service.IGraphStoreService;
|
import org.ruoyi.graph.service.IGraphStoreService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ import java.util.Map;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphInstanceServiceImpl implements IGraphInstanceService {
|
public class GraphInstanceServiceImpl implements IGraphInstanceService {
|
||||||
|
|
||||||
private final GraphInstanceMapper graphInstanceMapper;
|
private final GraphInstanceMapper graphInstanceMapper;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.ruoyi.graph.dto.GraphExtractionResult;
|
|||||||
import org.ruoyi.graph.service.IGraphExtractionService;
|
import org.ruoyi.graph.service.IGraphExtractionService;
|
||||||
import org.ruoyi.graph.service.IGraphRAGService;
|
import org.ruoyi.graph.service.IGraphRAGService;
|
||||||
import org.ruoyi.graph.service.IGraphStoreService;
|
import org.ruoyi.graph.service.IGraphStoreService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -26,6 +27,7 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphRAGServiceImpl implements IGraphRAGService {
|
public class GraphRAGServiceImpl implements IGraphRAGService {
|
||||||
|
|
||||||
private final IGraphExtractionService graphExtractionService;
|
private final IGraphExtractionService graphExtractionService;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.ruoyi.graph.config.GraphProperties;
|
|||||||
import org.ruoyi.graph.domain.GraphEdge;
|
import org.ruoyi.graph.domain.GraphEdge;
|
||||||
import org.ruoyi.graph.domain.GraphVertex;
|
import org.ruoyi.graph.domain.GraphVertex;
|
||||||
import org.ruoyi.graph.service.IGraphStoreService;
|
import org.ruoyi.graph.service.IGraphStoreService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -30,6 +31,7 @@ import static org.neo4j.driver.Values.parameters;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class GraphStoreServiceImpl implements IGraphStoreService {
|
public class GraphStoreServiceImpl implements IGraphStoreService {
|
||||||
|
|
||||||
private final Driver neo4jDriver;
|
private final Driver neo4jDriver;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.neo4j.driver.Record;
|
|||||||
import org.neo4j.driver.Result;
|
import org.neo4j.driver.Result;
|
||||||
import org.neo4j.driver.Session;
|
import org.neo4j.driver.Session;
|
||||||
import org.neo4j.driver.types.Node;
|
import org.neo4j.driver.types.Node;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -21,6 +22,7 @@ import static org.neo4j.driver.Values.parameters;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ConditionalOnProperty(prefix = "knowledge.graph", name = "enabled", havingValue = "true")
|
||||||
public class Neo4jTestUtil {
|
public class Neo4jTestUtil {
|
||||||
|
|
||||||
private final Driver driver;
|
private final Driver driver;
|
||||||
|
|||||||
Reference in New Issue
Block a user