var text = """ some content """; await memory.ImportTextAsync(text);
还有一种就是直接导入URL,这种方式会自动从URL中获取内容。
1 2
var url = "https://raw.githubusercontent.com/microsoft/kernel-memory/main/README.md"; await memory.ImportWebPageAsync(url);
4. 问答和查询
文档导入完成之后,就可以进行问答或者查询了。
问答的话,只需要调用AskAsync方法即可。
1 2
var question = "What's Kernel Memory?"; var answer = await memory.AskAsync(question);
其中answer包含了答案的内容,以及相关文档以及相关度。
例如使用以下方式获取答案的内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Console.WriteLine(answer.Result + "\n"); foreach (var x in answer.RelevantSources) { Console.WriteLine($" * {x.SourceName} -- {x.Partitions.First().LastUpdate:D}"); } /* OUTPUT */ /* Kernel Memory is an open-source service and plugin specialized in the efficient indexing of datasets through custom continuous data hybrid pipelines. It enables natural language querying for obtaining answers from the indexed data, complete with citations and links to the original sources. Kernel Memory enhances data-driven features in applications built for popular AI platforms. It can be used as a library or as a Docker container. * content.url -- 2023年12月19日 * sample-SK-Readme.pdf -- 2023年12月19日 */
如果只想查询有哪些相关文档的话,可以使用SearchAsync 方法
1 2
var question = "What's Kernel Memory?"; var results = await memory.SearchAsync(question);