-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
38 lines (30 loc) · 1.11 KB
/
Program.cs
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
#pragma warning disable
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Extensions.VectorData;
using Microsoft.ML.Tokenizers;
using Microsoft.SemanticKernel.Connectors.InMemory;
// Initialize tokenizer and model
var tokenizer = BertTokenizer.Create(Path.Join("assets", "vocab.txt"));
// Create embedding generator
var generator = new MLNETOnnxEmbeddingGenerator(tokenizer, Path.Join("assets","model.onnx"));
// Initialize movie service
var movieService = new MovieService(new InMemoryVectorStore(), generator);
// Populate VectorStore
await movieService.LoadAsync();
var query = "A family friendly movie";
// Search for movies similar to the query
var searchOptions = new VectorSearchOptions()
{
Top = 1,
VectorPropertyName = "Vector"
};
var results = await movieService.SearchAsync(query, searchOptions);
// Display search results
await foreach(var result in results.Results)
{
Console.WriteLine($"Title: {result.Record.Details.Title}");
Console.WriteLine($"Description: {result.Record.Details.Description}");
Console.WriteLine($"Score: {result.Score}");
Console.WriteLine();
}