@@ -431,4 +431,144 @@ public static void SetDataCompression(this IMutableIndex index, DataCompressionT
431431 /// <returns>The <see cref="ConfigurationSource" /> for the data compression the index uses.</returns>
432432 public static ConfigurationSource ? GetDataCompressionConfigurationSource ( this IConventionIndex index )
433433 => index . FindAnnotation ( SqlServerAnnotationNames . DataCompression ) ? . GetConfigurationSource ( ) ;
434+
435+ /// <summary>
436+ /// Returns whether the index is a vector index.
437+ /// </summary>
438+ /// <param name="index">The index.</param>
439+ /// <returns>Whether the index is a vector index.</returns>
440+ public static bool IsVectorIndex ( this IReadOnlyIndex index )
441+ => index is RuntimeIndex
442+ ? throw new InvalidOperationException ( CoreStrings . RuntimeModelMissingData )
443+ : index [ SqlServerAnnotationNames . VectorIndexMetric ] is not null ;
444+
445+ /// <summary>
446+ /// Returns the similarity metric for the vector index.
447+ /// </summary>
448+ /// <param name="index">The index.</param>
449+ /// <returns>The similarity metric for the vector index.</returns>
450+ public static string ? GetVectorMetric ( this IReadOnlyIndex index )
451+ => index is RuntimeIndex
452+ ? throw new InvalidOperationException ( CoreStrings . RuntimeModelMissingData )
453+ : ( string ? ) index [ SqlServerAnnotationNames . VectorIndexMetric ] ;
454+
455+ /// <summary>
456+ /// Returns the similarity metric for the vector index.
457+ /// </summary>
458+ /// <param name="index">The index.</param>
459+ /// <param name="storeObject">The identifier of the store object.</param>
460+ /// <returns>The similarity metric for the vector index.</returns>
461+ public static string ? GetVectorMetric ( this IReadOnlyIndex index , in StoreObjectIdentifier storeObject )
462+ {
463+ if ( index is RuntimeIndex )
464+ {
465+ throw new InvalidOperationException ( CoreStrings . RuntimeModelMissingData ) ;
466+ }
467+
468+ var annotation = index . FindAnnotation ( SqlServerAnnotationNames . VectorIndexMetric ) ;
469+ if ( annotation != null )
470+ {
471+ return ( string ? ) annotation . Value ;
472+ }
473+
474+ var sharedTableRootIndex = index . FindSharedObjectRootIndex ( storeObject ) ;
475+ return sharedTableRootIndex ? . GetVectorMetric ( storeObject ) ;
476+ }
477+
478+ /// <summary>
479+ /// Sets the similarity metric for the vector index.
480+ /// </summary>
481+ /// <param name="index">The index.</param>
482+ /// <param name="metric">The value to set.</param>
483+ public static void SetVectorMetric ( this IMutableIndex index , string ? metric )
484+ => index . SetAnnotation ( SqlServerAnnotationNames . VectorIndexMetric , metric ) ;
485+
486+ /// <summary>
487+ /// Sets the similarity metric for the vector index.
488+ /// </summary>
489+ /// <param name="index">The index.</param>
490+ /// <param name="metric">The value to set.</param>
491+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
492+ /// <returns>The configured value.</returns>
493+ public static string ? SetVectorMetric (
494+ this IConventionIndex index ,
495+ string ? metric ,
496+ bool fromDataAnnotation = false )
497+ => ( string ? ) index . SetAnnotation (
498+ SqlServerAnnotationNames . VectorIndexMetric ,
499+ metric ,
500+ fromDataAnnotation ) ? . Value ;
501+
502+ /// <summary>
503+ /// Returns the <see cref="ConfigurationSource" /> for the similarity metric of the vector index.
504+ /// </summary>
505+ /// <param name="index">The index.</param>
506+ /// <returns>The <see cref="ConfigurationSource" /> for the similarity metric of the vector index.</returns>
507+ public static ConfigurationSource ? GetVectorMetricConfigurationSource ( this IConventionIndex index )
508+ => index . FindAnnotation ( SqlServerAnnotationNames . VectorIndexMetric ) ? . GetConfigurationSource ( ) ;
509+
510+ /// <summary>
511+ /// Returns the type of the vector index.
512+ /// </summary>
513+ /// <param name="index">The index.</param>
514+ /// <returns>The type of the vector index.</returns>
515+ public static string ? GetVectorIndexType ( this IReadOnlyIndex index )
516+ => ( index is RuntimeIndex )
517+ ? throw new InvalidOperationException ( CoreStrings . RuntimeModelMissingData )
518+ : ( string ? ) index [ SqlServerAnnotationNames . VectorIndexType ] ;
519+
520+ /// <summary>
521+ /// Returns the type of the vector index.
522+ /// </summary>
523+ /// <param name="index">The index.</param>
524+ /// <param name="storeObject">The identifier of the store object.</param>
525+ /// <returns>The type of the vector index.</returns>
526+ public static string ? GetVectorIndexType ( this IReadOnlyIndex index , in StoreObjectIdentifier storeObject )
527+ {
528+ if ( index is RuntimeIndex )
529+ {
530+ throw new InvalidOperationException ( CoreStrings . RuntimeModelMissingData ) ;
531+ }
532+
533+ var annotation = index . FindAnnotation ( SqlServerAnnotationNames . VectorIndexType ) ;
534+ if ( annotation != null )
535+ {
536+ return ( string ? ) annotation . Value ;
537+ }
538+
539+ var sharedTableRootIndex = index . FindSharedObjectRootIndex ( storeObject ) ;
540+ return sharedTableRootIndex ? . GetVectorIndexType ( storeObject ) ;
541+ }
542+
543+ /// <summary>
544+ /// Sets the type of the vector index.
545+ /// </summary>
546+ /// <param name="index">The index.</param>
547+ /// <param name="type">The value to set.</param>
548+ public static void SetVectorIndexType ( this IMutableIndex index , string ? type )
549+ => index . SetAnnotation ( SqlServerAnnotationNames . VectorIndexType , type ) ;
550+
551+ /// <summary>
552+ /// Sets the type of the vector index.
553+ /// </summary>
554+ /// <param name="index">The index.</param>
555+ /// <param name="type">The value to set.</param>
556+ /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
557+ /// <returns>The configured value.</returns>
558+ public static string ? SetVectorIndexType (
559+ this IConventionIndex index ,
560+ string ? type ,
561+ bool fromDataAnnotation = false )
562+ => ( string ? ) index . SetAnnotation (
563+ SqlServerAnnotationNames . VectorIndexType ,
564+ type ,
565+ fromDataAnnotation ) ? . Value ;
566+
567+ /// <summary>
568+ /// Returns the <see cref="ConfigurationSource" /> for the type of the vector index.
569+ /// </summary>
570+ /// <param name="index">The index.</param>
571+ /// <returns>The <see cref="ConfigurationSource" /> for the type of the vector index.</returns>
572+ public static ConfigurationSource ? GetVectorIndexTypeConfigurationSource ( this IConventionIndex index )
573+ => index . FindAnnotation ( SqlServerAnnotationNames . VectorIndexType ) ? . GetConfigurationSource ( ) ;
434574}
0 commit comments