446f865cdf
- Implemented KnowledgeHandler for managing knowledge groups and items, including listing, creating, updating, and deleting operations. - Added database migration scripts to create necessary tables for knowledge management, including knowledge_groups, knowledge_items, knowledge_parse_tasks, and knowledge_chunks_meta. - Introduced prompt_rule_knowledge_groups table to associate prompt rules with knowledge groups.
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package retrieval
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/config"
|
|
)
|
|
|
|
var ErrNotConfigured = errors.New("retrieval provider is not configured")
|
|
|
|
type Provider interface {
|
|
Validate() error
|
|
Embed(ctx context.Context, inputs []string) ([][]float64, error)
|
|
Rerank(ctx context.Context, query string, documents []string, topN int) ([]RerankResult, error)
|
|
}
|
|
|
|
type RerankResult struct {
|
|
Index int
|
|
RelevanceScore float64
|
|
Text string
|
|
}
|
|
|
|
func NewProvider(cfg config.RetrievalConfig, logger *zap.Logger) Provider {
|
|
provider := strings.ToLower(strings.TrimSpace(cfg.Provider))
|
|
switch provider {
|
|
case "", "disabled":
|
|
return disabledProvider{reason: "retrieval provider is disabled"}
|
|
case "siliconflow":
|
|
return NewSiliconFlowProvider(cfg, logger)
|
|
default:
|
|
return disabledProvider{reason: fmt.Sprintf("unsupported retrieval provider %q", cfg.Provider)}
|
|
}
|
|
}
|
|
|
|
type disabledProvider struct {
|
|
reason string
|
|
}
|
|
|
|
func (p disabledProvider) Validate() error {
|
|
if p.reason == "" {
|
|
p.reason = "missing retrieval configuration"
|
|
}
|
|
return fmt.Errorf("%w: %s", ErrNotConfigured, p.reason)
|
|
}
|
|
|
|
func (p disabledProvider) Embed(context.Context, []string) ([][]float64, error) {
|
|
return nil, p.Validate()
|
|
}
|
|
|
|
func (p disabledProvider) Rerank(context.Context, string, []string, int) ([]RerankResult, error) {
|
|
return nil, p.Validate()
|
|
}
|