77import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
88import io .swagger .v3 .oas .annotations .tags .Tag ;
99import jakarta .ws .rs .Consumes ;
10- import jakarta .ws .rs .DefaultValue ;
1110import jakarta .ws .rs .GET ;
1211import jakarta .ws .rs .POST ;
1312import jakarta .ws .rs .Path ;
1817import jakarta .ws .rs .core .Response ;
1918import jakarta .ws .rs .core .SecurityContext ;
2019import java .util .Collections ;
21- import java .util .List ;
2220import java .util .Map ;
2321import java .util .UUID ;
2422import lombok .extern .slf4j .Slf4j ;
@@ -42,73 +40,12 @@ public VectorSearchResource(Authorizer authorizer) {
4240 this .authorizer = authorizer ;
4341 }
4442
45- @ GET
46- @ Path ("/query" )
47- @ Operation (
48- operationId = "vectorSearch" ,
49- summary = "Vector semantic search" ,
50- description = "Search entities using vector embeddings for semantic similarity." ,
51- responses = {
52- @ ApiResponse (
53- responseCode = "200" ,
54- description = "Vector search results" ,
55- content =
56- @ Content (
57- mediaType = "application/json" ,
58- schema = @ Schema (implementation = VectorSearchResponse .class )))
59- })
60- public Response vectorSearch (
61- @ Context SecurityContext securityContext ,
62- @ Parameter (description = "Search query text" , required = true ) @ QueryParam ("q" ) String query ,
63- @ Parameter (description = "Entity type to filter results" ) @ QueryParam ("entityType" )
64- String entityType ,
65- @ Parameter (description = "Number of results to return" ) @ DefaultValue ("10" ) @ QueryParam ("k" )
66- int k ,
67- @ Parameter (description = "Score threshold for filtering" )
68- @ DefaultValue ("0.0" )
69- @ QueryParam ("threshold" )
70- double threshold ) {
71- if (!Entity .getSearchRepository ().isVectorEmbeddingEnabled ()) {
72- return Response .status (Response .Status .SERVICE_UNAVAILABLE )
73- .entity ("{\" error\" :\" Vector search is not enabled\" }" )
74- .build ();
75- }
76-
77- if (query == null || query .isBlank ()) {
78- return Response .status (Response .Status .BAD_REQUEST )
79- .entity ("{\" error\" :\" query parameter 'q' is required\" }" )
80- .build ();
81- }
82-
83- OpenSearchVectorService vectorService = OpenSearchVectorService .getInstance ();
84- if (vectorService == null ) {
85- return Response .status (Response .Status .SERVICE_UNAVAILABLE )
86- .entity ("{\" error\" :\" Vector search service is not initialized\" }" )
87- .build ();
88- }
89-
90- try {
91- Map <String , List <String >> filters =
92- entityType != null && !entityType .isBlank ()
93- ? Map .of ("entityType" , List .of (entityType ))
94- : Collections .emptyMap ();
95-
96- VectorSearchResponse response = vectorService .search (query , filters , k , k , threshold );
97- return Response .ok (response ).build ();
98- } catch (Exception e ) {
99- LOG .error ("Vector search failed: {}" , e .getMessage (), e );
100- return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
101- .entity ("{\" error\" :\" An internal error occurred\" }" )
102- .build ();
103- }
104- }
105-
10643 @ POST
10744 @ Path ("/query" )
10845 @ Consumes (MediaType .APPLICATION_JSON )
10946 @ Operation (
110- operationId = "vectorSearchPost " ,
111- summary = "Vector semantic search (POST) " ,
47+ operationId = "vectorSearch " ,
48+ summary = "Vector semantic search" ,
11249 description = "Search entities using vector embeddings with full filter support." ,
11350 responses = {
11451 @ ApiResponse (
0 commit comments