forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (53 loc) · 2.81 KB
/
Program.cs
File metadata and controls
68 lines (53 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Handlers;
// Alternative approach using appsettings.json and appsettings.development.json
//
// Run `dotnet run setup` to create appsettings.development.json
// if (new[] { "setup", "-setup" }.Contains(args.FirstOrDefault(), StringComparer.OrdinalIgnoreCase))
// {
// Main.InteractiveSetup(cfgService: false, cfgOrchestration: false);
// }
//
// var memoryBuilder = new KernelMemoryBuilder().FromAppSettings();
var memoryBuilder = new KernelMemoryBuilder()
// .FromAppSettings() => read "KernelMemory" settings from appsettings.json (if available), see https://github.com/microsoft/kernel-memory/blob/main/dotnet/Service/appsettings.json as an example
// .WithAzureAISearch(Env.Var("AZSEARCH_ENDPOINT"), Env.Var("AZSEARCH_API_KEY")) => To use Azure AI Search
// .WithQdrant("http://127.0.0.1:6333") => To use Qdrant docker
.WithOpenAIDefaults(Env.Var("OPENAI_API_KEY"));
var _ = memoryBuilder.Build();
var orchestrator = memoryBuilder.GetOrchestrator();
// Add pipeline handlers
Console.WriteLine("* Defining pipeline handlers...");
TextExtractionHandler textExtraction = new("extract", orchestrator);
await orchestrator.AddHandlerAsync(textExtraction);
TextPartitioningHandler textPartitioning = new("partition", orchestrator);
await orchestrator.AddHandlerAsync(textPartitioning);
SummarizationHandler summarizeEmbedding = new("summarize", orchestrator);
await orchestrator.AddHandlerAsync(summarizeEmbedding);
GenerateEmbeddingsHandler textEmbedding = new("gen_embeddings", orchestrator);
await orchestrator.AddHandlerAsync(textEmbedding);
SaveRecordsHandler saveRecords = new("save_records", orchestrator);
await orchestrator.AddHandlerAsync(saveRecords);
// orchestrator.AddHandlerAsync(...);
// orchestrator.AddHandlerAsync(...);
// Create sample pipeline with 4 files
Console.WriteLine("* Defining pipeline with 4 files...");
var pipeline = orchestrator
.PrepareNewDocumentUpload(index: "tests", documentId: "inProcessTest", new TagCollection { { "testName", "example3" } })
.AddUploadFile("file1", "file1-Wikipedia-Carbon.txt", "file1-Wikipedia-Carbon.txt")
.AddUploadFile("file2", "file2-Wikipedia-Moon.txt", "file2-Wikipedia-Moon.txt")
.AddUploadFile("file3", "file3-lorem-ipsum.docx", "file3-lorem-ipsum.docx")
.AddUploadFile("file4", "file4-SK-Readme.pdf", "file4-SK-Readme.pdf")
.AddUploadFile("file5", "file5-NASA-news.pdf", "file5-NASA-news.pdf")
.Then("extract")
.Then("partition")
.Then("summarize")
.Then("gen_embeddings")
.Then("save_records")
.Build();
// Execute pipeline
Console.WriteLine("* Executing pipeline...");
await orchestrator.RunPipelineAsync(pipeline);
Console.WriteLine("* File import completed.");
Console.WriteLine("Refactoring in progress");