feat: Make search parameters configurable in HybridSearch
This commit is contained in:
committed by
lyingbug
parent
6eefe1c2a7
commit
789896f121
@@ -30,14 +30,6 @@ func (h *KnowledgeBaseHandler) HybridSearch(c *gin.Context) {
|
|||||||
|
|
||||||
logger.Info(ctx, "Start hybrid search")
|
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
|
// Validate knowledge base ID
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
@@ -46,15 +38,18 @@ func (h *KnowledgeBaseHandler) HybridSearch(c *gin.Context) {
|
|||||||
return
|
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
|
// Execute hybrid search with default search parameters
|
||||||
results, err := h.service.HybridSearch(ctx, id, types.SearchParams{
|
results, err := h.service.HybridSearch(ctx, id, req)
|
||||||
QueryText: query,
|
|
||||||
KeywordThreshold: 0.5,
|
|
||||||
VectorThreshold: 0.3,
|
|
||||||
MatchCount: 10,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorWithFields(ctx, err, nil)
|
logger.ErrorWithFields(ctx, err, nil)
|
||||||
c.Error(errors.NewInternalServerError(err.Error()))
|
c.Error(errors.NewInternalServerError(err.Error()))
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ type SearchResult struct {
|
|||||||
|
|
||||||
// SearchParams represents the search parameters
|
// SearchParams represents the search parameters
|
||||||
type SearchParams struct {
|
type SearchParams struct {
|
||||||
QueryText string
|
QueryText string `json:"query_text"`
|
||||||
VectorThreshold float64
|
VectorThreshold float64 `json:"vector_threshold"`
|
||||||
KeywordThreshold float64
|
KeywordThreshold float64 `json:"keyword_threshold"`
|
||||||
MatchCount int
|
MatchCount int `json:"match_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver.Valuer interface, used to convert SearchResult to database value
|
// Value implements the driver.Valuer interface, used to convert SearchResult to database value
|
||||||
|
|||||||
Reference in New Issue
Block a user