@@ -22,10 +22,11 @@ public static class Program
22
22
private static readonly List < string > s_toDelete = new ( ) ;
23
23
24
24
// 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 ;
26
26
27
27
public static async Task Main ( )
28
28
{
29
+ var memoryConfiguration = new KernelMemoryConfig ( ) ;
29
30
var openAIConfig = new OpenAIConfig ( ) ;
30
31
var azureOpenAITextConfig = new AzureOpenAIConfig ( ) ;
31
32
var azureOpenAIEmbeddingConfig = new AzureOpenAIConfig ( ) ;
@@ -39,6 +40,7 @@ public static async Task Main()
39
40
. AddJsonFile ( "appsettings.json" )
40
41
. AddJsonFile ( "appsettings.Development.json" , optional : true )
41
42
. Build ( )
43
+ . BindSection ( "KernelMemory" , memoryConfiguration )
42
44
. BindSection ( "KernelMemory:Services:OpenAI" , openAIConfig )
43
45
. BindSection ( "KernelMemory:Services:AzureOpenAIText" , azureOpenAITextConfig )
44
46
. BindSection ( "KernelMemory:Services:AzureOpenAIEmbedding" , azureOpenAIEmbeddingConfig )
@@ -49,6 +51,7 @@ public static async Task Main()
49
51
. BindSection ( "KernelMemory:Retrieval:SearchClient" , searchClientConfig ) ;
50
52
51
53
s_memory = new KernelMemoryBuilder ( )
54
+ . AddSingleton ( memoryConfiguration )
52
55
// .WithOpenAIDefaults(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))
53
56
// .WithOpenAI(openAIConfig)
54
57
. WithAzureOpenAITextGeneration ( azureOpenAITextConfig , new DefaultGPTTokenizer ( ) )
@@ -97,6 +100,8 @@ public static async Task Main()
97
100
// =======================
98
101
99
102
await DeleteMemories ( ) ;
103
+
104
+ Console . WriteLine ( "\n # DONE" ) ;
100
105
}
101
106
102
107
// =======================
@@ -111,25 +116,28 @@ private static async Task StoreText()
111
116
"in a system's rest frame, where the two quantities differ only by a multiplicative " +
112
117
"constant and the units of measurement. The principle is described by the physicist " +
113
118
"Albert Einstein's formula: E = m*c^2" ) ;
119
+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
114
120
s_toDelete . Add ( docId ) ;
115
121
}
116
122
117
123
// Simple file upload, with document ID
118
124
private static async Task StoreFile ( )
119
125
{
120
126
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 } ") ;
123
130
}
124
131
125
132
// Extract memory from images (OCR required)
126
133
private static async Task StoreImage ( )
127
134
{
128
- if ( ! imageSupportDemoEnabled ) { return ; }
135
+ if ( ! ImageSupportDemoEnabled ) { return ; }
129
136
130
137
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 } ") ;
133
141
}
134
142
135
143
// Uploading multiple files and adding a user tag, checking if the document already exists
@@ -138,9 +146,11 @@ private static async Task StoreMultipleFiles()
138
146
if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "doc002" ) )
139
147
{
140
148
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" )
142
150
. AddFiles ( new [ ] { "file2-Wikipedia-Moon.txt" , "file3-lorem-ipsum.docx" , "file4-KM-Readme.pdf" } )
143
151
. AddTag ( "user" , "Blake" ) ) ;
152
+ s_toDelete . Add ( docId ) ;
153
+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
144
154
}
145
155
else
146
156
{
@@ -156,13 +166,15 @@ private static async Task StoreFileWithMultipleTags()
156
166
if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "doc003" ) )
157
167
{
158
168
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" )
160
170
. AddFile ( "file5-NASA-news.pdf" )
161
171
. AddTag ( "user" , "Taylor" )
162
172
. AddTag ( "collection" , "meetings" )
163
173
. AddTag ( "collection" , "NASA" )
164
174
. AddTag ( "collection" , "space" )
165
175
. AddTag ( "type" , "news" ) ) ;
176
+ s_toDelete . Add ( docId ) ;
177
+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
166
178
}
167
179
else
168
180
{
@@ -178,7 +190,9 @@ private static async Task StoreWebPage()
178
190
if ( ! await s_memory . IsDocumentReadyAsync ( "webPage1" ) )
179
191
{
180
192
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 } ") ;
182
196
}
183
197
else
184
198
{
@@ -194,7 +208,9 @@ private static async Task StoreHTMLFile()
194
208
if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "htmlDoc001" ) )
195
209
{
196
210
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 } ") ;
198
214
}
199
215
else
200
216
{
@@ -210,9 +226,11 @@ private static async Task StoreWithCustomPipeline()
210
226
if ( ! await s_memory . IsDocumentReadyAsync ( "webPage2" ) )
211
227
{
212
228
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" ,
214
230
documentId : "webPage2" ,
215
231
steps : Constants . PipelineWithoutSummary ) ;
232
+ s_toDelete . Add ( docId ) ;
233
+ Console . WriteLine ( $ "- Document Id: { docId } ") ;
216
234
}
217
235
else
218
236
{
@@ -228,7 +246,9 @@ private static async Task StoreExcel()
228
246
if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "xls01" ) )
229
247
{
230
248
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 } ") ;
232
252
}
233
253
else
234
254
{
@@ -244,7 +264,9 @@ private static async Task StoreJson()
244
264
if ( ! await s_memory . IsDocumentReadyAsync ( documentId : "json01" ) )
245
265
{
246
266
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 } ") ;
248
270
}
249
271
else
250
272
{
@@ -339,7 +361,7 @@ private static async Task AskQuestionAboutImageContent()
339
361
340
362
var answer = await s_memory . AskAsync ( question , minRelevance : 0.76 ) ;
341
363
342
- Console . WriteLine ( imageSupportDemoEnabled
364
+ Console . WriteLine ( ImageSupportDemoEnabled
343
365
? $ "\n Answer: { answer . Result } \n \n Sources:\n "
344
366
: $ "\n Answer (none expected): { answer . Result } \n \n Sources:\n ") ;
345
367
0 commit comments