You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Redis OM .NET also supports storing and querying Vectors stored in Redis.
294
+
295
+
A `Vector<T>` is a representation of an object that can be transformed into a vector by a Vectorizer.
296
+
297
+
A `VectorizerAttribute` is the abstract class you use to decorate your Vector fields, it is responsible for defining the logic to convert the object's that `Vector<T>` is a container for into actual vector embeddings needed. In the package `Redis.OM.Vectorizers` we provide vectorizers for HuggingFace, OpenAI, and AzureOpenAI to allow you to easily integrate them into your workflows.
298
+
299
+
#### Define a Vector in your Model.
300
+
301
+
To define a vector in your model, simply decorate a `Vector<T>` field with an `Indexed` attribute which defines the algorithm and algorithmic parameters and a `Vectorizer` attribute which defines the shape of the vectors, (in this case we'll use OpenAI):
With the vector defined in our model, all we need to do is create Vectors of the generic type, and insert them with our model. Using our `RedisCollection`, you can do this by simply using `Insert`:
Prompt=Vector.Of("What is the Capital of France?"),
334
+
Response="Paris",
335
+
TimeStamp=DateTime.Now-TimeSpan.FromHours(3)
336
+
};
337
+
collection.Insert(completionResult);
338
+
```
339
+
340
+
The Vectorizer will manage the embedding generation for you without you having to intervene.
341
+
342
+
#### Query Vectors in Redis
343
+
344
+
To query vector fields in Redis, all you need to do is use the `VectorRange` method on a vector within our normal LINQ queries, and/or use the `NearestNeighbors` with whatever other filters you want to use, here's some examples:
345
+
346
+
```cs
347
+
varprompt="What really is the Capital of France?";
With Redis OM, the embeddings can be completely transparent to you, they are generated and bound to the `Vector<T>` when you query/insert your vectors. If however you needed your embedding after the insertion/Query, they are available at `Vector<T>.Embedding`, and be queried either as the raw bytes, as an array of doubles or as an array of floats (depending on your vectorizer).
366
+
367
+
#### Configuration
368
+
369
+
The Vectorizers provided by the `Redis.OM.Vectorizers` package have some configuration parameters that it will pull in either from your `appsettings.json` file, or your environment variables (with your appsettings taking precedence).
Redis OM also provides the ability to use Semantic Caching, as well as providers for OpenAI, HuggingFace, and Azure OpenAI to perform semantic caching. To use a Semantic Cache, simply pull one out of the RedisConnectionProvider and use `Store` to insert items, and `GetSimilar` to retrieve items. For example:
cache.Store("What is the capital of France?", "Paris");
387
+
varres=cache.GetSimilar("What really is the capital of France?").First();
388
+
```
389
+
390
+
### ML.NET Based Vectorizers
391
+
392
+
We also provide the packages `Redis.OM.Vectorizers.ResNet18` and `Redis.OM.Vectorizers.AllMiniLML6V2` which have embedded models / ML Pipelines in them to
393
+
allow you to easily Vectorize Images and Sentences respectively without the need to depend on an external API.
394
+
291
395
### 🖩 Aggregations
292
396
293
397
We can also run aggregations on the customer object, again using expressions in LINQ:
0 commit comments