package handlers import ( "net/http" "github.com/breakpilot/ai-compliance-sdk/internal/ucca" "github.com/gin-gonic/gin" ) // RAGHandlers handles RAG search API endpoints. type RAGHandlers struct { ragClient *ucca.LegalRAGClient } // NewRAGHandlers creates new RAG handlers. func NewRAGHandlers() *RAGHandlers { return &RAGHandlers{ ragClient: ucca.NewLegalRAGClient(), } } // SearchRequest represents a RAG search request. type SearchRequest struct { Query string `json:"query" binding:"required"` Regulations []string `json:"regulations,omitempty"` TopK int `json:"top_k,omitempty"` } // Search performs a semantic search across the compliance regulation corpus. // POST /sdk/v1/rag/search func (h *RAGHandlers) Search(c *gin.Context) { var req SearchRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } if req.TopK <= 0 || req.TopK > 20 { req.TopK = 5 } results, err := h.ragClient.Search(c.Request.Context(), req.Query, req.Regulations, req.TopK) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "RAG search failed: " + err.Error()}) return } c.JSON(http.StatusOK, gin.H{ "query": req.Query, "results": results, "count": len(results), }) } // ListRegulations returns the list of available regulations in the corpus. // GET /sdk/v1/rag/regulations func (h *RAGHandlers) ListRegulations(c *gin.Context) { regs := h.ragClient.ListAvailableRegulations() // Optionally filter by category category := c.Query("category") if category != "" { filtered := make([]ucca.CERegulationInfo, 0) for _, r := range regs { if r.Category == category { filtered = append(filtered, r) } } regs = filtered } c.JSON(http.StatusOK, gin.H{ "regulations": regs, "count": len(regs), }) }