Skip to content

Commit

Permalink
feat: Support output dimensionality in Google AI Embeddings (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored Apr 10, 2024
1 parent d254f92 commit 6dcb27d
Show file tree
Hide file tree
Showing 8 changed files with 1,795 additions and 1,696 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EmbedContentRequest with _$EmbedContentRequest {
/// Required. The content to embed. Only the `parts.text` fields will be counted.
@JsonKey(includeIfNull: false) Content? content,

/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001`.
/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001` or newer models.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
Expand All @@ -30,6 +30,9 @@ class EmbedContentRequest with _$EmbedContentRequest {

/// Required. The model's resource name. This serves as an ID for the Model to use. This name should match a model name returned by the `ListModels` method. Format: `models/{model}`
@JsonKey(includeIfNull: false) String? model,

/// Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024, and the earlier model (`models/embedding-001`) cannot specify this value.
@JsonKey(includeIfNull: false) int? outputDimensionality,
}) = _EmbedContentRequest;

/// Object construction from a JSON representation
Expand All @@ -41,7 +44,8 @@ class EmbedContentRequest with _$EmbedContentRequest {
'title',
'content',
'taskType',
'model'
'model',
'outputDimensionality'
];

/// Perform validations on the schema property values
Expand All @@ -56,6 +60,7 @@ class EmbedContentRequest with _$EmbedContentRequest {
'content': content,
'taskType': taskType,
'model': model,
'outputDimensionality': outputDimensionality,
};
}
}
Expand All @@ -64,7 +69,7 @@ class EmbedContentRequest with _$EmbedContentRequest {
// ENUM: EmbedContentRequestTaskType
// ==========================================

/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001`.
/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001` or newer models.
enum EmbedContentRequestTaskType {
@JsonValue('TASK_TYPE_UNSPECIFIED')
taskTypeUnspecified,
Expand All @@ -78,4 +83,8 @@ enum EmbedContentRequestTaskType {
classification,
@JsonValue('CLUSTERING')
clustering,
@JsonValue('QUESTION_ANSWERING')
questionAnswering,
@JsonValue('FACT_VERIFICATION')
factVerification,
}
51 changes: 41 additions & 10 deletions packages/googleai_dart/lib/src/generated/schema/schema.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4044,7 +4044,7 @@ mixin _$EmbedContentRequest {
@JsonKey(includeIfNull: false)
Content? get content => throw _privateConstructorUsedError;

/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001`.
/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001` or newer models.
@JsonKey(
includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
EmbedContentRequestTaskType? get taskType =>
Expand All @@ -4054,6 +4054,10 @@ mixin _$EmbedContentRequest {
@JsonKey(includeIfNull: false)
String? get model => throw _privateConstructorUsedError;

/// Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024, and the earlier model (`models/embedding-001`) cannot specify this value.
@JsonKey(includeIfNull: false)
int? get outputDimensionality => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$EmbedContentRequestCopyWith<EmbedContentRequest> get copyWith =>
Expand All @@ -4073,7 +4077,8 @@ abstract class $EmbedContentRequestCopyWith<$Res> {
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
EmbedContentRequestTaskType? taskType,
@JsonKey(includeIfNull: false) String? model});
@JsonKey(includeIfNull: false) String? model,
@JsonKey(includeIfNull: false) int? outputDimensionality});

$ContentCopyWith<$Res>? get content;
}
Expand All @@ -4095,6 +4100,7 @@ class _$EmbedContentRequestCopyWithImpl<$Res, $Val extends EmbedContentRequest>
Object? content = freezed,
Object? taskType = freezed,
Object? model = freezed,
Object? outputDimensionality = freezed,
}) {
return _then(_value.copyWith(
title: freezed == title
Expand All @@ -4113,6 +4119,10 @@ class _$EmbedContentRequestCopyWithImpl<$Res, $Val extends EmbedContentRequest>
? _value.model
: model // ignore: cast_nullable_to_non_nullable
as String?,
outputDimensionality: freezed == outputDimensionality
? _value.outputDimensionality
: outputDimensionality // ignore: cast_nullable_to_non_nullable
as int?,
) as $Val);
}

Expand Down Expand Up @@ -4144,7 +4154,8 @@ abstract class _$$EmbedContentRequestImplCopyWith<$Res>
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
EmbedContentRequestTaskType? taskType,
@JsonKey(includeIfNull: false) String? model});
@JsonKey(includeIfNull: false) String? model,
@JsonKey(includeIfNull: false) int? outputDimensionality});

@override
$ContentCopyWith<$Res>? get content;
Expand All @@ -4165,6 +4176,7 @@ class __$$EmbedContentRequestImplCopyWithImpl<$Res>
Object? content = freezed,
Object? taskType = freezed,
Object? model = freezed,
Object? outputDimensionality = freezed,
}) {
return _then(_$EmbedContentRequestImpl(
title: freezed == title
Expand All @@ -4183,6 +4195,10 @@ class __$$EmbedContentRequestImplCopyWithImpl<$Res>
? _value.model
: model // ignore: cast_nullable_to_non_nullable
as String?,
outputDimensionality: freezed == outputDimensionality
? _value.outputDimensionality
: outputDimensionality // ignore: cast_nullable_to_non_nullable
as int?,
));
}
}
Expand All @@ -4197,7 +4213,8 @@ class _$EmbedContentRequestImpl extends _EmbedContentRequest {
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
this.taskType,
@JsonKey(includeIfNull: false) this.model})
@JsonKey(includeIfNull: false) this.model,
@JsonKey(includeIfNull: false) this.outputDimensionality})
: super._();

factory _$EmbedContentRequestImpl.fromJson(Map<String, dynamic> json) =>
Expand All @@ -4213,7 +4230,7 @@ class _$EmbedContentRequestImpl extends _EmbedContentRequest {
@JsonKey(includeIfNull: false)
final Content? content;

/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001`.
/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001` or newer models.
@override
@JsonKey(
includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
Expand All @@ -4224,9 +4241,14 @@ class _$EmbedContentRequestImpl extends _EmbedContentRequest {
@JsonKey(includeIfNull: false)
final String? model;

/// Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024, and the earlier model (`models/embedding-001`) cannot specify this value.
@override
@JsonKey(includeIfNull: false)
final int? outputDimensionality;

@override
String toString() {
return 'EmbedContentRequest(title: $title, content: $content, taskType: $taskType, model: $model)';
return 'EmbedContentRequest(title: $title, content: $content, taskType: $taskType, model: $model, outputDimensionality: $outputDimensionality)';
}

@override
Expand All @@ -4238,12 +4260,15 @@ class _$EmbedContentRequestImpl extends _EmbedContentRequest {
(identical(other.content, content) || other.content == content) &&
(identical(other.taskType, taskType) ||
other.taskType == taskType) &&
(identical(other.model, model) || other.model == model));
(identical(other.model, model) || other.model == model) &&
(identical(other.outputDimensionality, outputDimensionality) ||
other.outputDimensionality == outputDimensionality));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, title, content, taskType, model);
int get hashCode => Object.hash(
runtimeType, title, content, taskType, model, outputDimensionality);

@JsonKey(ignore: true)
@override
Expand All @@ -4268,7 +4293,8 @@ abstract class _EmbedContentRequest extends EmbedContentRequest {
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
final EmbedContentRequestTaskType? taskType,
@JsonKey(includeIfNull: false) final String? model}) =
@JsonKey(includeIfNull: false) final String? model,
@JsonKey(includeIfNull: false) final int? outputDimensionality}) =
_$EmbedContentRequestImpl;
const _EmbedContentRequest._() : super._();

Expand All @@ -4287,7 +4313,7 @@ abstract class _EmbedContentRequest extends EmbedContentRequest {
Content? get content;
@override

/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001`.
/// Optional. Optional task type for which the embeddings will be used. Can only be set for `models/embedding-001` or newer models.
@JsonKey(
includeIfNull: false, unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
EmbedContentRequestTaskType? get taskType;
Expand All @@ -4297,6 +4323,11 @@ abstract class _EmbedContentRequest extends EmbedContentRequest {
@JsonKey(includeIfNull: false)
String? get model;
@override

/// Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024, and the earlier model (`models/embedding-001`) cannot specify this value.
@JsonKey(includeIfNull: false)
int? get outputDimensionality;
@override
@JsonKey(ignore: true)
_$$EmbedContentRequestImplCopyWith<_$EmbedContentRequestImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
4 changes: 4 additions & 0 deletions packages/googleai_dart/lib/src/generated/schema/schema.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6dcb27d

Please sign in to comment.