()
| 13 | ) |
| 14 | |
| 15 | func main() { |
| 16 | pipe, err := core.NewPipeline(core.PipelineConfig{ |
| 17 | Store: vector.NewMemoryStore(), |
| 18 | Embedder: vector.NewMockEmbedder(32), |
| 19 | Namespace: "demo", |
| 20 | DefaultTopK: 3, |
| 21 | }) |
| 22 | if err != nil { |
| 23 | log.Fatalf("init pipeline: %v", err) |
| 24 | } |
| 25 | |
| 26 | ctx := context.Background() |
| 27 | |
| 28 | // 入库 |
| 29 | text := `Aster 是面向生产的多 Agent 框架。 |
| 30 | 它内置工作记忆、语义记忆、Workflow 编排以及丰富的安全护栏。` |
| 31 | |
| 32 | chunks, err := pipe.Ingest(ctx, core.IngestRequest{ |
| 33 | ID: "intro", |
| 34 | Text: text, |
| 35 | Namespace: "demo", |
| 36 | Metadata: map[string]any{ |
| 37 | "source": "docs/intro", |
| 38 | }, |
| 39 | }) |
| 40 | if err != nil { |
| 41 | log.Fatalf("ingest: %v", err) |
| 42 | } |
| 43 | if _, err := fmt.Fprintf(os.Stdout, "Inserted %d chunks\n", len(chunks)); err != nil { |
| 44 | log.Printf("Failed to write output: %v", err) |
| 45 | } |
| 46 | |
| 47 | // 检索 |
| 48 | hits, err := pipe.Search(ctx, "什么是 Aster?", 3, map[string]any{ |
| 49 | "namespace": "demo", |
| 50 | }) |
| 51 | if err != nil { |
| 52 | log.Fatalf("search: %v", err) |
| 53 | } |
| 54 | |
| 55 | if _, err := fmt.Fprintf(os.Stdout, "Top hits:\n"); err != nil { |
| 56 | log.Printf("Failed to write output: %v", err) |
| 57 | } |
| 58 | for i, h := range hits { |
| 59 | if _, err := fmt.Fprintf(os.Stdout, "%d) score=%.4f text=%.50s...\n", i+1, h.Score, h.Text); err != nil { |
| 60 | log.Printf("Failed to write output: %v", err) |
| 61 | } |
| 62 | } |
| 63 | } |
nothing calls this directly
no test coverage detected