Skip to content

Commit be010c4

Browse files
committed
fix: add ai/search endpoint (#281)
1 parent 0afb11f commit be010c4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

base/src/main/java/com/tinyengine/it/controller/AiChatController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import com.tinyengine.it.model.dto.AiToken;
1919
import com.tinyengine.it.model.dto.ChatRequest;
2020

21+
import com.tinyengine.it.rag.entity.EmbeddingMatchDto;
22+
import com.tinyengine.it.rag.entity.SearchRequest;
23+
import com.tinyengine.it.rag.service.StorageService;
2124
import com.tinyengine.it.service.app.v1.AiChatV1Service;
2225
import io.swagger.v3.oas.annotations.Operation;
2326
import io.swagger.v3.oas.annotations.Parameter;
@@ -37,6 +40,8 @@
3740
import org.springframework.web.bind.annotation.RestController;
3841
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
3942

43+
import java.util.List;
44+
4045
/**
4146
* The type Ai chat controller.
4247
*
@@ -53,6 +58,9 @@ public class AiChatController {
5358
@Autowired
5459
private AiChatV1Service aiChatV1Service;
5560

61+
@Autowired
62+
private StorageService vectorStorageService;
63+
5664
/**
5765
* AI api
5866
*
@@ -151,4 +159,25 @@ public Result<AiToken> getToken(@RequestBody ChatRequest request) throws Excepti
151159
String token = aiChatV1Service.getToken(apiKey);
152160
return Result.success(new AiToken(token));
153161
}
162+
163+
/**
164+
* search in collection
165+
*
166+
* @param searchDto the searchDto
167+
* @return result
168+
*/
169+
@Operation(summary = "在指定集合中搜索", description = "在指定集合中搜索",
170+
parameters = {
171+
@Parameter(name = "searchDto", description = "搜索请求参数体"),
172+
}, responses = {
173+
@ApiResponse(responseCode = "200", description = "返回信息",
174+
content = @Content(mediaType = "application/json", schema = @Schema())),
175+
@ApiResponse(responseCode = "400", description = "请求失败")
176+
})
177+
@SystemControllerLog(description = "AI search in collection")
178+
@PostMapping("/ai/search")
179+
public Result<List<EmbeddingMatchDto>> searchInCollection(@RequestBody SearchRequest searchDto) {
180+
List<EmbeddingMatchDto> results = vectorStorageService.search(searchDto);
181+
return Result.success(results);
182+
}
154183
}

0 commit comments

Comments
 (0)