Search runs hybrid retrieval and renders cited passages.
(query, kb string, topK int)
| 52 | |
| 53 | // Search runs hybrid retrieval and renders cited passages. |
| 54 | func (a *knowledgePluginAdapter) Search(query, kb string, topK int) (string, error) { |
| 55 | mgr := a.manager() |
| 56 | if mgr == nil { |
| 57 | return "", fmt.Errorf("context manager unavailable in this session") |
| 58 | } |
| 59 | if topK <= 0 { |
| 60 | topK = ctxmgr.DefaultRetrievalTopK |
| 61 | } |
| 62 | if topK > knowledgeSearchMaxTopK { |
| 63 | topK = knowledgeSearchMaxTopK |
| 64 | } |
| 65 | ctx, cancel := context.WithTimeout(context.Background(), knowledgeOpTimeout) |
| 66 | defer cancel() |
| 67 | hits, err := mgr.KnowledgeSearch(ctx, a.sessionID(), kb, query, topK) |
| 68 | if err != nil { |
| 69 | return "", err |
| 70 | } |
| 71 | return ctxmgr.FormatKnowledgeHits(query, hits), nil |
| 72 | } |
| 73 | |
| 74 | // Get returns one page of a document plus explicit pagination guidance. |
| 75 | func (a *knowledgePluginAdapter) Get(source, kb string, offset int) (string, error) { |