Files
breakpilot-compliance/ai-compliance-sdk/internal/api/handlers/rag_handlers.go
Benjamin Boenisch 899e22a31b
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 46s
CI / test-python-backend-compliance (push) Successful in 30s
CI / test-python-dsms-gateway (push) Has been cancelled
CI / test-python-document-crawler (push) Has been cancelled
feat(rag): connect bp_compliance_ce vector corpus to SDK
- Switch LegalRAGClient from empty bp_legal_corpus to bp_compliance_ce
  collection (3,734 chunks across 14 regulations)
- Replace embedding-service (384-dim MiniLM) with Ollama bge-m3 (1024-dim)
- Add standalone RAG search endpoint: POST /sdk/v1/rag/search
- Add regulations list endpoint: GET /sdk/v1/rag/regulations
- Add QDRANT_HOST/PORT env vars to docker-compose.yml
- Update regulation ID mapping to match actual Qdrant payload schema
- Update determineRelevantRegulations for CE corpus regulation IDs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 23:44:47 +01:00

77 lines
1.8 KiB
Go

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),
})
}