feat: Make search parameters configurable in HybridSearch

This commit is contained in:
Mirza-Samad-Ahmed-Baig
2025-08-09 17:23:03 +05:00
committed by lyingbug
parent 6eefe1c2a7
commit 789896f121
2 changed files with 14 additions and 19 deletions
+10 -15
View File
@@ -30,14 +30,6 @@ func (h *KnowledgeBaseHandler) HybridSearch(c *gin.Context) {
logger.Info(ctx, "Start hybrid search")
// Validate query parameter existence
query := c.Query("query")
if query == "" {
logger.Error(ctx, "Query parameter is empty")
c.Error(errors.NewBadRequestError("Query parameter cannot be empty"))
return
}
// Validate knowledge base ID
id := c.Param("id")
if id == "" {
@@ -46,15 +38,18 @@ func (h *KnowledgeBaseHandler) HybridSearch(c *gin.Context) {
return
}
logger.Infof(ctx, "Executing hybrid search, knowledge base ID: %s, query: %s", id, query)
// Parse request body
var req types.SearchParams
if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to parse request parameters", err)
c.Error(errors.NewBadRequestError("Invalid request parameters").WithDetails(err.Error()))
return
}
logger.Infof(ctx, "Executing hybrid search, knowledge base ID: %s, query: %s", id, req.QueryText)
// Execute hybrid search with default search parameters
results, err := h.service.HybridSearch(ctx, id, types.SearchParams{
QueryText: query,
KeywordThreshold: 0.5,
VectorThreshold: 0.3,
MatchCount: 10,
})
results, err := h.service.HybridSearch(ctx, id, req)
if err != nil {
logger.ErrorWithFields(ctx, err, nil)
c.Error(errors.NewInternalServerError(err.Error()))
+4 -4
View File
@@ -50,10 +50,10 @@ type SearchResult struct {
// SearchParams represents the search parameters
type SearchParams struct {
QueryText string
VectorThreshold float64
KeywordThreshold float64
MatchCount int
QueryText string `json:"query_text"`
VectorThreshold float64 `json:"vector_threshold"`
KeywordThreshold float64 `json:"keyword_threshold"`
MatchCount int `json:"match_count"`
}
// Value implements the driver.Valuer interface, used to convert SearchResult to database value