@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
290 lines • 11.7 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataObject = void 0;
const pulumi = __importStar(require("@pulumi/pulumi"));
const utilities = __importStar(require("../utilities"));
/**
* A DataObject is a single item of data (with optional vectors) stored in a
* Vector Search Collection. Each DataObject conforms to the parent
* Collection's `dataSchema` and `vectorSchema`.
*
* This resource always issues one `CreateDataObject` request per Terraform
* resource block. It does NOT use the `batchCreate` REST endpoint --
* Terraform's resource lifecycle is inherently per-object, so batching
* across resources is not modeled. When you use `forEach` or `count`,
* Terraform will still issue individual requests, up to `-parallelism`
* in parallel.
*
* For ingesting more than a few hundred items, prefer one of the
* following out-of-band paths instead of Terraform:
*
* * `importDataObjects` (bulk ingest from Cloud Storage) -- highest
* throughput, but only available *before* any Index is created on
* the Collection.
* * `batchCreate` (up to ~1000 items per call) -- available at any
* time, but must be driven from your own client code, not Terraform.
*
* Once an Index exists on the Collection, `importDataObjects` is no
* longer available and DataObjects must be created via `CreateDataObject`
* (as this resource does) or via `batchCreate`.
*
* ## Example Usage
*
* ### Vectorsearch Data Object Basic
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* // NOTE: This resource issues one CreateDataObject request per block.
* // It does NOT batch across resources. Terraform will parallelize a
* // 'for_each' up to '-parallelism', but each item is still a separate
* // HTTP call.
* //
* // For bulk ingestion of many items, prefer one of these out-of-band
* // paths instead of Terraform:
* // * 'importDataObjects' (from Cloud Storage) -- highest throughput,
* // but only available *before* any Index is created on the Collection.
* // * 'batchCreate' (up to ~1000 items per call) -- available at any
* // time, but must be driven from client code, not Terraform.
* const parent = new gcp.vectorsearch.Collection("parent", {
* location: "us-central1",
* collectionId: "example-collection",
* displayName: "My Awesome Collection",
* description: "This collection stores important data.",
* dataSchema: `{
* \\"type\\": \\"object\\",
* \\"properties\\": {
* \\"title\\": {
* \\"type\\": \\"string\\"
* },
* \\"plot\\": {
* \\"type\\": \\"string\\"
* }
* }
* }
* `,
* vectorSchemas: [{
* fieldName: "text_embedding",
* denseVector: {
* dimensions: 768,
* vertexEmbeddingConfig: {
* modelId: "text-embedding-005",
* taskType: "RETRIEVAL_DOCUMENT",
* textTemplate: "Title: {title} ---- Plot: {plot}",
* },
* },
* }],
* });
* // Because the parent Collection's 'text_embedding' field is configured
* // with a 'vertex_embedding_config', the server will populate the vector
* // automatically from 'data.title' and 'data.plot' -- no explicit
* // 'vectors' block is required.
* const example_data_object = new gcp.vectorsearch.DataObject("example-data-object", {
* location: "us-central1",
* collectionId: parent.collectionId,
* dataObjectId: "example-data-object",
* data: JSON.stringify({
* title: "The Matrix",
* plot: "A computer hacker learns about the true nature of reality.",
* }),
* });
* ```
* ### Vectorsearch Data Object With Vectors
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* // NOTE: This resource issues one CreateDataObject request per block.
* // It does NOT batch across resources. Terraform will parallelize a
* // 'for_each' up to '-parallelism', but each item is still a separate
* // HTTP call.
* //
* // For bulk ingestion of many items, prefer one of these out-of-band
* // paths instead of Terraform:
* // * 'importDataObjects' (from Cloud Storage) -- highest throughput,
* // but only available *before* any Index is created on the Collection.
* // * 'batchCreate' (up to ~1000 items per call) -- available at any
* // time, but must be driven from client code, not Terraform.
* const parent = new gcp.vectorsearch.Collection("parent", {
* location: "us-central1",
* collectionId: "example-vectors-collection",
* displayName: "My BYO-Embedding Collection",
* description: "Collection whose vectors are supplied by the client.",
* dataSchema: `{
* \\"type\\": \\"object\\",
* \\"properties\\": {
* \\"title\\": {
* \\"type\\": \\"string\\"
* },
* \\"category\\": {
* \\"type\\": \\"string\\"
* }
* }
* }
* `,
* vectorSchemas: [
* {
* fieldName: "dense_embedding",
* denseVector: {
* dimensions: 4,
* },
* },
* {
* fieldName: "sparse_embedding",
* sparseVector: {},
* },
* ],
* });
* const example_vectors_data_object = new gcp.vectorsearch.DataObject("example-vectors-data-object", {
* location: "us-central1",
* collectionId: parent.collectionId,
* dataObjectId: "example-vectors-data-object",
* data: JSON.stringify({
* title: "The Matrix",
* category: "movie",
* }),
* vectors: [
* {
* fieldName: "dense_embedding",
* dense: {
* values: [
* 0.11,
* 0.22,
* 0.33,
* 0.44,
* ],
* },
* },
* {
* fieldName: "sparse_embedding",
* sparse: {
* values: [
* 0.9,
* 0.5,
* 0.1,
* ],
* indices: [
* 3,
* 17,
* 42,
* ],
* },
* },
* ],
* });
* ```
*
* ## Import
*
* DataObject can be imported using any of these accepted formats:
*
* * `projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/dataObjects/{{data_object_id}}`
* * `{{project}}/{{location}}/{{collection_id}}/{{data_object_id}}`
* * `{{location}}/{{collection_id}}/{{data_object_id}}`
*
* When using the `pulumi import` command, DataObject can be imported using one of the formats above. For example:
*
* ```sh
* $ pulumi import gcp:vectorsearch/dataObject:DataObject default projects/{{project}}/locations/{{location}}/collections/{{collection_id}}/dataObjects/{{data_object_id}}
* $ pulumi import gcp:vectorsearch/dataObject:DataObject default {{project}}/{{location}}/{{collection_id}}/{{data_object_id}}
* $ pulumi import gcp:vectorsearch/dataObject:DataObject default {{location}}/{{collection_id}}/{{data_object_id}}
* ```
*/
class DataObject extends pulumi.CustomResource {
/**
* Get an existing DataObject resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new DataObject(name, state, { ...opts, id: id });
}
/** @internal */
static __pulumiType = 'gcp:vectorsearch/dataObject:DataObject';
/**
* Returns true if the given object is an instance of DataObject. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === DataObject.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["collectionId"] = state?.collectionId;
resourceInputs["createTime"] = state?.createTime;
resourceInputs["data"] = state?.data;
resourceInputs["dataObjectId"] = state?.dataObjectId;
resourceInputs["deletionPolicy"] = state?.deletionPolicy;
resourceInputs["etag"] = state?.etag;
resourceInputs["location"] = state?.location;
resourceInputs["name"] = state?.name;
resourceInputs["project"] = state?.project;
resourceInputs["updateTime"] = state?.updateTime;
resourceInputs["vectors"] = state?.vectors;
}
else {
const args = argsOrState;
if (args?.collectionId === undefined && !opts.urn) {
throw new Error("Missing required property 'collectionId'");
}
if (args?.dataObjectId === undefined && !opts.urn) {
throw new Error("Missing required property 'dataObjectId'");
}
if (args?.location === undefined && !opts.urn) {
throw new Error("Missing required property 'location'");
}
resourceInputs["collectionId"] = args?.collectionId;
resourceInputs["data"] = args?.data;
resourceInputs["dataObjectId"] = args?.dataObjectId;
resourceInputs["deletionPolicy"] = args?.deletionPolicy;
resourceInputs["etag"] = args?.etag;
resourceInputs["location"] = args?.location;
resourceInputs["project"] = args?.project;
resourceInputs["vectors"] = args?.vectors;
resourceInputs["createTime"] = undefined /*out*/;
resourceInputs["name"] = undefined /*out*/;
resourceInputs["updateTime"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(DataObject.__pulumiType, name, resourceInputs, opts);
}
}
exports.DataObject = DataObject;
//# sourceMappingURL=dataObject.js.map