package com.agent.management.rag.controller; import com.agent.management.common.Result; import com.agent.management.model.entity.RagKnowledgeBase; import com.agent.management.model.entity.RagKnowledgeSourceBinding; import com.agent.management.rag.kb.KnowledgeBaseRagRetriever; import com.agent.management.rag.kb.RagKnowledgeBaseConfigService; import com.agent.management.rag.model.*; import com.agent.management.repository.RagKnowledgeBaseRepository; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.util.*;
@RestController @RequestMapping("/api/rag/kb") @RequiredArgsConstructor public class KnowledgeBaseRagDebugController {private final KnowledgeBaseRagRetriever retriever;private final RagKnowledgeBaseConfigService configs;private final RagKnowledgeBaseRepository knowledgeBaseRepository;@PostMapping("/retrieve") public Result<KnowledgeBaseRagResult> retrieve(@RequestBody KnowledgeBaseRagRequest q){return Result.success(retriever.retrieve(q));}@GetMapping("/{id}/bindings") public Result<List<RagKnowledgeSourceBinding>> bindings(@PathVariable Long id){return Result.success(configs.listBindings(id));}@PutMapping("/{id}/bindings/{bindingId}/config") public Result<RagKnowledgeSourceBinding> updateConfig(@PathVariable Long id,@PathVariable Long bindingId,@RequestBody Map<String,Object> config){return Result.success(configs.updateConfig(id,bindingId,config));}@PutMapping("/{id}/bindings/by-source") public Result<RagKnowledgeSourceBinding> upsertBySource(@PathVariable Long id,@RequestBody Map<String,Object> body){RagSourceType sourceType=RagSourceType.valueOf(String.valueOf(body.get("sourceType")).toUpperCase(Locale.ROOT));String sourceId=String.valueOf(body.get("sourceId"));@SuppressWarnings("unchecked") Map<String,Object> config=(Map<String,Object>)body.get("config");return Result.success(configs.upsertBySource(id,sourceType,sourceId,config));}@GetMapping public Result<List<RagKnowledgeBase>> list(){return Result.success(knowledgeBaseRepository.findAll());}}
