(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestFactory_AddAndSearch(t *testing.T) { |
| 13 | pipe, err := core.NewPipeline(core.PipelineConfig{ |
| 14 | Store: vector.NewMemoryStore(), |
| 15 | Embedder: vector.NewMockEmbedder(16), |
| 16 | }) |
| 17 | if err != nil { |
| 18 | t.Fatalf("new pipeline: %v", err) |
| 19 | } |
| 20 | |
| 21 | f := NewFactory(pipe) |
| 22 | add, _ := f.KnowledgeAddTool() |
| 23 | search, _ := f.KnowledgeSearchTool() |
| 24 | |
| 25 | _, err = add.Execute(context.Background(), map[string]any{ |
| 26 | "text": "Go has goroutines for concurrency.", |
| 27 | "namespace": "ns1", |
| 28 | }, &tools.ToolContext{}) |
| 29 | if err != nil { |
| 30 | t.Fatalf("add exec error: %v", err) |
| 31 | } |
| 32 | |
| 33 | resp, err := search.Execute(context.Background(), map[string]any{ |
| 34 | "query": "goroutines", |
| 35 | "namespace": "ns1", |
| 36 | "top_k": 3, |
| 37 | }, &tools.ToolContext{}) |
| 38 | if err != nil { |
| 39 | t.Fatalf("search exec error: %v", err) |
| 40 | } |
| 41 | |
| 42 | resMap, ok := resp.(map[string]any) |
| 43 | if !ok { |
| 44 | t.Fatalf("unexpected resp type: %T", resp) |
| 45 | } |
| 46 | results, ok := resMap["results"].([]map[string]any) |
| 47 | if !ok || len(results) == 0 { |
| 48 | t.Fatalf("expected results") |
| 49 | } |
| 50 | } |
nothing calls this directly
no test coverage detected