@@ -22,10 +22,11 @@ public static class Program
2222 private static readonly List < string > s_toDelete = new ( ) ;
2323
2424 // Change this to True and configure Azure Document Intelligence to test OCR and support for images
25- private const bool imageSupportDemoEnabled = false ;
25+ private const bool ImageSupportDemoEnabled = true ;
2626
2727 public static async Task Main ( )
2828 {
29+ var memoryConfiguration = new KernelMemoryConfig ( ) ;
2930 var openAIConfig = new OpenAIConfig ( ) ;
3031 var azureOpenAITextConfig = new AzureOpenAIConfig ( ) ;
3132 var azureOpenAIEmbeddingConfig = new AzureOpenAIConfig ( ) ;
@@ -39,6 +40,7 @@ public static async Task Main()
3940 . AddJsonFile ( "appsettings.json" )
4041 . AddJsonFile ( "appsettings.Development.json" , optional : true )
4142 . Build ( )
43+ . BindSection ( "KernelMemory" , memoryConfiguration )
4244 . BindSection ( "KernelMemory:Services:OpenAI" , openAIConfig )
4345 . BindSection ( "KernelMemory:Services:AzureOpenAIText" , azureOpenAITextConfig )
4446 . BindSection ( "KernelMemory:Services:AzureOpenAIEmbedding" , azureOpenAIEmbeddingConfig )
@@ -49,6 +51,7 @@ public static async Task Main()
4951 . BindSection ( "KernelMemory:Retrieval:SearchClient" , searchClientConfig ) ;
5052
5153 s_memory = new KernelMemoryBuilder ( )
54+ . AddSingleton ( memoryConfiguration )
5255 // .WithOpenAIDefaults(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))
5356 // .WithOpenAI(openAIConfig)
5457 . WithAzureOpenAITextGeneration ( azureOpenAITextConfig , new DefaultGPTTokenizer ( ) )
@@ -97,6 +100,8 @@ public static async Task Main()
97100 // =======================
98101
99102 await DeleteMemories ( ) ;
103+
104+ Console . WriteLine ( "\n # DONE" ) ;
100105 }
101106
102107 // =======================
@@ -111,25 +116,28 @@ private static async Task StoreText()
111116 "in a system's rest frame, where the two quantities differ only by a multiplicative " +
112117 "constant and the units of measurement. The principle is described by the physicist " +
113118 "Albert Einstein's formula: E = m*c^2" ) ;
119+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
114120 s_toDelete . Add ( docId ) ;
115121 }
116122
117123 // Simple file upload, with document ID
118124 private static async Task StoreFile ( )
119125 {
120126 Console . WriteLine ( "Uploading article file about Carbon" ) ;
121- await s_memory . ImportDocumentAsync ( "file1-Wikipedia-Carbon.txt" , documentId : "doc001" ) ;
122- s_toDelete . Add ( "doc001" ) ;
127+ var docId = await s_memory . ImportDocumentAsync ( "file1-Wikipedia-Carbon.txt" , documentId : "doc001" ) ;
128+ s_toDelete . Add ( docId ) ;
129+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
123130 }
124131
125132 // Extract memory from images (OCR required)
126133 private static async Task StoreImage ( )
127134 {
128- if ( ! imageSupportDemoEnabled ) { return ; }
135+ if ( ! ImageSupportDemoEnabled ) { return ; }
129136
130137 Console . WriteLine ( "Uploading Image file with a news about a conference sponsored by Microsoft" ) ;
131- await s_memory . ImportDocumentAsync ( new Document ( "img001" ) . AddFiles ( new [ ] { "file6-ANWC-image.jpg" } ) ) ;
132- s_toDelete . Add ( "img001" ) ;
138+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "img001" ) . AddFiles ( new [ ] { "file6-ANWC-image.jpg" } ) ) ;
139+ s_toDelete . Add ( docId ) ;
140+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
133141 }
134142
135143 // Uploading multiple files and adding a user tag, checking if the document already exists
@@ -138,9 +146,11 @@ private static async Task StoreMultipleFiles()
138146 if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "doc002" ) )
139147 {
140148 Console . WriteLine ( "Uploading a text file, a Word doc, and a PDF about Kernel Memory" ) ;
141- await s_memory . ImportDocumentAsync ( new Document ( "doc002" )
149+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "doc002" )
142150 . AddFiles ( new [ ] { "file2-Wikipedia-Moon.txt" , "file3-lorem-ipsum.docx" , "file4-KM-Readme.pdf" } )
143151 . AddTag ( "user" , "Blake" ) ) ;
152+ s_toDelete . Add ( docId ) ;
153+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
144154 }
145155 else
146156 {
@@ -156,13 +166,15 @@ private static async Task StoreFileWithMultipleTags()
156166 if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "doc003" ) )
157167 {
158168 Console . WriteLine ( "Uploading a PDF with a news about NASA and Orion" ) ;
159- await s_memory . ImportDocumentAsync ( new Document ( "doc003" )
169+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "doc003" )
160170 . AddFile ( "file5-NASA-news.pdf" )
161171 . AddTag ( "user" , "Taylor" )
162172 . AddTag ( "collection" , "meetings" )
163173 . AddTag ( "collection" , "NASA" )
164174 . AddTag ( "collection" , "space" )
165175 . AddTag ( "type" , "news" ) ) ;
176+ s_toDelete . Add ( docId ) ;
177+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
166178 }
167179 else
168180 {
@@ -178,7 +190,9 @@ private static async Task StoreWebPage()
178190 if ( ! await s_memory . IsDocumentReadyAsync ( "webPage1" ) )
179191 {
180192 Console . WriteLine ( "Uploading https://raw.githubusercontent.com/microsoft/kernel-memory/main/README.md" ) ;
181- await s_memory . ImportWebPageAsync ( "https://raw.githubusercontent.com/microsoft/kernel-memory/main/README.md" , documentId : "webPage1" ) ;
193+ var docId = await s_memory . ImportWebPageAsync ( "https://raw.githubusercontent.com/microsoft/kernel-memory/main/README.md" , documentId : "webPage1" ) ;
194+ s_toDelete . Add ( docId ) ;
195+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
182196 }
183197 else
184198 {
@@ -194,7 +208,9 @@ private static async Task StoreHTMLFile()
194208 if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "htmlDoc001" ) )
195209 {
196210 Console . WriteLine ( "Uploading a HTML file about Apache Submarine project" ) ;
197- await s_memory . ImportDocumentAsync ( new Document ( "htmlDoc001" ) . AddFile ( "file7-submarine.html" ) . AddTag ( "user" , "Ela" ) ) ;
211+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "htmlDoc001" ) . AddFile ( "file7-submarine.html" ) . AddTag ( "user" , "Ela" ) ) ;
212+ s_toDelete . Add ( docId ) ;
213+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
198214 }
199215 else
200216 {
@@ -210,9 +226,11 @@ private static async Task StoreWithCustomPipeline()
210226 if ( ! await s_memory . IsDocumentReadyAsync ( "webPage2" ) )
211227 {
212228 Console . WriteLine ( "Uploading https://raw.githubusercontent.com/microsoft/kernel-memory/main/docs/security/security-filters.md" ) ;
213- await s_memory . ImportWebPageAsync ( "https://raw.githubusercontent.com/microsoft/kernel-memory/main/docs/security/security-filters.md" ,
229+ var docId = await s_memory . ImportWebPageAsync ( "https://raw.githubusercontent.com/microsoft/kernel-memory/main/docs/security/security-filters.md" ,
214230 documentId : "webPage2" ,
215231 steps : Constants . PipelineWithoutSummary ) ;
232+ s_toDelete . Add ( docId ) ;
233+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
216234 }
217235 else
218236 {
@@ -228,7 +246,9 @@ private static async Task StoreExcel()
228246 if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "xls01" ) )
229247 {
230248 Console . WriteLine ( "Uploading Excel file with some empty cells" ) ;
231- await s_memory . ImportDocumentAsync ( new Document ( "xls01" ) . AddFiles ( new [ ] { "file8-data.xlsx" } ) ) ;
249+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "xls01" ) . AddFiles ( new [ ] { "file8-data.xlsx" } ) ) ;
250+ s_toDelete . Add ( docId ) ;
251+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
232252 }
233253 else
234254 {
@@ -244,7 +264,9 @@ private static async Task StoreJson()
244264 if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "json01" ) )
245265 {
246266 Console . WriteLine ( "Uploading JSON file" ) ;
247- await s_memory . ImportDocumentAsync ( new Document ( "json01" ) . AddFiles ( new [ ] { "file9-settings.json" } ) ) ;
267+ var docId = await s_memory . ImportDocumentAsync ( new Document ( "json01" ) . AddFiles ( new [ ] { "file9-settings.json" } ) ) ;
268+ s_toDelete . Add ( docId ) ;
269+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
248270 }
249271 else
250272 {
@@ -339,7 +361,7 @@ private static async Task AskQuestionAboutImageContent()
339361
340362 var answer = await s_memory . AskAsync ( question , minRelevance : 0.76 ) ;
341363
342- Console . WriteLine ( imageSupportDemoEnabled
364+ Console . WriteLine ( ImageSupportDemoEnabled
343365 ? $ "\n Answer: { answer . Result } \n \n Sources:\n "
344366 : $ "\n Answer (none expected): { answer . Result } \n \n Sources:\n ") ;
345367
0 commit comments