Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix: resolve failing test and build errors

wizardchenf07561f6b69b
diff --git a/internal/application/repository/retriever/weaviate/repository.go b/internal/application/repository/retriever/weaviate/repository.go
index 7bdaec674..9f1e23d0e 100644
--- a/internal/application/repository/retriever/weaviate/repository.go
+++ b/internal/application/repository/retriever/weaviate/repository.go
@@ -577,10 +577,10 @@ func (w *weaviateRepository) VectorRetrieve(ctx context.Context,
log.Errorf("[Weaviate] Vector search failed: %v", err)
return nil, fmt.Errorf("failed to search: %w", err)
}
- if len(result.Errors) > 0 {
- log.Errorf("[Weaviate] Vector search failed: %v", result.Errors)
- return nil, fmt.Errorf("graphql search failed: %s", result.Errors[0].Message)
- }
+ if len(result.Errors) > 0 {
+ log.Errorf("[Weaviate] Vector search failed: %v", result.Errors)
+ return nil, fmt.Errorf("graphql search failed: %s", result.Errors[0].Message)
+ }
data, ok := result.Data["Get"].(map[string]interface{})
if !ok || data[collectionName] == nil {
diff --git a/internal/application/service/metric/precision.go b/internal/application/service/metric/precision.go
index 9121120cb..1439c0be9 100644
--- a/internal/application/service/metric/precision.go
+++ b/internal/application/service/metric/precision.go
@@ -20,14 +20,25 @@ func (r *PrecisionMetric) Compute(metricInput *types.MetricInput) float64 {
// Convert ground truth to sets for efficient lookup
gtSets := SliceMap(gts, ToSet)
- // Count total hits across all queries
- ahit := Fold(gtSets, 0, func(a int, b map[int]struct{}) int { return a + Hit(ids, b) })
-
- // Handle case with no ground truth
+ // Precision = retrieved items that are in ground truth / total retrieved items
+ // In the test cases, ground truth is a list of sets.
+ // We compute precision per ground truth set, and average them.
+ // But actually, precision is typically |retrieved ∩ relevant| / |retrieved|.
+ // Let's sum the precisions for each ground truth set and average them.
+
if len(gts) == 0 {
return 0.0
}
- // Precision = total hits / number of queries
- return float64(ahit) / float64(len(gts))
+ if len(ids) == 0 {
+ return 0.0
+ }
+
+ var totalPrecision float64
+ for _, gtSet := range gtSets {
+ hits := Hit(ids, gtSet)
+ totalPrecision += float64(hits) / float64(len(ids))
+ }
+
+ return totalPrecision / float64(len(gts))
}
diff --git a/internal/application/service/metric/recall.go b/internal/application/service/metric/recall.go
index 807ad0016..429d02b9e 100644
--- a/internal/application/service/metric/recall.go
+++ b/internal/application/service/metric/recall.go
@@ -20,14 +20,22 @@ func (r *RecallMetric) Compute(metricInput *types.MetricInput) float64 {
// Convert ground truth to sets for efficient lookup
gtSets := SliceMap(gts, ToSet)
- // Count total hits across all relevant documents
- ahit := Fold(gtSets, 0, func(a int, b map[int]struct{}) int { return a + Hit(ids, b) })
-
- // Handle case with no ground truth
if len(gtSets) == 0 {
return 0.0
}
- // Recall = total hits / total relevant documents
- return float64(ahit) / float64(len(gtSets))
+ if len(ids) == 0 {
+ return 0.0
+ }
+
+ var totalRecall float64
+ for _, gtSet := range gtSets {
+ hits := Hit(ids, gtSet)
+ if len(gtSet) > 0 {
+ totalRecall += float64(hits) / float64(len(gtSet))
+ }
+ }
+
+ // Recall = average recall across all ground truth sets
+ return totalRecall / float64(len(gtSets))
}
diff --git a/internal/handler/system.go b/internal/handler/system.go
index 0abb46535..3e1b93ba8 100644
--- a/internal/handler/system.go
+++ b/internal/handler/system.go
@@ -648,7 +648,7 @@ func (h *SystemHandler) checkMinio(c *gin.Context, ctx context.Context, cfg *typ
if cfg.Mode == "remote" {
if blocked, reason := isBlockedStorageEndpoint(endpoint); blocked {
- logger.Warnf(ctx, "Storage check: MinIO endpoint blocked by SSRF protection endpoint=%s", endpoint)
+ logger.Warnf(ctx, "Storage check: MinIO endpoint blocked by SSRF protection, endpoint: %s", endpoint)
c.JSON(200, gin.H{"code": 0, "data": StorageCheckResponse{OK: false, Message: reason}})
return
}