11using KernelMemory . Extensions . ConsoleTest . Helper ;
22using Microsoft . Extensions . DependencyInjection ;
3+ using Microsoft . Extensions . Logging ;
34using Microsoft . KernelMemory ;
45using Microsoft . KernelMemory . DataFormats ;
56using Microsoft . KernelMemory . DocumentStorage . DevTools ;
67using Microsoft . KernelMemory . FileSystem . DevTools ;
78using Microsoft . KernelMemory . Handlers ;
89using Microsoft . KernelMemory . MemoryStorage . DevTools ;
10+ using Spectre . Console ;
911
1012namespace SemanticMemory . Samples ;
1113
@@ -14,7 +16,11 @@ public class SimpleBookIndexingWithTextCleaning : ISample
1416 public async Task RunSample ( string bookPdf )
1517 {
1618 var services = new ServiceCollection ( ) ;
17-
19+ services . AddLogging ( l => l
20+ . SetMinimumLevel ( LogLevel . Trace )
21+ . AddConsole ( )
22+ . AddDebug ( )
23+ ) ;
1824 //do not forget to add decoders
1925 services . AddDefaultContentDecoders ( ) ;
2026
@@ -38,8 +44,8 @@ public async Task RunSample(string bookPdf)
3844 TextPartitioningHandler textPartitioning = new ( "partition" , orchestrator ) ;
3945 await orchestrator . AddHandlerAsync ( textPartitioning ) ;
4046
41- SummarizationHandler summarizeEmbedding = new ( "summarize" , orchestrator ) ;
42- await orchestrator . AddHandlerAsync ( summarizeEmbedding ) ;
47+ // SummarizationHandler summarizeEmbedding = new("summarize", orchestrator);
48+ // await orchestrator.AddHandlerAsync(summarizeEmbedding);
4349
4450 GenerateEmbeddingsHandler textEmbedding = new ( "gen_embeddings" , orchestrator ) ;
4551 await orchestrator . AddHandlerAsync ( textEmbedding ) ;
@@ -51,24 +57,39 @@ public async Task RunSample(string bookPdf)
5157 // orchestrator.AddHandlerAsync(...);
5258
5359 // Create sample pipeline with 4 files
54- Console . WriteLine ( "* Defining pipeline with 4 files..." ) ;
55- var pipeline = orchestrator
56- . PrepareNewDocumentUpload (
57- index : "booksample" ,
58- documentId : "booksample" ,
59- new TagCollection { { "example" , "books" } } )
60- . AddUploadFile ( "file1" , Path . GetFileName ( bookPdf ) , bookPdf )
61- . Then ( "extract" )
62- . Then ( "clean" )
63- . Then ( "partition" )
64- . Then ( "summarize" )
65- . Then ( "gen_embeddings" )
66- . Then ( "save_records" )
67- . Build ( ) ;
68-
69- // Execute pipeline
70- Console . WriteLine ( "* Executing pipeline..." ) ;
71- await orchestrator . RunPipelineAsync ( pipeline ) ;
60+ var index = AnsiConsole . Ask < bool > ( "Do you want to index document?" ) ;
61+ if ( index )
62+ {
63+ Console . WriteLine ( "* Defining pipeline with 4 files..." ) ;
64+ var pipeline = orchestrator
65+ . PrepareNewDocumentUpload (
66+ index : "booksample" ,
67+ documentId : "booksample" ,
68+ new TagCollection { { "example" , "books" } } )
69+ . AddUploadFile ( "file1" , Path . GetFileName ( bookPdf ) , bookPdf )
70+ . Then ( "extract" )
71+ . Then ( "clean" )
72+ . Then ( "partition" )
73+ //.Then("summarize")
74+ . Then ( "gen_embeddings" )
75+ . Then ( "save_records" )
76+ . Build ( ) ;
77+
78+ // Execute pipeline
79+ Console . WriteLine ( "* Executing pipeline..." ) ;
80+ await orchestrator . RunPipelineAsync ( pipeline ) ;
81+ }
82+ string question ;
83+ do
84+ {
85+ Console . WriteLine ( "Ask a question to the kernel memory:" ) ;
86+ question = Console . ReadLine ( ) ;
87+ if ( ! string . IsNullOrWhiteSpace ( question ) )
88+ {
89+ var response = await kernelMemory . AskAsync ( question , index : "booksample" ) ;
90+ Console . WriteLine ( response . Result ) ;
91+ }
92+ } while ( ! string . IsNullOrWhiteSpace ( question ) ) ;
7293 }
7394
7495 private static IKernelMemoryBuilder CreateBasicKernelMemoryBuilder (
@@ -105,12 +126,12 @@ private static IKernelMemoryBuilder CreateBasicKernelMemoryBuilder(
105126 kernelMemoryBuilder
106127 . WithSimpleFileStorage ( new SimpleFileStorageConfig ( )
107128 {
108- Directory = "c:\\ temp\\ km \\ storage" ,
129+ Directory = "c:\\ temp\\ km2 \\ storage" ,
109130 StorageType = FileSystemTypes . Disk
110131 } )
111132 . WithSimpleVectorDb ( new SimpleVectorDbConfig ( )
112133 {
113- Directory = "c:\\ temp\\ km \\ vectorstorage" ,
134+ Directory = "c:\\ temp\\ km2 \\ vectorstorage" ,
114135 StorageType = FileSystemTypes . Disk
115136 } ) ;
116137
0 commit comments