|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +using AzureAISearch.ConformanceTests.Support; |
| 4 | +using Microsoft.Extensions.VectorData; |
| 5 | +using VectorData.ConformanceTests.Xunit; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace AzureAISearch.ConformanceTests; |
| 9 | + |
| 10 | +public class AzureAISearchAllSupportedTypesTests(AzureAISearchFixture fixture) : IClassFixture<AzureAISearchFixture> |
| 11 | +{ |
| 12 | + [ConditionalFact] |
| 13 | + public async Task AllTypesBatchGetAsync() |
| 14 | + { |
| 15 | + var collection = fixture.TestStore.DefaultVectorStore.GetCollection<string, AzureAISearchAllTypes>("all-types", AzureAISearchAllTypes.GetRecordDefinition()); |
| 16 | + await collection.EnsureCollectionExistsAsync(); |
| 17 | + |
| 18 | + List<AzureAISearchAllTypes> records = |
| 19 | + [ |
| 20 | + new() |
| 21 | + { |
| 22 | + Id = "all-types-1", |
| 23 | + BoolProperty = true, |
| 24 | + NullableBoolProperty = false, |
| 25 | + StringProperty = "string prop 1", |
| 26 | + NullableStringProperty = "nullable prop 1", |
| 27 | + IntProperty = 1, |
| 28 | + NullableIntProperty = 10, |
| 29 | + LongProperty = 100L, |
| 30 | + NullableLongProperty = 1000L, |
| 31 | + FloatProperty = 10.5f, |
| 32 | + NullableFloatProperty = 100.5f, |
| 33 | + DoubleProperty = 23.75d, |
| 34 | + NullableDoubleProperty = 233.75d, |
| 35 | + DateTimeOffsetProperty = DateTimeOffset.UtcNow, |
| 36 | + NullableDateTimeOffsetProperty = DateTimeOffset.UtcNow, |
| 37 | + StringArray = ["one", "two"], |
| 38 | + StringList = ["eleven", "twelve"], |
| 39 | + BoolArray = [true, false], |
| 40 | + BoolList = [true, false], |
| 41 | + IntArray = [1, 2], |
| 42 | + IntList = [11, 12], |
| 43 | + LongArray = [100L, 200L], |
| 44 | + LongList = [1100L, 1200L], |
| 45 | + FloatArray = [1.5f, 2.5f], |
| 46 | + FloatList = [11.5f, 12.5f], |
| 47 | + DoubleArray = [1.5d, 2.5d], |
| 48 | + DoubleList = [11.5d, 12.5d], |
| 49 | + DateTimeOffsetArray = [DateTimeOffset.UtcNow, DateTimeOffset.UtcNow], |
| 50 | + DateTimeOffsetList = [DateTimeOffset.UtcNow, DateTimeOffset.UtcNow], |
| 51 | + Embedding = new ReadOnlyMemory<float>([1.5f, 2.5f, 3.5f, 4.5f, 5.5f, 6.5f, 7.5f, 8.5f]) |
| 52 | + }, |
| 53 | + new() |
| 54 | + { |
| 55 | + Id = "all-types-2", |
| 56 | + BoolProperty = false, |
| 57 | + NullableBoolProperty = null, |
| 58 | + StringProperty = "string prop 2", |
| 59 | + NullableStringProperty = null, |
| 60 | + IntProperty = 2, |
| 61 | + NullableIntProperty = null, |
| 62 | + LongProperty = 200L, |
| 63 | + NullableLongProperty = null, |
| 64 | + FloatProperty = 20.5f, |
| 65 | + NullableFloatProperty = null, |
| 66 | + DoubleProperty = 43.75, |
| 67 | + NullableDoubleProperty = null, |
| 68 | + Embedding = ReadOnlyMemory<float>.Empty, |
| 69 | + // From https://learn.microsoft.com/en-us/rest/api/searchservice/supported-data-types: |
| 70 | + // "All of the above types are nullable, except for collections of primitive and complex types, for example, Collection(Edm.String)" |
| 71 | + // So for collections, we can't use nulls. |
| 72 | + StringArray = [], |
| 73 | + StringList = [], |
| 74 | + BoolArray = [], |
| 75 | + BoolList = [], |
| 76 | + IntArray = [], |
| 77 | + IntList = [], |
| 78 | + LongArray = [], |
| 79 | + LongList = [], |
| 80 | + FloatArray = [], |
| 81 | + FloatList = [], |
| 82 | + DoubleArray = [], |
| 83 | + DoubleList = [], |
| 84 | + DateTimeOffsetArray = [], |
| 85 | + DateTimeOffsetList = [], |
| 86 | + } |
| 87 | + ]; |
| 88 | + |
| 89 | + try |
| 90 | + { |
| 91 | + await collection.UpsertAsync(records); |
| 92 | + |
| 93 | + var allTypes = await collection.GetAsync(records.Select(r => r.Id), new RecordRetrievalOptions { IncludeVectors = true }).ToListAsync(); |
| 94 | + |
| 95 | + var allTypes1 = allTypes.Single(x => x.Id == records[0].Id); |
| 96 | + var allTypes2 = allTypes.Single(x => x.Id == records[1].Id); |
| 97 | + |
| 98 | + records[0].AssertEqual(allTypes1); |
| 99 | + records[1].AssertEqual(allTypes2); |
| 100 | + } |
| 101 | + finally |
| 102 | + { |
| 103 | + await collection.EnsureCollectionDeletedAsync(); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments