Skip to content
GitHubXDiscord

Schema

The Schema resource lets you define and manage AWS Personalize Schemas for your machine learning models. Schemas define the structure of your data and how it will be used in your personalization solutions.

Create a basic schema with required properties:

import AWS from "alchemy/aws/control";
const basicSchema = await AWS.Personalize.Schema("basic-schema", {
Name: "UserInteractionSchema",
Schema: JSON.stringify({
type: "record",
name: "UserInteraction",
fields: [
{ name: "USER_ID", type: "string" },
{ name: "ITEM_ID", type: "string" },
{ name: "TIMESTAMP", type: "long" }
],
version: "1.0"
}),
Domain: "ECOMMERCE" // Optional domain
});

Define a schema with additional properties and a custom domain:

const advancedSchema = await AWS.Personalize.Schema("advanced-schema", {
Name: "AdvancedUserInteractionSchema",
Schema: JSON.stringify({
type: "record",
name: "AdvancedUserInteraction",
fields: [
{ name: "USER_ID", type: "string" },
{ name: "ITEM_ID", type: "string" },
{ name: "TIMESTAMP", type: "long" },
{ name: "EVENT_TYPE", type: "string" }
],
version: "1.0"
}),
Domain: "ECOMMERCE",
adopt: true // Adopt existing resource if it already exists
});

Define a schema that includes multiple interaction types and metadata:

const multiFieldSchema = await AWS.Personalize.Schema("multi-field-schema", {
Name: "UserInteractionWithMetadata",
Schema: JSON.stringify({
type: "record",
name: "UserInteractionWithMetadata",
fields: [
{ name: "USER_ID", type: "string" },
{ name: "ITEM_ID", type: "string" },
{ name: "TIMESTAMP", type: "long" },
{ name: "EVENT_TYPE", type: "string" },
{ name: "METADATA", type: "string" }
],
version: "1.0"
})
});

Create schemas tailored for different domains such as ECOMMERCE and VIDEO:

const videoSchema = await AWS.Personalize.Schema("video-schema", {
Name: "VideoInteractionSchema",
Schema: JSON.stringify({
type: "record",
name: "VideoInteraction",
fields: [
{ name: "USER_ID", type: "string" },
{ name: "VIDEO_ID", type: "string" },
{ name: "WATCH_DURATION", type: "long" },
{ name: "TIMESTAMP", type: "long" }
],
version: "1.0"
}),
Domain: "VIDEO" // Specify domain for the video use case
});