MCPcopy Create free account
hub / github.com/astercloud/aster / TestFactory_AddAndSearch

Function TestFactory_AddAndSearch

pkg/tools/knowledge/factory_test.go:12–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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}

Callers

nothing calls this directly

Calls 7

KnowledgeAddToolMethod · 0.95
KnowledgeSearchToolMethod · 0.95
NewPipelineFunction · 0.92
NewMemoryStoreFunction · 0.92
NewMockEmbedderFunction · 0.92
NewFactoryFunction · 0.70
ExecuteMethod · 0.65

Tested by

no test coverage detected