Skip to content

Commit

Permalink
Merge pull request #6350 from artsy/staging
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
starsirius authored Jan 14, 2025
2 parents 6a9925b + 2c27d36 commit 7949a4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions _schemaV2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16812,6 +16812,9 @@ type Query {
# (Only for when useOpenSearch is true) Exclude these artworks from the response
excludeArtworkIds: [String]
first: Int

# (Only for when useOpenSearch is true) Which index to use to display initial batch of artworks
initialArtworksIndexName: String = "infinite_discovery_initial_artworks"
last: Int

# (Only for when useOpenSearch is true) These artworks are used to calculate the taste profile vector. Such artworks are excluded from the response
Expand Down Expand Up @@ -21448,6 +21451,9 @@ type Viewer {
# (Only for when useOpenSearch is true) Exclude these artworks from the response
excludeArtworkIds: [String]
first: Int

# (Only for when useOpenSearch is true) Which index to use to display initial batch of artworks
initialArtworksIndexName: String = "infinite_discovery_initial_artworks"
last: Int

# (Only for when useOpenSearch is true) These artworks are used to calculate the taste profile vector. Such artworks are excluded from the response
Expand Down
5 changes: 3 additions & 2 deletions src/lib/infiniteDiscovery/getInitialArtworksSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { opensearch } from "lib/apis/opensearch"
export const getInitialArtworksSample = async (
limit,
excludeArtworkIds,
artworksLoader
artworksLoader,
indexName
) => {
// initial artworks sample comes from indexed curators picks, but
// in future we plan to come up with a more sophisticated approach
const RANDOM_SEED = Math.floor(Math.random() * 1000)

const curatorsPicks = await opensearch(`/curators_picks/_search`, undefined, {
const curatorsPicks = await opensearch(`/${indexName}/_search`, undefined, {
method: "POST",
body: JSON.stringify({
size: limit,
Expand Down
20 changes: 17 additions & 3 deletions src/schema/v2/infiniteDiscovery/discoverArtworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ export const DiscoverArtworks: GraphQLFieldConfig<void, ResolverContext> = {
"The number of curated artworks to return. This is a temporary field to support the transition to OpenSearch",
defaultValue: 2,
},
initialArtworksIndexName: {
type: GraphQLString,
description:
"(Only for when useOpenSearch is true) Which index to use to display initial batch of artworks",
defaultValue: "infinite_discovery_initial_artworks",
},
}),
resolve: async (_root, args, { artworksLoader }) => {
if (!artworksLoader) {
new Error("A loader is not available")
}

const { limit = 10, mltFields, osWeights, curatedPicksSize } = args
const {
limit = 10,
mltFields,
osWeights,
curatedPicksSize,
initialArtworksIndexName,
} = args

const { excludeArtworkIds = [], likedArtworkIds = [] } = args

Expand All @@ -61,7 +73,8 @@ export const DiscoverArtworks: GraphQLFieldConfig<void, ResolverContext> = {
result = await getInitialArtworksSample(
limit,
excludeArtworkIds,
artworksLoader
artworksLoader,
initialArtworksIndexName
)
} else {
const tasteProfileVector = await calculateMeanArtworksVector(
Expand All @@ -88,7 +101,8 @@ export const DiscoverArtworks: GraphQLFieldConfig<void, ResolverContext> = {
? curatedPicksSize
: limit - result.length,
excludeArtworkIds,
artworksLoader
artworksLoader,
initialArtworksIndexName
)
result.push(...randomArtworks)
}
Expand Down

0 comments on commit 7949a4f

Please sign in to comment.