function buildIndexMetdata()

in firestore-semantic-search/functions/src/common/vertex.ts [41:98]


function buildIndexMetdata(updateMetdata = false) {
  const algorithmConfig =
    config.algorithmConfig === AlgorithmConfig.BruteForceConfig
      ? {
          structValue: {
            fields: {
              bruteForceConfig: {
                structValue: {
                  fields: {},
                },
              },
            },
          },
        }
      : {
          structValue: {
            fields: {
              treeAhConfig: {
                structValue: {
                  fields: {},
                },
              },
            },
          },
        };

  const metadata = {
    structValue: {
      fields: {
        ...(!updateMetdata && {
          contentsDeltaUri: {
            stringValue: `gs://${config.bucketName}/datapoints`,
          },
          isCompleteOverwrite: {boolValue: false},
        }),
        config: {
          structValue: {
            fields: {
              dimensions: {
                numberValue: config.dimension,
              },
              approximateNeighborsCount: {numberValue: config.neighbors},
              distanceMeasureType: {stringValue: config.distanceMeasureType},
              shardSize: {stringValue: config.shardSize},
              featureNormType: {stringValue: config.featureNormType},
              algorithmConfig: {},
            },
          },
        },
      },
    },
  };

  metadata.structValue.fields.config.structValue.fields.algorithmConfig =
    algorithmConfig;

  return metadata;
}