From 266820e5c2447b5942be7743a34a8396732f15d8 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Wed, 13 Nov 2024 17:27:28 -0500 Subject: [PATCH] refactor: shrink 17-artwork-multimodal import size --- src/17-infinite-discovery/03-artworks-mutli2vec.ts | 14 ++++++++++++-- src/17-infinite-discovery/helpers.ts | 8 ++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/17-infinite-discovery/03-artworks-mutli2vec.ts b/src/17-infinite-discovery/03-artworks-mutli2vec.ts index a3dda8d..bcf7320 100644 --- a/src/17-infinite-discovery/03-artworks-mutli2vec.ts +++ b/src/17-infinite-discovery/03-artworks-mutli2vec.ts @@ -17,7 +17,7 @@ const client = weaviate.client({ async function main() { await deleteIfExists(CLASS_NAME) await prepareArtworkCollection() - const artworks = await getArtworks() + const artworks = await getArtworks("2024-11-12_artworks.json") await insertArtworks(artworks) } @@ -30,6 +30,7 @@ async function prepareArtworkCollection() { vectorizer: "multi2vec-clip", moduleConfig: { "multi2vec-clip": { + dimensions: 512, textFields: [ "title", "medium", @@ -37,6 +38,8 @@ async function prepareArtworkCollection() { "categories", "tags", "additionalInformation", + "date", + "artistName", ], imageFields: ["image"], }, @@ -114,6 +117,10 @@ async function prepareArtworkCollection() { name: "artistGender", dataType: ["text"], }, + { + name: "isCurated", + dataType: ["boolean"], + }, ], } @@ -135,6 +142,8 @@ async function insertArtworks( artworks: GravityArtwork[], batchSize: number = BATCH_SIZE ) { + const start = Date.now() + console.log("Started inserting artworks at: ", start) console.log(`Inserting artwork: ${artworks.length}`) const batches = chunk(artworks, batchSize) @@ -168,6 +177,7 @@ async function insertArtworks( artistBirthday: artwork.artist_birthday, artistGender: artwork.artist_gender, image: imageData[artwork.id], + isCurated: false, }, id: generateUuid5(artwork.id), } @@ -177,7 +187,7 @@ async function insertArtworks( await batcher.do() } process.stdout.write("\n") - console.log("Done.") + console.log("Finished inserting artworks at: ", Date.now() - start) } main().catch(console.error) diff --git a/src/17-infinite-discovery/helpers.ts b/src/17-infinite-discovery/helpers.ts index c8d0d3b..41d4484 100644 --- a/src/17-infinite-discovery/helpers.ts +++ b/src/17-infinite-discovery/helpers.ts @@ -11,8 +11,8 @@ import { fromPairs, defaults } from "lodash" * * https://drive.google.com/drive/u/1/folders/1Lh7msUc0R_JlpNEzApZ4YbqB8x5tbpws */ -export async function getArtworks() { - const filePath = path.join(__dirname, "./data/artworks.json") +export async function getArtworks(filename: string) { + const filePath = path.join(__dirname, `./data/${filename}`) const data = await fs.promises.readFile(filePath, "utf-8") const artworks: GravityArtwork[] = JSON.parse(data) return artworks @@ -60,8 +60,8 @@ export function resizeImage( height: number } ) { - const { width, height } = defaults(options, { width: 500, height: 500 }) - return `https://d7hftxdivxxvm.cloudfront.net/?src=${src}&resize_to=fit&width=${width}&height=${height}&grow=false` + const { width, height } = defaults(options, { width: 224, height: 224 }) + return `https://d7hftxdivxxvm.cloudfront.net/?src=${src}&resize_to=fit&width=${width}&height=${height}&grow=false&quality=75` } /**