mirror of
https://gitee.com/270580156/weiyu.git
synced 2026-05-23 17:57:47 +00:00
update
This commit is contained in:
@@ -30,7 +30,7 @@ import com.bytedesk.kbase.article.elastic.ArticleElasticService;
|
||||
import com.bytedesk.kbase.article.vector.ArticleVectorService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.bytedesk.core.annotation.ActionAnnotation;
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.springframework.context.annotation.Description;
|
||||
@Tag(name = "文章管理", description = "文章管理相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/article")
|
||||
@AllArgsConstructor
|
||||
@Description("Article Management Controller - Knowledge base article content management APIs")
|
||||
public class ArticleRestController extends BaseRestController<ArticleRequest> {
|
||||
|
||||
@@ -52,7 +51,13 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
|
||||
|
||||
private final ArticleElasticService articleElasticService;
|
||||
|
||||
private final ArticleVectorService articleVectorService;
|
||||
@Autowired(required = false)
|
||||
private ArticleVectorService articleVectorService;
|
||||
|
||||
public ArticleRestController(ArticleRestService articleRestService, ArticleElasticService articleElasticService) {
|
||||
this.articleRestService = articleRestService;
|
||||
this.articleElasticService = articleElasticService;
|
||||
}
|
||||
|
||||
@Operation(summary = "查询组织下的文章", description = "根据组织ID查询文章列表")
|
||||
@ApiResponse(responseCode = "200", description = "查询成功",
|
||||
@@ -167,9 +172,12 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
|
||||
@PostMapping("/updateVectorIndex")
|
||||
public ResponseEntity<?> updateVectorIndex(@RequestBody ArticleRequest request) {
|
||||
|
||||
articleVectorService.updateVectorIndex(request);
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
|
||||
if (articleVectorService != null) {
|
||||
articleVectorService.updateVectorIndex(request);
|
||||
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
|
||||
} else {
|
||||
return ResponseEntity.ok(JsonResult.error("Vector service is not available"));
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新所有文章索引", description = "更新所有文章的Elasticsearch索引")
|
||||
@@ -189,9 +197,12 @@ public class ArticleRestController extends BaseRestController<ArticleRequest> {
|
||||
@PostMapping("/updateAllVectorIndex")
|
||||
public ResponseEntity<?> updateAllVectorIndex(@RequestBody ArticleRequest request) {
|
||||
|
||||
articleVectorService.updateAllVectorIndex(request);
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
|
||||
if (articleVectorService != null) {
|
||||
articleVectorService.updateAllVectorIndex(request);
|
||||
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
|
||||
} else {
|
||||
return ResponseEntity.ok(JsonResult.error("Vector service is not available"));
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "搜索文章", description = "输入联想搜索文章")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-03-22 22:59:07
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-30 10:06:45
|
||||
* @LastEditTime: 2025-08-08 17:28:50
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -30,13 +30,13 @@ import lombok.AllArgsConstructor;
|
||||
@Tag(name = "文章匿名管理", description = "文章匿名相关接口")
|
||||
public class ArticleRestControllerVisitor {
|
||||
|
||||
private final ArticleRestService articleService;
|
||||
private final ArticleRestService articleRestService;
|
||||
|
||||
@RequestMapping("/search")
|
||||
@Operation(summary = "搜索文章", description = "访客搜索文章")
|
||||
public ResponseEntity<?> searchKb(ArticleRequest request) {
|
||||
|
||||
Page<ArticleResponse> page = articleService.queryByOrg(request);
|
||||
Page<ArticleResponse> page = articleRestService.queryByOrg(request);
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success(page));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2025-05-31 18:10:00
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2025-05-31 18:10:00
|
||||
* @LastEditTime: 2025-08-08 17:36:41
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -23,8 +23,8 @@ import com.bytedesk.kbase.article.ArticleEntity;
|
||||
import com.bytedesk.kbase.article.ArticleRestService;
|
||||
import com.bytedesk.kbase.article.vector.ArticleVectorService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 文章索引消息监听器
|
||||
@@ -32,13 +32,17 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ArticleIndexMessageListener {
|
||||
|
||||
private final ArticleRestService articleRestService;
|
||||
private final ArticleVectorService articleVectorService;
|
||||
@Autowired(required = false)
|
||||
private ArticleVectorService articleVectorService;
|
||||
// private final ArticleElasticService articleElasticService;
|
||||
|
||||
public ArticleIndexMessageListener(ArticleRestService articleRestService) {
|
||||
this.articleRestService = articleRestService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听文章索引队列,处理索引和删除操作
|
||||
* 使用并发消费者提高吞吐量,但保持消息的顺序处理
|
||||
@@ -69,7 +73,7 @@ public class ArticleIndexMessageListener {
|
||||
log.info("处理文章删除索引: {}", article.getTitle());
|
||||
|
||||
// 删除向量索引
|
||||
if (message.getUpdateVectorIndex()) {
|
||||
if (message.getUpdateVectorIndex() && articleVectorService != null) {
|
||||
try {
|
||||
articleVectorService.deleteArticle(article);
|
||||
} catch (Exception e) {
|
||||
@@ -91,7 +95,7 @@ public class ArticleIndexMessageListener {
|
||||
log.info("处理文章创建/更新索引: {}", article.getTitle());
|
||||
|
||||
// 创建/更新向量索引
|
||||
if (message.getUpdateVectorIndex()) {
|
||||
if (message.getUpdateVectorIndex() && articleVectorService != null) {
|
||||
try {
|
||||
articleVectorService.indexVector(article);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2025-05-31 16:35:20
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2025-06-03 14:51:23
|
||||
* @LastEditTime: 2025-08-08 17:39:32
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -25,7 +25,7 @@ import com.bytedesk.kbase.article.ArticleRestService;
|
||||
import com.bytedesk.kbase.article.elastic.ArticleElasticService;
|
||||
import com.bytedesk.kbase.article.vector.ArticleVectorService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -34,14 +34,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ArticleMessageConsumer {
|
||||
|
||||
private final ArticleElasticService articleElasticService;
|
||||
private final ArticleRestService articleRestService;
|
||||
private final ArticleVectorService articleVectorService;
|
||||
@Autowired(required = false)
|
||||
private ArticleVectorService articleVectorService;
|
||||
private final Random random = new Random();
|
||||
|
||||
public ArticleMessageConsumer(ArticleElasticService articleElasticService, ArticleRestService articleRestService) {
|
||||
this.articleElasticService = articleElasticService;
|
||||
this.articleRestService = articleRestService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文章索引队列中的消息
|
||||
* 使用客户端确认模式,只有成功处理后才确认消息
|
||||
@@ -149,7 +154,7 @@ public class ArticleMessageConsumer {
|
||||
}
|
||||
|
||||
// 这里可以添加对向量索引的处理,如果需要
|
||||
if (message.getUpdateVectorIndex()) {
|
||||
if (message.getUpdateVectorIndex() && articleVectorService != null) {
|
||||
log.info("更新文章向量索引: {}", articleUid);
|
||||
// 如果有文章向量服务,在这里调用
|
||||
articleVectorService.indexVector(article);
|
||||
@@ -184,7 +189,7 @@ public class ArticleMessageConsumer {
|
||||
}
|
||||
|
||||
// 这里可以添加对向量索引删除的处理,如果需要
|
||||
if (message.getUpdateVectorIndex()) {
|
||||
if (message.getUpdateVectorIndex() && articleVectorService != null) {
|
||||
log.info("从向量引擎中删除文章索引: {}", articleUid);
|
||||
// 如果有文章向量服务,在这里调用
|
||||
boolean vectorDeleted = articleVectorService.deleteArticle(article);
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
/**
|
||||
* 文章向量检索服务
|
||||
@@ -44,6 +45,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
|
||||
public class ArticleVectorService {
|
||||
|
||||
private final ElasticsearchVectorStore vectorStore;
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.bytedesk.kbase.faq.vector.FaqVectorService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -40,14 +41,19 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@Tag(name = "常见问题管理", description = "常见问题管理相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/faq")
|
||||
@AllArgsConstructor
|
||||
public class FaqRestController extends BaseRestController<FaqRequest> {
|
||||
|
||||
private final FaqRestService faqRestService;
|
||||
|
||||
private final FaqElasticService faqElasticService;
|
||||
|
||||
private final FaqVectorService faqVectorService;
|
||||
@Autowired(required = false)
|
||||
private FaqVectorService faqVectorService;
|
||||
|
||||
public FaqRestController(FaqRestService faqRestService, FaqElasticService faqElasticService) {
|
||||
this.faqRestService = faqRestService;
|
||||
this.faqElasticService = faqElasticService;
|
||||
}
|
||||
|
||||
@Operation(summary = "查询组织下的常见问题", description = "根据组织ID查询常见问题列表")
|
||||
@ApiResponse(responseCode = "200", description = "查询成功",
|
||||
@@ -186,7 +192,9 @@ public class FaqRestController extends BaseRestController<FaqRequest> {
|
||||
@PostMapping("/updateVectorIndex")
|
||||
public ResponseEntity<?> updateVectorIndex(@RequestBody FaqRequest request) {
|
||||
|
||||
faqVectorService.updateVectorIndex(request);
|
||||
if (faqVectorService != null) {
|
||||
faqVectorService.updateVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
|
||||
}
|
||||
@@ -208,7 +216,9 @@ public class FaqRestController extends BaseRestController<FaqRequest> {
|
||||
@PostMapping("/updateAllVectorIndex")
|
||||
public ResponseEntity<?> updateAllVectorIndex(@RequestBody FaqRequest request) {
|
||||
|
||||
faqVectorService.updateAllVectorIndex(request);
|
||||
if (faqVectorService != null) {
|
||||
faqVectorService.updateAllVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getUid()));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.bytedesk.kbase.faq.elastic.FaqElasticService;
|
||||
import com.bytedesk.kbase.faq.vector.FaqVectorService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -34,14 +35,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class FaqIndexConsumer {
|
||||
|
||||
private final FaqElasticService faqElasticService;
|
||||
private final FaqVectorService faqVectorService;
|
||||
@Autowired(required = false)
|
||||
private FaqVectorService faqVectorService;
|
||||
private final FaqRestService faqRestService;
|
||||
private final Random random = new Random();
|
||||
|
||||
public FaqIndexConsumer(FaqElasticService faqElasticService, FaqRestService faqRestService) {
|
||||
this.faqElasticService = faqElasticService;
|
||||
this.faqRestService = faqRestService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理FAQ索引队列中的消息
|
||||
* 使用客户端确认模式,只有成功处理后才确认消息
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
/**
|
||||
* FAQ向量检索服务
|
||||
@@ -45,6 +46,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
|
||||
public class FaqVectorService {
|
||||
|
||||
private final ElasticsearchVectorStore vectorStore;
|
||||
|
||||
@@ -35,11 +35,11 @@ import com.bytedesk.kbase.llm_chunk.vector.ChunkVectorService;
|
||||
import com.bytedesk.core.utils.BdDateUtils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ChunkEventListener {
|
||||
|
||||
private final ChunkElasticService chunkElasticService;
|
||||
@@ -48,7 +48,14 @@ public class ChunkEventListener {
|
||||
|
||||
private final FileRestService fileRestService;
|
||||
|
||||
private final ChunkVectorService chunkVectorService;
|
||||
@Autowired(required = false)
|
||||
private ChunkVectorService chunkVectorService;
|
||||
|
||||
public ChunkEventListener(ChunkElasticService chunkElasticService, ChunkRestService chunkRestService, FileRestService fileRestService) {
|
||||
this.chunkElasticService = chunkElasticService;
|
||||
this.chunkRestService = chunkRestService;
|
||||
this.fileRestService = fileRestService;
|
||||
}
|
||||
|
||||
|
||||
@EventListener
|
||||
@@ -104,10 +111,12 @@ public class ChunkEventListener {
|
||||
// 仅做全文索引
|
||||
chunkElasticService.indexChunk(chunk);
|
||||
/// 索引向量
|
||||
try {
|
||||
chunkVectorService.indexChunkVector(chunk);
|
||||
} catch (Exception e) {
|
||||
log.error("Chunk向量索引失败: {}, 错误: {}", chunk.getName(), e.getMessage());
|
||||
if (chunkVectorService != null) {
|
||||
try {
|
||||
chunkVectorService.indexChunkVector(chunk);
|
||||
} catch (Exception e) {
|
||||
log.error("Chunk向量索引失败: {}, 错误: {}", chunk.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,14 +128,16 @@ public class ChunkEventListener {
|
||||
// 更新全文索引
|
||||
chunkElasticService.indexChunk(chunk);
|
||||
// 更新向量索引
|
||||
try {
|
||||
// 先删除旧的向量索引
|
||||
chunkVectorService.deleteChunkVector(chunk);
|
||||
// 再创建新的向量索引
|
||||
chunkVectorService.indexChunkVector(chunk);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引更新失败: {}, 错误: {}", chunk.getContent(), e.getMessage());
|
||||
if (chunkVectorService != null) {
|
||||
try {
|
||||
// 先删除旧的向量索引
|
||||
chunkVectorService.deleteChunkVector(chunk);
|
||||
// 再创建新的向量索引
|
||||
chunkVectorService.indexChunkVector(chunk);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引更新失败: {}, 错误: {}", chunk.getContent(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,17 +28,23 @@ import com.bytedesk.kbase.llm_chunk.vector.ChunkVectorService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/llm/chunk")
|
||||
@AllArgsConstructor
|
||||
public class ChunkRestController extends BaseRestController<ChunkRequest> {
|
||||
|
||||
private final ChunkRestService chunkRestService;
|
||||
|
||||
private final ChunkElasticService chunkElasticService;
|
||||
|
||||
private final ChunkVectorService chunkVectorService;
|
||||
@Autowired(required = false)
|
||||
private ChunkVectorService chunkVectorService;
|
||||
|
||||
public ChunkRestController(ChunkRestService chunkRestService, ChunkElasticService chunkElasticService) {
|
||||
this.chunkRestService = chunkRestService;
|
||||
this.chunkElasticService = chunkElasticService;
|
||||
}
|
||||
|
||||
// @PreAuthorize("hasAuthority('KBASE_READ')")
|
||||
@Override
|
||||
@@ -138,7 +144,9 @@ public class ChunkRestController extends BaseRestController<ChunkRequest> {
|
||||
@PostMapping("/updateVectorIndex")
|
||||
public ResponseEntity<?> updateVectorIndex(@RequestBody ChunkRequest request) {
|
||||
|
||||
chunkVectorService.updateVectorIndex(request);
|
||||
if (chunkVectorService != null) {
|
||||
chunkVectorService.updateVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
|
||||
}
|
||||
@@ -158,7 +166,9 @@ public class ChunkRestController extends BaseRestController<ChunkRequest> {
|
||||
@PostMapping("/updateAllVectorIndex")
|
||||
public ResponseEntity<?> updateAllVectorIndex(@RequestBody ChunkRequest request) {
|
||||
|
||||
chunkVectorService.updateAllVectorIndex(request);
|
||||
if (chunkVectorService != null) {
|
||||
chunkVectorService.updateAllVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getKbUid()));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.bytedesk.kbase.llm_chunk.ChunkStatusEnum;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
/**
|
||||
* Chunk向量检索服务
|
||||
@@ -42,6 +43,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
|
||||
public class ChunkVectorService {
|
||||
|
||||
private final ElasticsearchVectorStore vectorStore;
|
||||
|
||||
@@ -31,18 +31,25 @@ import com.bytedesk.kbase.llm_text.event.TextUpdateDocEvent;
|
||||
import com.bytedesk.kbase.llm_text.vector.TextVectorService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class TextEventListener {
|
||||
|
||||
private final TextRestService textRestService;
|
||||
private final TextElasticService textElasticService;
|
||||
private final TextVectorService textVectorService;
|
||||
@Autowired(required = false)
|
||||
private TextVectorService textVectorService;
|
||||
private final UploadRestService uploadRestService;
|
||||
|
||||
public TextEventListener(TextRestService textRestService, TextElasticService textElasticService, UploadRestService uploadRestService) {
|
||||
this.textRestService = textRestService;
|
||||
this.textElasticService = textElasticService;
|
||||
this.uploadRestService = uploadRestService;
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onUploadCreateEvent(UploadCreateEvent event) {
|
||||
UploadEntity upload = event.getUpload();
|
||||
@@ -87,10 +94,12 @@ public class TextEventListener {
|
||||
textElasticService.indexText(text);
|
||||
|
||||
// 进行向量索引
|
||||
try {
|
||||
textVectorService.indexTextVector(text);
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引创建失败: {}, 错误: {}", text.getTitle(), e.getMessage());
|
||||
if (textVectorService != null) {
|
||||
try {
|
||||
textVectorService.indexTextVector(text);
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引创建失败: {}, 错误: {}", text.getTitle(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +112,15 @@ public class TextEventListener {
|
||||
textElasticService.indexText(text);
|
||||
|
||||
// 更新向量索引
|
||||
try {
|
||||
// 先删除旧的向量索引
|
||||
textVectorService.deleteTextVector(text);
|
||||
// 再创建新的向量索引
|
||||
textVectorService.indexTextVector(text);
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引更新失败: {}, 错误: {}", text.getTitle(), e.getMessage());
|
||||
if (textVectorService != null) {
|
||||
try {
|
||||
// 先删除旧的向量索引
|
||||
textVectorService.deleteTextVector(text);
|
||||
// 再创建新的向量索引
|
||||
textVectorService.indexTextVector(text);
|
||||
} catch (Exception e) {
|
||||
log.error("文本向量索引更新失败: {}, 错误: {}", text.getTitle(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,9 +136,11 @@ public class TextEventListener {
|
||||
}
|
||||
|
||||
// 从向量索引中删除
|
||||
boolean vectorDeleted = textVectorService.deleteTextVector(text);
|
||||
if (!vectorDeleted) {
|
||||
log.warn("从向量存储中删除Text索引失败: {}", text.getUid());
|
||||
if (textVectorService != null) {
|
||||
boolean vectorDeleted = textVectorService.deleteTextVector(text);
|
||||
if (!vectorDeleted) {
|
||||
log.warn("从向量存储中删除Text索引失败: {}", text.getUid());
|
||||
}
|
||||
}
|
||||
if (!deleted) {
|
||||
log.warn("从Elasticsearch中删除Text索引失败: {}", text.getUid());
|
||||
|
||||
@@ -28,11 +28,11 @@ import com.bytedesk.kbase.llm_text.vector.TextVectorService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/llm/text")
|
||||
@AllArgsConstructor
|
||||
@Description("Text Management Controller - LLM text content management and vector processing APIs")
|
||||
public class TextRestController extends BaseRestController<TextRequest> {
|
||||
|
||||
@@ -40,7 +40,13 @@ public class TextRestController extends BaseRestController<TextRequest> {
|
||||
|
||||
private final TextElasticService textElasticService;
|
||||
|
||||
private final TextVectorService textVectorService;
|
||||
@Autowired(required = false)
|
||||
private TextVectorService textVectorService;
|
||||
|
||||
public TextRestController(TextRestService textRestService, TextElasticService textElasticService) {
|
||||
this.textRestService = textRestService;
|
||||
this.textElasticService = textElasticService;
|
||||
}
|
||||
|
||||
// @PreAuthorize("hasAnyRole('SUPER', 'ADMIN')")
|
||||
@Override
|
||||
@@ -139,7 +145,9 @@ public class TextRestController extends BaseRestController<TextRequest> {
|
||||
@PostMapping("/updateVectorIndex")
|
||||
public ResponseEntity<?> updateVectorIndex(@RequestBody TextRequest request) {
|
||||
|
||||
textVectorService.updateVectorIndex(request);
|
||||
if (textVectorService != null) {
|
||||
textVectorService.updateVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update vector index success", request.getUid()));
|
||||
}
|
||||
@@ -159,7 +167,9 @@ public class TextRestController extends BaseRestController<TextRequest> {
|
||||
@PostMapping("/updateAllVectorIndex")
|
||||
public ResponseEntity<?> updateAllVectorIndex(@RequestBody TextRequest request) {
|
||||
|
||||
textVectorService.updateAllVectorIndex(request);
|
||||
if (textVectorService != null) {
|
||||
textVectorService.updateAllVectorIndex(request);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success("update all vector index success", request.getKbUid()));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_text.TextRestService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
/**
|
||||
* Text向量检索服务
|
||||
@@ -43,6 +44,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
|
||||
public class TextVectorService {
|
||||
|
||||
private final ElasticsearchVectorStore vectorStore;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.bytedesk.kbase.llm_webpage.vector.WebpageVectorService;
|
||||
import com.bytedesk.kbase.llm_webpage.service.WebpageCrawlerService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -35,13 +36,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class WebpageIndexConsumer {
|
||||
|
||||
private final WebpageElasticService webpageElasticService;
|
||||
private final WebpageVectorService webpageVectorService;
|
||||
@Autowired(required = false)
|
||||
private WebpageVectorService webpageVectorService;
|
||||
private final WebpageRestService webpageRestService;
|
||||
private final WebpageCrawlerService webpageCrawlerService;
|
||||
|
||||
public WebpageIndexConsumer(WebpageElasticService webpageElasticService, WebpageRestService webpageRestService, WebpageCrawlerService webpageCrawlerService) {
|
||||
this.webpageElasticService = webpageElasticService;
|
||||
this.webpageRestService = webpageRestService;
|
||||
this.webpageCrawlerService = webpageCrawlerService;
|
||||
}
|
||||
private final Random random = new Random();
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.bytedesk.kbase.llm_webpage.WebpageRestService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
/**
|
||||
* 网页向量检索服务
|
||||
@@ -44,6 +45,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.class)
|
||||
public class WebpageVectorService {
|
||||
|
||||
private final ElasticsearchVectorStore vectorStore;
|
||||
|
||||
Reference in New Issue
Block a user