Repository navigation
.Net MEVD: Strongly-typed vector property selector - #10793
Adam Sitnik (adamsitnik) wants to merge 4 commits into
Conversation
…o vectorSearchSelector # Conflicts: # dotnet/src/Connectors/Connectors.AzureAISearch.UnitTests/AzureAISearchVectorStoreRecordCollectionTests.cs # dotnet/src/Connectors/Connectors.Weaviate.UnitTests/WeaviateVectorStoreRecordCollectionQueryBuilderTests.cs # dotnet/src/IntegrationTests/Connectors/Memory/AzureAISearch/AzureAISearchVectorStoreRecordCollectionTests.cs # dotnet/src/VectorDataIntegrationTests/VectorDataIntegrationTests/Filter/BasicFilterTests.cs
|
Shay Rojansky (@roji) westey (@westey-m) Damn, it's late and it seems that one test is failing. I am going to fix it tomorrow and ask you for review again. |
Shay Rojansky (roji)
left a comment
There was a problem hiding this comment.
Thanks Adam Sitnik (@adamsitnik), looks great.
| { | ||
| Verify.NotNull(vector); | ||
|
|
||
| if (this._propertyReader.FirstVectorPropertyName is null) |
There was a problem hiding this comment.
I've removed this and similar guards from other types as the methods exposed by PropertyReader will simply throw in such cases.
There was a problem hiding this comment.
Yeah, I have similar changes in my Hybrid search PR as well, so we'll have to do some merging
5de40f6 to
bb801b5
Compare
| { | ||
| IncludeVectors = includeVectors, | ||
| VectorPropertyName = "DescriptionEmbedding", | ||
| VectorProperty = r => "DescriptionEmbedding", |
There was a problem hiding this comment.
| VectorProperty = r => "DescriptionEmbedding", | |
| VectorProperty = r => r.DescriptionEmbedding, |
| new() | ||
| { | ||
| VectorPropertyName = "DescriptionEmbedding", | ||
| VectorProperty = r => "DescriptionEmbedding", |
There was a problem hiding this comment.
| VectorProperty = r => "DescriptionEmbedding", | |
| VectorProperty = r => r.DescriptionEmbedding, |
There was a problem hiding this comment.
I see a few other tests are also returning a string instead of selecting the prop
| throw new InvalidOperationException($"The property {property.Name} of {typeof(TRecord).FullName} is not a Vector property."); | ||
| } | ||
|
|
||
| throw new InvalidOperationException("The expression must be a a valid Vector property access."); |
There was a problem hiding this comment.
| throw new InvalidOperationException("The expression must be a a valid Vector property access."); | |
| throw new InvalidOperationException("The expression must be a a valid Vector property accessor."); |
| #pragma warning restore CS0618 // Type or member is obsolete | ||
| if (!string.IsNullOrEmpty(obsoletePropertyName)) | ||
| { | ||
| return obsoletePropertyName!; |
There was a problem hiding this comment.
We are missing some validation here, to ensure that the name is actually referring to a vector property.
In some connectors I see we are subsequently calling GetProperty, but it would only check that the property exists, not that it is a vector. Not checking upfront might lead to poor error messaging later if we just pass the name down to the SDK and let it throw.
In my branch I'm adding a propertyreader method that deals with this checking, so we could hold off until mine is merged and then use that here too.
| #pragma warning restore CS0618 // Type or member is obsolete | ||
| }; | ||
|
|
||
| Assert.Equal(ExpectedName, sut.GetVectorPropertyName(searchOptions)); |
There was a problem hiding this comment.
This should actually fail in the same way that it would if using the property selection expression.
| } | ||
| } | ||
|
|
||
| return this._vectorProperties.Count > 0 |
There was a problem hiding this comment.
We want to throw here if the user didn't specify a property and more than 1 exists. This is a change from the current behavior, but I'm adding it to my change doc.
| } | ||
|
|
||
| [Fact] | ||
| public void GetVectorPropertyNameReturnsFirstVectorPropertyWhenNoPropertySpecified() |
There was a problem hiding this comment.
This should actually fail, since first is not necessarily deterministic.
| if (!this._storagePropertyNames.TryGetValue(vectorDataModelPropertyName, out var vectorPropertyName)) | ||
| { | ||
| throw new InvalidOperationException("The collection does not have any vector properties, so vector search is not possible."); | ||
| throw new InvalidOperationException($"The collection does not have a vector field named '{vectorDataModelPropertyName}'."); |
There was a problem hiding this comment.
It would be nice to just verify this in GetVectorPropertyName.
| var vectorProperty = this._propertyReader.GetProperty<VectorStoreRecordVectorProperty>(this._propertyReader.GetVectorPropertyName(internalOptions)); | ||
| var vectorPropertyName = vectorProperty.DataModelPropertyName; |
There was a problem hiding this comment.
this._propertyReader.GetVectorPropertyName(internalOptions) already returns DataModelPropertyName. However in GetVectorPropertyName we are typically looking through the list if Properties to get the right vector property.
Consider just returning the vector property from GetVectorPropertyName and then the caller can read its DataModelPropertyName or whatever other property is required.
…o vectorSearchSelector # Conflicts: # dotnet/src/Connectors/VectorData.Abstractions/VectorSearch/VectorSearchOptions.cs
| /// </value> | ||
| public string? VectorPropertyName { get; init; } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
Adam Sitnik (@adamsitnik) did I see correctly that you removed the [Obsolete] from VectorPropertyName just above? Don't we want to obsolete it?
There was a problem hiding this comment.
Shay Rojansky (@roji) great catch! It must have been removed during the merge (xml docs were updated), I am going to add it back of course.
|
Closing, I've sent a new PR for that that handles HybridSerarch as well: #10850 |
The property selector can return a property:
fixes #10420