Skip to content

Commit

Permalink
Dump movieId embedding into a CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Robbins committed Dec 12, 2023
1 parent de045da commit 8f904fc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/chDB_vector_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,29 @@
"similar_movies = model.wv.most_similar(str(input_movie_id), topn=top_k)\n",
"print(chs.query(f\"SELECT movieId, title FROM movies WHERE movieId IN ({','.join([str(m[0]) for m in similar_movies])})\", \"CSV\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import csv\n",
"\n",
"# Open the CSV file in write mode\n",
"with open('movie_embeddings.csv', 'w', newline='') as file:\n",
" writer = csv.writer(file)\n",
"\n",
" # Write the header row\n",
" writer.writerow(['movieId', 'embedding'])\n",
"\n",
" # Iterate over each movieId and its corresponding embedding\n",
" for movieId in model.wv.index_to_key:\n",
" embedding = model.wv[movieId]\n",
"\n",
" # Write the movieId and embedding as a row in the CSV file\n",
" writer.writerow([movieId, embedding])\n"
]
}
],
"metadata": {
Expand Down

0 comments on commit 8f904fc

Please sign in to comment.