From c65cef04332e20be82129d0c49396485be683585 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:08:13 -0600 Subject: [PATCH] feat: Protos and autogen client for vector (#2027) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add VectorSearch API PiperOrigin-RevId: 617982192 Source-Link: https://github.com/googleapis/googleapis/commit/5e2ca445cd8fd09440fbc7d296fa9b3e78effb68 Source-Link: https://github.com/googleapis/googleapis-gen/commit/37fe0b159cf9611ecbcd4f08985d5e0b56bb0a4c Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzdmZTBiMTU5Y2Y5NjExZWNiY2Q0ZjA4OTg1ZDVlMGI1NmJiMGE0YyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: add Vector Index API PiperOrigin-RevId: 618867415 Source-Link: https://github.com/googleapis/googleapis/commit/277145d108819fa30fbed3a7cbbb50f91eb6155e Source-Link: https://github.com/googleapis/googleapis-gen/commit/adcd3076784b5ae4e53a7b9be15d7720c2c07de7 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWRjZDMwNzY3ODRiNWFlNGU1M2E3YjliZTE1ZDc3MjBjMmMwN2RlNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- dev/protos/admin_v1.json | 38 ++- dev/protos/firestore_admin_v1_proto_api.d.ts | 110 ++++++++- dev/protos/firestore_admin_v1_proto_api.js | 233 +++++++++++++++++- dev/protos/firestore_v1_proto_api.d.ts | 79 ++++++ dev/protos/firestore_v1_proto_api.js | 207 ++++++++++++++++ .../google/firestore/admin/v1/index.proto | 24 ++ dev/protos/google/firestore/v1/query.proto | 52 ++++ dev/protos/google/protobuf/descriptor.proto | 2 + dev/protos/v1.json | 53 ++++ dev/protos/v1beta1.json | 4 + types/firestore.d.ts | 12 +- 11 files changed, 804 insertions(+), 10 deletions(-) diff --git a/dev/protos/admin_v1.json b/dev/protos/admin_v1.json index bdebe2b50..a602e0320 100644 --- a/dev/protos/admin_v1.json +++ b/dev/protos/admin_v1.json @@ -349,7 +349,8 @@ "valueMode": { "oneof": [ "order", - "arrayConfig" + "arrayConfig", + "vectorConfig" ] } }, @@ -365,6 +366,10 @@ "arrayConfig": { "type": "ArrayConfig", "id": 3 + }, + "vectorConfig": { + "type": "VectorConfig", + "id": 4 } }, "nested": { @@ -380,6 +385,33 @@ "ARRAY_CONFIG_UNSPECIFIED": 0, "CONTAINS": 1 } + }, + "VectorConfig": { + "oneofs": { + "type": { + "oneof": [ + "flat" + ] + } + }, + "fields": { + "dimension": { + "type": "int32", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "flat": { + "type": "FlatIndex", + "id": 2 + } + }, + "nested": { + "FlatIndex": { + "fields": {} + } + } } } }, @@ -3283,6 +3315,10 @@ 1002, 1002 ], + [ + 9990, + 9990 + ], [ 9995, 9999 diff --git a/dev/protos/firestore_admin_v1_proto_api.d.ts b/dev/protos/firestore_admin_v1_proto_api.d.ts index 6348ee27b..8e7284cc5 100644 --- a/dev/protos/firestore_admin_v1_proto_api.d.ts +++ b/dev/protos/firestore_admin_v1_proto_api.d.ts @@ -605,6 +605,9 @@ export namespace google { /** IndexField arrayConfig */ arrayConfig?: (google.firestore.admin.v1.Index.IndexField.ArrayConfig|null); + + /** IndexField vectorConfig */ + vectorConfig?: (google.firestore.admin.v1.Index.IndexField.IVectorConfig|null); } /** Represents an IndexField. */ @@ -625,8 +628,11 @@ export namespace google { /** IndexField arrayConfig. */ public arrayConfig?: (google.firestore.admin.v1.Index.IndexField.ArrayConfig|null); + /** IndexField vectorConfig. */ + public vectorConfig?: (google.firestore.admin.v1.Index.IndexField.IVectorConfig|null); + /** IndexField valueMode. */ - public valueMode?: ("order"|"arrayConfig"); + public valueMode?: ("order"|"arrayConfig"|"vectorConfig"); /** * Creates an IndexField message from a plain object. Also converts values to their respective internal types. @@ -666,6 +672,108 @@ export namespace google { /** ArrayConfig enum. */ type ArrayConfig = "ARRAY_CONFIG_UNSPECIFIED"| "CONTAINS"; + + /** Properties of a VectorConfig. */ + interface IVectorConfig { + + /** VectorConfig dimension */ + dimension?: (number|null); + + /** VectorConfig flat */ + flat?: (google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex|null); + } + + /** Represents a VectorConfig. */ + class VectorConfig implements IVectorConfig { + + /** + * Constructs a new VectorConfig. + * @param [properties] Properties to set + */ + constructor(properties?: google.firestore.admin.v1.Index.IndexField.IVectorConfig); + + /** VectorConfig dimension. */ + public dimension: number; + + /** VectorConfig flat. */ + public flat?: (google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex|null); + + /** VectorConfig type. */ + public type?: "flat"; + + /** + * Creates a VectorConfig message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns VectorConfig + */ + public static fromObject(object: { [k: string]: any }): google.firestore.admin.v1.Index.IndexField.VectorConfig; + + /** + * Creates a plain object from a VectorConfig message. Also converts values to other types if specified. + * @param message VectorConfig + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.firestore.admin.v1.Index.IndexField.VectorConfig, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this VectorConfig to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for VectorConfig + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace VectorConfig { + + /** Properties of a FlatIndex. */ + interface IFlatIndex { + } + + /** Represents a FlatIndex. */ + class FlatIndex implements IFlatIndex { + + /** + * Constructs a new FlatIndex. + * @param [properties] Properties to set + */ + constructor(properties?: google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex); + + /** + * Creates a FlatIndex message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FlatIndex + */ + public static fromObject(object: { [k: string]: any }): google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex; + + /** + * Creates a plain object from a FlatIndex message. Also converts values to other types if specified. + * @param message FlatIndex + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FlatIndex to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FlatIndex + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + } } /** State enum. */ diff --git a/dev/protos/firestore_admin_v1_proto_api.js b/dev/protos/firestore_admin_v1_proto_api.js index d0ccf3092..18176d982 100644 --- a/dev/protos/firestore_admin_v1_proto_api.js +++ b/dev/protos/firestore_admin_v1_proto_api.js @@ -1627,6 +1627,7 @@ * @property {string|null} [fieldPath] IndexField fieldPath * @property {google.firestore.admin.v1.Index.IndexField.Order|null} [order] IndexField order * @property {google.firestore.admin.v1.Index.IndexField.ArrayConfig|null} [arrayConfig] IndexField arrayConfig + * @property {google.firestore.admin.v1.Index.IndexField.IVectorConfig|null} [vectorConfig] IndexField vectorConfig */ /** @@ -1668,17 +1669,25 @@ */ IndexField.prototype.arrayConfig = null; + /** + * IndexField vectorConfig. + * @member {google.firestore.admin.v1.Index.IndexField.IVectorConfig|null|undefined} vectorConfig + * @memberof google.firestore.admin.v1.Index.IndexField + * @instance + */ + IndexField.prototype.vectorConfig = null; + // OneOf field names bound to virtual getters and setters var $oneOfFields; /** * IndexField valueMode. - * @member {"order"|"arrayConfig"|undefined} valueMode + * @member {"order"|"arrayConfig"|"vectorConfig"|undefined} valueMode * @memberof google.firestore.admin.v1.Index.IndexField * @instance */ Object.defineProperty(IndexField.prototype, "valueMode", { - get: $util.oneOfGetter($oneOfFields = ["order", "arrayConfig"]), + get: $util.oneOfGetter($oneOfFields = ["order", "arrayConfig", "vectorConfig"]), set: $util.oneOfSetter($oneOfFields) }); @@ -1732,6 +1741,11 @@ message.arrayConfig = 1; break; } + if (object.vectorConfig != null) { + if (typeof object.vectorConfig !== "object") + throw TypeError(".google.firestore.admin.v1.Index.IndexField.vectorConfig: object expected"); + message.vectorConfig = $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.fromObject(object.vectorConfig); + } return message; }; @@ -1762,6 +1776,11 @@ if (options.oneofs) object.valueMode = "arrayConfig"; } + if (message.vectorConfig != null && message.hasOwnProperty("vectorConfig")) { + object.vectorConfig = $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.toObject(message.vectorConfig, options); + if (options.oneofs) + object.valueMode = "vectorConfig"; + } return object; }; @@ -1821,6 +1840,216 @@ return values; })(); + IndexField.VectorConfig = (function() { + + /** + * Properties of a VectorConfig. + * @memberof google.firestore.admin.v1.Index.IndexField + * @interface IVectorConfig + * @property {number|null} [dimension] VectorConfig dimension + * @property {google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex|null} [flat] VectorConfig flat + */ + + /** + * Constructs a new VectorConfig. + * @memberof google.firestore.admin.v1.Index.IndexField + * @classdesc Represents a VectorConfig. + * @implements IVectorConfig + * @constructor + * @param {google.firestore.admin.v1.Index.IndexField.IVectorConfig=} [properties] Properties to set + */ + function VectorConfig(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * VectorConfig dimension. + * @member {number} dimension + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @instance + */ + VectorConfig.prototype.dimension = 0; + + /** + * VectorConfig flat. + * @member {google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex|null|undefined} flat + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @instance + */ + VectorConfig.prototype.flat = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * VectorConfig type. + * @member {"flat"|undefined} type + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @instance + */ + Object.defineProperty(VectorConfig.prototype, "type", { + get: $util.oneOfGetter($oneOfFields = ["flat"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a VectorConfig message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @static + * @param {Object.} object Plain object + * @returns {google.firestore.admin.v1.Index.IndexField.VectorConfig} VectorConfig + */ + VectorConfig.fromObject = function fromObject(object) { + if (object instanceof $root.google.firestore.admin.v1.Index.IndexField.VectorConfig) + return object; + var message = new $root.google.firestore.admin.v1.Index.IndexField.VectorConfig(); + if (object.dimension != null) + message.dimension = object.dimension | 0; + if (object.flat != null) { + if (typeof object.flat !== "object") + throw TypeError(".google.firestore.admin.v1.Index.IndexField.VectorConfig.flat: object expected"); + message.flat = $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.fromObject(object.flat); + } + return message; + }; + + /** + * Creates a plain object from a VectorConfig message. Also converts values to other types if specified. + * @function toObject + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @static + * @param {google.firestore.admin.v1.Index.IndexField.VectorConfig} message VectorConfig + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + VectorConfig.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.dimension = 0; + if (message.dimension != null && message.hasOwnProperty("dimension")) + object.dimension = message.dimension; + if (message.flat != null && message.hasOwnProperty("flat")) { + object.flat = $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex.toObject(message.flat, options); + if (options.oneofs) + object.type = "flat"; + } + return object; + }; + + /** + * Converts this VectorConfig to JSON. + * @function toJSON + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @instance + * @returns {Object.} JSON object + */ + VectorConfig.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for VectorConfig + * @function getTypeUrl + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + VectorConfig.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.firestore.admin.v1.Index.IndexField.VectorConfig"; + }; + + VectorConfig.FlatIndex = (function() { + + /** + * Properties of a FlatIndex. + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @interface IFlatIndex + */ + + /** + * Constructs a new FlatIndex. + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig + * @classdesc Represents a FlatIndex. + * @implements IFlatIndex + * @constructor + * @param {google.firestore.admin.v1.Index.IndexField.VectorConfig.IFlatIndex=} [properties] Properties to set + */ + function FlatIndex(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a FlatIndex message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + * @static + * @param {Object.} object Plain object + * @returns {google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex} FlatIndex + */ + FlatIndex.fromObject = function fromObject(object) { + if (object instanceof $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex) + return object; + return new $root.google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex(); + }; + + /** + * Creates a plain object from a FlatIndex message. Also converts values to other types if specified. + * @function toObject + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + * @static + * @param {google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex} message FlatIndex + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FlatIndex.toObject = function toObject() { + return {}; + }; + + /** + * Converts this FlatIndex to JSON. + * @function toJSON + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + * @instance + * @returns {Object.} JSON object + */ + FlatIndex.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FlatIndex + * @function getTypeUrl + * @memberof google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FlatIndex.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.firestore.admin.v1.Index.IndexField.VectorConfig.FlatIndex"; + }; + + return FlatIndex; + })(); + + return VectorConfig; + })(); + return IndexField; })(); diff --git a/dev/protos/firestore_v1_proto_api.d.ts b/dev/protos/firestore_v1_proto_api.d.ts index eac3a6f12..8db3cd697 100644 --- a/dev/protos/firestore_v1_proto_api.d.ts +++ b/dev/protos/firestore_v1_proto_api.d.ts @@ -6847,6 +6847,9 @@ export namespace google { /** StructuredQuery limit */ limit?: (google.protobuf.IInt32Value|null); + + /** StructuredQuery findNearest */ + findNearest?: (google.firestore.v1.StructuredQuery.IFindNearest|null); } /** Represents a StructuredQuery. */ @@ -6882,6 +6885,9 @@ export namespace google { /** StructuredQuery limit. */ public limit?: (google.protobuf.IInt32Value|null); + /** StructuredQuery findNearest. */ + public findNearest?: (google.firestore.v1.StructuredQuery.IFindNearest|null); + /** * Creates a StructuredQuery message from a plain object. Also converts values to their respective internal types. * @param object Plain object @@ -7375,6 +7381,79 @@ export namespace google { */ public static getTypeUrl(typeUrlPrefix?: string): string; } + + /** Properties of a FindNearest. */ + interface IFindNearest { + + /** FindNearest vectorField */ + vectorField?: (google.firestore.v1.StructuredQuery.IFieldReference|null); + + /** FindNearest queryVector */ + queryVector?: (google.firestore.v1.IValue|null); + + /** FindNearest distanceMeasure */ + distanceMeasure?: (google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure|null); + + /** FindNearest limit */ + limit?: (google.protobuf.IInt32Value|null); + } + + /** Represents a FindNearest. */ + class FindNearest implements IFindNearest { + + /** + * Constructs a new FindNearest. + * @param [properties] Properties to set + */ + constructor(properties?: google.firestore.v1.StructuredQuery.IFindNearest); + + /** FindNearest vectorField. */ + public vectorField?: (google.firestore.v1.StructuredQuery.IFieldReference|null); + + /** FindNearest queryVector. */ + public queryVector?: (google.firestore.v1.IValue|null); + + /** FindNearest distanceMeasure. */ + public distanceMeasure: google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure; + + /** FindNearest limit. */ + public limit?: (google.protobuf.IInt32Value|null); + + /** + * Creates a FindNearest message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FindNearest + */ + public static fromObject(object: { [k: string]: any }): google.firestore.v1.StructuredQuery.FindNearest; + + /** + * Creates a plain object from a FindNearest message. Also converts values to other types if specified. + * @param message FindNearest + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.firestore.v1.StructuredQuery.FindNearest, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FindNearest to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FindNearest + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace FindNearest { + + /** DistanceMeasure enum. */ + type DistanceMeasure = + "DISTANCE_MEASURE_UNSPECIFIED"| "EUCLIDEAN"| "COSINE"| "DOT_PRODUCT"; + } } /** Properties of a StructuredAggregationQuery. */ diff --git a/dev/protos/firestore_v1_proto_api.js b/dev/protos/firestore_v1_proto_api.js index f817f2e9a..233baf2a1 100644 --- a/dev/protos/firestore_v1_proto_api.js +++ b/dev/protos/firestore_v1_proto_api.js @@ -16852,6 +16852,7 @@ * @property {google.firestore.v1.ICursor|null} [endAt] StructuredQuery endAt * @property {number|null} [offset] StructuredQuery offset * @property {google.protobuf.IInt32Value|null} [limit] StructuredQuery limit + * @property {google.firestore.v1.StructuredQuery.IFindNearest|null} [findNearest] StructuredQuery findNearest */ /** @@ -16935,6 +16936,14 @@ */ StructuredQuery.prototype.limit = null; + /** + * StructuredQuery findNearest. + * @member {google.firestore.v1.StructuredQuery.IFindNearest|null|undefined} findNearest + * @memberof google.firestore.v1.StructuredQuery + * @instance + */ + StructuredQuery.prototype.findNearest = null; + /** * Creates a StructuredQuery message from a plain object. Also converts values to their respective internal types. * @function fromObject @@ -16994,6 +17003,11 @@ throw TypeError(".google.firestore.v1.StructuredQuery.limit: object expected"); message.limit = $root.google.protobuf.Int32Value.fromObject(object.limit); } + if (object.findNearest != null) { + if (typeof object.findNearest !== "object") + throw TypeError(".google.firestore.v1.StructuredQuery.findNearest: object expected"); + message.findNearest = $root.google.firestore.v1.StructuredQuery.FindNearest.fromObject(object.findNearest); + } return message; }; @@ -17021,6 +17035,7 @@ object.offset = 0; object.startAt = null; object.endAt = null; + object.findNearest = null; } if (message.select != null && message.hasOwnProperty("select")) object.select = $root.google.firestore.v1.StructuredQuery.Projection.toObject(message.select, options); @@ -17044,6 +17059,8 @@ object.startAt = $root.google.firestore.v1.Cursor.toObject(message.startAt, options); if (message.endAt != null && message.hasOwnProperty("endAt")) object.endAt = $root.google.firestore.v1.Cursor.toObject(message.endAt, options); + if (message.findNearest != null && message.hasOwnProperty("findNearest")) + object.findNearest = $root.google.firestore.v1.StructuredQuery.FindNearest.toObject(message.findNearest, options); return object; }; @@ -18249,6 +18266,196 @@ return Projection; })(); + StructuredQuery.FindNearest = (function() { + + /** + * Properties of a FindNearest. + * @memberof google.firestore.v1.StructuredQuery + * @interface IFindNearest + * @property {google.firestore.v1.StructuredQuery.IFieldReference|null} [vectorField] FindNearest vectorField + * @property {google.firestore.v1.IValue|null} [queryVector] FindNearest queryVector + * @property {google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure|null} [distanceMeasure] FindNearest distanceMeasure + * @property {google.protobuf.IInt32Value|null} [limit] FindNearest limit + */ + + /** + * Constructs a new FindNearest. + * @memberof google.firestore.v1.StructuredQuery + * @classdesc Represents a FindNearest. + * @implements IFindNearest + * @constructor + * @param {google.firestore.v1.StructuredQuery.IFindNearest=} [properties] Properties to set + */ + function FindNearest(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * FindNearest vectorField. + * @member {google.firestore.v1.StructuredQuery.IFieldReference|null|undefined} vectorField + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @instance + */ + FindNearest.prototype.vectorField = null; + + /** + * FindNearest queryVector. + * @member {google.firestore.v1.IValue|null|undefined} queryVector + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @instance + */ + FindNearest.prototype.queryVector = null; + + /** + * FindNearest distanceMeasure. + * @member {google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure} distanceMeasure + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @instance + */ + FindNearest.prototype.distanceMeasure = 0; + + /** + * FindNearest limit. + * @member {google.protobuf.IInt32Value|null|undefined} limit + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @instance + */ + FindNearest.prototype.limit = null; + + /** + * Creates a FindNearest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @static + * @param {Object.} object Plain object + * @returns {google.firestore.v1.StructuredQuery.FindNearest} FindNearest + */ + FindNearest.fromObject = function fromObject(object) { + if (object instanceof $root.google.firestore.v1.StructuredQuery.FindNearest) + return object; + var message = new $root.google.firestore.v1.StructuredQuery.FindNearest(); + if (object.vectorField != null) { + if (typeof object.vectorField !== "object") + throw TypeError(".google.firestore.v1.StructuredQuery.FindNearest.vectorField: object expected"); + message.vectorField = $root.google.firestore.v1.StructuredQuery.FieldReference.fromObject(object.vectorField); + } + if (object.queryVector != null) { + if (typeof object.queryVector !== "object") + throw TypeError(".google.firestore.v1.StructuredQuery.FindNearest.queryVector: object expected"); + message.queryVector = $root.google.firestore.v1.Value.fromObject(object.queryVector); + } + switch (object.distanceMeasure) { + default: + if (typeof object.distanceMeasure === "number") { + message.distanceMeasure = object.distanceMeasure; + break; + } + break; + case "DISTANCE_MEASURE_UNSPECIFIED": + case 0: + message.distanceMeasure = 0; + break; + case "EUCLIDEAN": + case 1: + message.distanceMeasure = 1; + break; + case "COSINE": + case 2: + message.distanceMeasure = 2; + break; + case "DOT_PRODUCT": + case 3: + message.distanceMeasure = 3; + break; + } + if (object.limit != null) { + if (typeof object.limit !== "object") + throw TypeError(".google.firestore.v1.StructuredQuery.FindNearest.limit: object expected"); + message.limit = $root.google.protobuf.Int32Value.fromObject(object.limit); + } + return message; + }; + + /** + * Creates a plain object from a FindNearest message. Also converts values to other types if specified. + * @function toObject + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @static + * @param {google.firestore.v1.StructuredQuery.FindNearest} message FindNearest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FindNearest.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.vectorField = null; + object.queryVector = null; + object.distanceMeasure = options.enums === String ? "DISTANCE_MEASURE_UNSPECIFIED" : 0; + object.limit = null; + } + if (message.vectorField != null && message.hasOwnProperty("vectorField")) + object.vectorField = $root.google.firestore.v1.StructuredQuery.FieldReference.toObject(message.vectorField, options); + if (message.queryVector != null && message.hasOwnProperty("queryVector")) + object.queryVector = $root.google.firestore.v1.Value.toObject(message.queryVector, options); + if (message.distanceMeasure != null && message.hasOwnProperty("distanceMeasure")) + object.distanceMeasure = options.enums === String ? $root.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure[message.distanceMeasure] === undefined ? message.distanceMeasure : $root.google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure[message.distanceMeasure] : message.distanceMeasure; + if (message.limit != null && message.hasOwnProperty("limit")) + object.limit = $root.google.protobuf.Int32Value.toObject(message.limit, options); + return object; + }; + + /** + * Converts this FindNearest to JSON. + * @function toJSON + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @instance + * @returns {Object.} JSON object + */ + FindNearest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FindNearest + * @function getTypeUrl + * @memberof google.firestore.v1.StructuredQuery.FindNearest + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FindNearest.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.firestore.v1.StructuredQuery.FindNearest"; + }; + + /** + * DistanceMeasure enum. + * @name google.firestore.v1.StructuredQuery.FindNearest.DistanceMeasure + * @enum {string} + * @property {string} DISTANCE_MEASURE_UNSPECIFIED=DISTANCE_MEASURE_UNSPECIFIED DISTANCE_MEASURE_UNSPECIFIED value + * @property {string} EUCLIDEAN=EUCLIDEAN EUCLIDEAN value + * @property {string} COSINE=COSINE COSINE value + * @property {string} DOT_PRODUCT=DOT_PRODUCT DOT_PRODUCT value + */ + FindNearest.DistanceMeasure = (function() { + var valuesById = {}, values = Object.create(valuesById); + values[valuesById[0] = "DISTANCE_MEASURE_UNSPECIFIED"] = "DISTANCE_MEASURE_UNSPECIFIED"; + values[valuesById[1] = "EUCLIDEAN"] = "EUCLIDEAN"; + values[valuesById[2] = "COSINE"] = "COSINE"; + values[valuesById[3] = "DOT_PRODUCT"] = "DOT_PRODUCT"; + return values; + })(); + + return FindNearest; + })(); + return StructuredQuery; })(); diff --git a/dev/protos/google/firestore/admin/v1/index.proto b/dev/protos/google/firestore/admin/v1/index.proto index 2567da650..add5c3f3f 100644 --- a/dev/protos/google/firestore/admin/v1/index.proto +++ b/dev/protos/google/firestore/admin/v1/index.proto @@ -16,6 +16,7 @@ syntax = "proto3"; package google.firestore.admin.v1; +import "google/api/field_behavior.proto"; import "google/api/resource.proto"; option csharp_namespace = "Google.Cloud.Firestore.Admin.V1"; @@ -92,6 +93,25 @@ message Index { CONTAINS = 1; } + // The index configuration to support vector search operations + message VectorConfig { + // An index that stores vectors in a flat data structure, and supports + // exhaustive search. + message FlatIndex {} + + // Required. The vector dimension this configuration applies to. + // + // The resulting index will only include vectors of this dimension, and + // can be used for vector search with the same dimension. + int32 dimension = 1 [(google.api.field_behavior) = REQUIRED]; + + // The type of index used. + oneof type { + // Indicates the vector index is a flat index. + FlatIndex flat = 2; + } + } + // Can be __name__. // For single field indexes, this must match the name of the field or may // be omitted. @@ -105,6 +125,10 @@ message Index { // Indicates that this field supports operations on `array_value`s. ArrayConfig array_config = 3; + + // Indicates that this field supports nearest neighbors and distance + // operations on vector. + VectorConfig vector_config = 4; } } diff --git a/dev/protos/google/firestore/v1/query.proto b/dev/protos/google/firestore/v1/query.proto index 09eefa241..68d9d5458 100644 --- a/dev/protos/google/firestore/v1/query.proto +++ b/dev/protos/google/firestore/v1/query.proto @@ -263,6 +263,51 @@ message StructuredQuery { repeated FieldReference fields = 2; } + // Nearest Neighbors search config. + message FindNearest { + // The distance measure to use when comparing vectors. + enum DistanceMeasure { + // Should not be set. + DISTANCE_MEASURE_UNSPECIFIED = 0; + + // Measures the EUCLIDEAN distance between the vectors. See + // [Euclidean](https://en.wikipedia.org/wiki/Euclidean_distance) to learn + // more + EUCLIDEAN = 1; + + // Compares vectors based on the angle between them, which allows you to + // measure similarity that isn't based on the vectors magnitude. + // We recommend using DOT_PRODUCT with unit normalized vectors instead of + // COSINE distance, which is mathematically equivalent with better + // performance. See [Cosine + // Similarity](https://en.wikipedia.org/wiki/Cosine_similarity) to learn + // more. + COSINE = 2; + + // Similar to cosine but is affected by the magnitude of the vectors. See + // [Dot Product](https://en.wikipedia.org/wiki/Dot_product) to learn more. + DOT_PRODUCT = 3; + } + + // Required. An indexed vector field to search upon. Only documents which + // contain vectors whose dimensionality match the query_vector can be + // returned. + FieldReference vector_field = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. The query vector that we are searching on. Must be a vector of + // no more than 2048 dimensions. + Value query_vector = 2 [(google.api.field_behavior) = REQUIRED]; + + // Required. The Distance Measure to use, required. + DistanceMeasure distance_measure = 3 + [(google.api.field_behavior) = REQUIRED]; + + // Required. The number of nearest neighbors to return. Must be a positive + // integer of no more than 1000. + google.protobuf.Int32Value limit = 4 + [(google.api.field_behavior) = REQUIRED]; + } + // Optional sub-set of the fields to return. // // This acts as a [DocumentMask][google.firestore.v1.DocumentMask] over the @@ -360,6 +405,13 @@ message StructuredQuery { // // * The value must be greater than or equal to zero if specified. google.protobuf.Int32Value limit = 5; + + // Optional. A potential Nearest Neighbors Search. + // + // Applies after all other filters and ordering. + // + // Finds the closest vector embeddings to the given query vector. + FindNearest find_nearest = 9 [(google.api.field_behavior) = OPTIONAL]; } // Firestore query for running an aggregation over a diff --git a/dev/protos/google/protobuf/descriptor.proto b/dev/protos/google/protobuf/descriptor.proto index 6805b9b4b..cfd2cd4eb 100644 --- a/dev/protos/google/protobuf/descriptor.proto +++ b/dev/protos/google/protobuf/descriptor.proto @@ -1020,6 +1020,8 @@ message FeatureSet { extensions 1001; // for Protobuf Java extensions 1002; // for Protobuf Go + extensions 9990; // for deprecated Java Proto1 + extensions 9995 to 9999; // For internal testing extensions 10000; // for https://github.com/bufbuild/protobuf-es } diff --git a/dev/protos/v1.json b/dev/protos/v1.json index f36d2f46f..f83db8234 100644 --- a/dev/protos/v1.json +++ b/dev/protos/v1.json @@ -1185,6 +1185,10 @@ 1002, 1002 ], + [ + 9990, + 9990 + ], [ 9995, 9999 @@ -2885,6 +2889,13 @@ "limit": { "type": "google.protobuf.Int32Value", "id": 5 + }, + "findNearest": { + "type": "FindNearest", + "id": 9, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } } }, "nested": { @@ -3045,6 +3056,48 @@ "id": 2 } } + }, + "FindNearest": { + "fields": { + "vectorField": { + "type": "FieldReference", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "queryVector": { + "type": "Value", + "id": 2, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "distanceMeasure": { + "type": "DistanceMeasure", + "id": 3, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "limit": { + "type": "google.protobuf.Int32Value", + "id": 4, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + } + }, + "nested": { + "DistanceMeasure": { + "values": { + "DISTANCE_MEASURE_UNSPECIFIED": 0, + "EUCLIDEAN": 1, + "COSINE": 2, + "DOT_PRODUCT": 3 + } + } + } } } }, diff --git a/dev/protos/v1beta1.json b/dev/protos/v1beta1.json index e892f5e33..6ddc237d9 100644 --- a/dev/protos/v1beta1.json +++ b/dev/protos/v1beta1.json @@ -1185,6 +1185,10 @@ 1002, 1002 ], + [ + 9990, + 9990 + ], [ 9995, 9999 diff --git a/types/firestore.d.ts b/types/firestore.d.ts index 92d8477ed..73fa17065 100644 --- a/types/firestore.d.ts +++ b/types/firestore.d.ts @@ -39,8 +39,8 @@ declare namespace FirebaseFirestore { | (T extends Primitive ? T : T extends {} - ? {[K in keyof T]?: PartialWithFieldValue | FieldValue} - : never); + ? {[K in keyof T]?: PartialWithFieldValue | FieldValue} + : never); /** * Allows FieldValues to be passed in as a property value while maintaining @@ -51,8 +51,8 @@ declare namespace FirebaseFirestore { | (T extends Primitive ? T : T extends {} - ? {[K in keyof T]: WithFieldValue | FieldValue} - : never); + ? {[K in keyof T]: WithFieldValue | FieldValue} + : never); /** * Update data (for use with [update]{@link DocumentReference#update}) @@ -71,8 +71,8 @@ declare namespace FirebaseFirestore { export type UpdateData = T extends Primitive ? T : T extends {} - ? {[K in keyof T]?: UpdateData | FieldValue} & NestedUpdateFields - : Partial; + ? {[K in keyof T]?: UpdateData | FieldValue} & NestedUpdateFields + : Partial; /** Primitive types. */ export type Primitive = string | number | boolean | undefined | null;