Skip to content

Commit a606be8

Browse files
committed
Corrections for instructions
1 parent 7a3bfd2 commit a606be8

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

03-CoreGenerativeAITechniques/02-retrieval-augmented-generation.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ You may have heard of vector databases. These are databases that store data in a
3636
We'll use the Microsoft.Extension.AI along with the [Microsoft.Extensions.VectorData](https://www.nuget.org/packages/Microsoft.Extensions.VectorData.Abstractions/) and [Microsoft.SemanticKernel.Connectors.InMemory](https://www.nuget.org/packages/Microsoft.SemanticKernel.Connectors.InMemory) libraries to implement RAG below.
3737

3838
> 🧑‍💻**Sample code:** You can follow along with the [sample code here](./src/RAGSimple-02MEAIVectorsMemory/).
39-
>
39+
>
4040
> You can also see how to implement a RAG app [using Semantic Kernel by itself in our sample source code here](./src/RAGSimple-01SK/).
4141
>
4242
> We have additional RAG examples for different vector stores and models:
43+
>
4344
> - [RAGSimple-03MEAIVectorsAISearch](./src/RAGSimple-03MEAIVectorsAISearch/) - Using Azure AI Search as a vector store
4445
> - [RAGSimple-04MEAIVectorsQdrant](./src/RAGSimple-04MEAIVectorsQdrant/) - Using Qdrant as a vector store
4546
> - [RAGSimple-10SKOllama](./src/RAGSimple-10SKOllama/) - Using Semantic Kernel with Ollama
@@ -52,16 +53,16 @@ We'll use the Microsoft.Extension.AI along with the [Microsoft.Extensions.Vector
5253
```csharp
5354
public class Movie
5455
{
55-
[VectorStoreRecordKey]
56+
[VectorStoreKey]
5657
public int Key { get; set; }
5758

58-
[VectorStoreRecordData]
59+
[VectorStoreData]
5960
public string Title { get; set; }
6061

61-
[VectorStoreRecordData]
62+
[VectorStoreData]
6263
public string Description { get; set; }
6364

64-
[VectorStoreRecordVector(384, DistanceFunction.CosineSimilarity)]
65+
[VectorStoreVector(384, DistanceFunction = DistanceFunction.CosineSimilarity)]
6566
public ReadOnlyMemory<float> Vector { get; set; }
6667
}
6768
```
@@ -75,16 +76,14 @@ We'll use the Microsoft.Extension.AI along with the [Microsoft.Extensions.Vector
7576

7677
// get movie list
7778
var movies = vectorStore.GetCollection<int, MovieVector<int>>("movies");
78-
await movies.CreateCollectionIfNotExistsAsync();
79+
await movies.EnsureCollectionExistsAsync();
7980
var movieData = MovieFactory<int>.GetMovieVectorList();
8081

8182
```
8283

8384
3. Our next task then is to convert our knowledge store (the `movieData` object) into embeddings and then store them into the in-memory vector store. When we create the embeddings we'll use a different model - an embeddings model instead of a language model.
8485

8586
```csharp
86-
var endpoint = new Uri("https://models.inference.ai.azure.com");
87-
var modelId = "text-embedding-3-small";
8887
// get embeddings generator and generate embeddings for movies
8988
IEmbeddingGenerator<string, Embedding<float>> generator =
9089
new OllamaEmbeddingGenerator(new Uri("http://localhost:11434/"), "all-minilm");
@@ -107,14 +106,9 @@ We'll use the Microsoft.Extension.AI along with the [Microsoft.Extensions.Vector
107106
// generate the embedding vector for the user's prompt
108107
var query = "A family friendly movie that includes ogres and dragons";
109108
var queryEmbedding = await generator.GenerateVectorAsync(query);
110-
var searchOptions = new VectorSearchOptions()
111-
{
112-
Top = 2,
113-
VectorPropertyName = "Vector"
114-
};
115109

116110
// search the knowledge store based on the user's prompt
117-
var results = await movies.VectorizedSearchAsync(queryEmbedding, searchOptions);
111+
var results = movies.SearchAsync(queryEmbedding, 2, new VectorSearchOptions<MovieVector<int>>());
118112

119113
// let's see the results just so we know what they look like
120114
await foreach (var result in results.Results)
@@ -136,7 +130,7 @@ So we could do something like the following while looping through the results of
136130

137131
```csharp
138132

139-
// assuming chatClient is instatiated as before to a language model
133+
// assuming chatClient is instantiated as before to a language model
140134
// assuming the vector search is done as above
141135
// assuming List<ChatMessage> conversation object is already instantiated and has a system prompt
142136
@@ -157,7 +151,7 @@ var response = await chatClient.GetResponseAsync(conversation);
157151
conversation.Add(new ChatMessage(ChatRole.Assistant, response.Message));
158152

159153
//display the conversation
160-
Console.WriteLine($"Bot:> {response.Message.Text});
154+
Console.WriteLine($"Bot:> {response.Message.Text}");
161155
```
162156

163157
> 🙋 **Need help?**: If you encounter any issues, [open an issue in the repository](https://github.com/microsoft/Generative-AI-for-beginners-dotnet/issues/new).

0 commit comments

Comments
 (0)