textSearch 文本搜索
(ctx context.Context, query string, opts *RAGOptions)
| 360 | |
| 361 | // textSearch 文本搜索 |
| 362 | func (r *RAG) textSearch(ctx context.Context, query string, opts *RAGOptions) ([]*RetrievalItem, error) { |
| 363 | searchQuery := &SearchQuery{ |
| 364 | Query: query, |
| 365 | Strategy: StrategyText, |
| 366 | MaxResults: opts.MaxResults, |
| 367 | Namespace: opts.Namespace, |
| 368 | } |
| 369 | |
| 370 | // 应用选项过滤 |
| 371 | if opts.KnowledgeType != "" { |
| 372 | searchQuery.Type = opts.KnowledgeType |
| 373 | } |
| 374 | if opts.Category != "" { |
| 375 | searchQuery.Category = opts.Category |
| 376 | } |
| 377 | if len(opts.Tags) > 0 { |
| 378 | searchQuery.Tags = opts.Tags |
| 379 | } |
| 380 | if opts.TimeRange != nil { |
| 381 | searchQuery.After = &opts.TimeRange.Start |
| 382 | searchQuery.Before = &opts.TimeRange.End |
| 383 | } |
| 384 | if opts.QualityFilter != nil { |
| 385 | searchQuery.MinConfidence = opts.QualityFilter.MinConfidence |
| 386 | searchQuery.MinQuality = opts.QualityFilter.MinQuality |
| 387 | } |
| 388 | |
| 389 | results, err := r.manager.Search(ctx, searchQuery) |
| 390 | if err != nil { |
| 391 | return nil, err |
| 392 | } |
| 393 | |
| 394 | items := make([]*RetrievalItem, len(results)) |
| 395 | for i, result := range results { |
| 396 | items[i] = &RetrievalItem{ |
| 397 | Item: &result.Item, |
| 398 | Score: result.Score * r.config.TextSearchWeight, |
| 399 | Source: "text", |
| 400 | Explanation: "Text-based search match", |
| 401 | Rank: i + 1, |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | return items, nil |
| 406 | } |
| 407 | |
| 408 | // vectorSearch 向量搜索 |
| 409 | func (r *RAG) vectorSearch(_ context.Context, _ string, _ *RAGOptions) ([]*RetrievalItem, error) { |
no test coverage detected