Skip to content

Instantly share code, notes, and snippets.

Created April 18, 2023 18:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import gzip
import json
import openai
# Download the following file from
product_data_full = []
for line in'./amazon_metadata/meta_Video_Games.json.gz', 'rt', encoding='UTF-8'):
# Remove products without descriptions and embed a subset of the data to save time (and money)
product_data = []
for item in range(12000):
if product_data_full[item]['description'] and product_data_full[item]['price']:
# Create embeddings for each product desciption
for item in product_data:
item['description_embedding'] = openai.Embedding.create(input=item['description'][0], model="text-embedding-ada-002")["data"][0]["embedding"]
# Create new file with embeddings
for item in product_data:
jsonString = json.dumps(item)
jsonFile.write(jsonString + '\n')
# Generate embedding for future search input
search_query = 'open-world play, multiplayer options, and support for in-game purchases'
search_query_embedding = openai.Embedding.create(input=search_query, model="text-embedding-ada-002")["data"][0]["embedding"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment