Movie Recommender with Tensorflow and pgvector Workshop

Welcome to our workshop!

Thank you so much for taking part in our hands-on workshop: Build a movie recommendation app with Tensorflow and pgvector

We hope you will join us LIVE at the appointed time, but what follows are written instructions for those keeners who would like to jump ahead, or for those newer folks who might hit bumps along the way during the workshop to help get themselves caught up.

If you want to have a look beforehand, here is the GitHub repo.

A tutorial following similar steps is also available in Aiven’s Developer Center at TensorFlow, PostgreSQL®, PGVector & Next.js: building a movie recommender.

Pre-requisites

To get the most out of your workshop experience, we recommend doing the following ahead of time:

  1. Get signed in to Aiven Console
  2. Set up a GitHub Codespace

Get signed in to Aiven Console

(If you prefer a video walkthrough, see Set up PG service with Aiven from the repo’s README.md file)

  1. Head to https://go.aiven.io/signup-movie-workshop
  2. If you’ve used Aiven before, go ahead and log in. You’re done with this step!
  3. If not, sign up through whichever method you’d like!
  4. If you chose email, you’ll need to click the link sent to you to validate your email address
  5. Once logged in, you’ll be asked to enter some additional information. Choose either Personal or Business, whichever applies to you, and specify the Name of your first project on Aiven.
  6. Once at your project’s Services screen, you can close your browser; we’ll do this part during the workshop.

Spoiler alert: we’re going to create a PostgreSQL service here. :wink:

Set up a GitHub Codespace

GitHub Codespaces offer an entire development environment running in the cloud, accessible from your browser, including Visual Studio Code and a Terminal. We’ll use this tool to eliminate issues with individual machines during the workshop, and ensure we’re all using the same versions of all the things so commands work correctly.

As mentioned before, we have all this nifty code ready to go for you in our workshop GitHub repo.

  1. From the repo’s README.md file, click the “Open in GitHub Codespaces” button to begin.
  2. Leave the settings at their default options and click Create codespace.

    (Note: You shouldn’t need to worry about getting charged as a result of this workshop, as the number of core hours + storage required should fit well under their monthly included storage)
  3. Once completed, you should see an interface that looks something like the following:
  4. If you ever lose this window and need to get back here again, you can view your full list of GitHub Codespaces from https://github.com/codespaces

NOTE: By default, these will end up with doofy auto-generated names like “probable space orbit” … feel free to click the “3-dots” menu > Rename and give it something a bit more intelligible.

Code overview

Once the workshop repo is open in GitHub Codespaces, you can use the file browser under “Explorer” on the left to inspect the code.

If you drill into the part1-core folder, some notable files in here are:

Following along with the workshop

Once your pre-requisites are all set, you can now follow the instructions under Part 2: Core Functionality in the README. Copy/paste the command line prompts from there into the Terminal of GitHub Codespaces.

Note: You’ll need to click “Allow” on a pop-up the first time to you paste to allow it to do this.

FAQs / Troubleshooting

When I run a command, I get back just [] … what gives?

That just means the command didn’t return any output, which will happen for a few of of them (e.g. node pg-commands.js enablePGVector just runs the query CREATE EXTENSION vector; so there’s no return value)

I get errors when trying to connect to PostgreSQL, what gives?

Connecting securely to PostgreSQL requires a couple of different steps (this is covered in the workshop as well, but restating for completeness):

  1. From GitHub Codespaces, in your part1-core folder, rename the .env-example file to .env
  2. From your PostgreSQL Service Overview page in Aiven Console, copy and paste the following values into the file:
  • User = PG_NAME
  • Password = PG_PASSWORD
  • Host = PG_HOST
  • Port = PG_PORT
  1. On the same page, click the Download icon next to CA Certificate and save your ca.pem file to, for example, your desktop.
  2. Click and drag the file into your GitHub Codespaces file explorer (also in the part1-core folder)

I got some errors about memory usage during the movie import. HALP!

If you see errors like the following during the movie import:

2024-06-11 20:22:53.626423: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 16477184 exceeds 10% of free system memory.

… don’t stress! :slight_smile: “W” just means “Warning” — as long as you also see a bunch of lines like the following, you’re good to go.

...
Processing starting from 600 with the step 150 of total amount 34886.
Processing starting from 750 with the step 150 of total amount 34886.
Processing starting from 900 with the step 150 of total amount 34886.
...

Oopsie doodle… I forgot to say “Yes” or “No” correctly to one of the Next.js app questions… what now?

Under Next.js project setup there are some specific directions on what to answer during a series of questions as npx create-next-app@latest is running. If you accidentally mess one of them up, simply delete and re-create the part2-fullstack folder and run the command again.

After doing the TypeScript part, my IDE has a bunch of angry red underlines under some things, why might that be?

Things might be okay, but do double check that all various files you’re creating/copying have the correct placement, which would be:

/part2-fullstack/movie-recommender:
  - .env
  - ca.pem
  - movie.d.ts

/part2-fullstack/movie-recommender/pages/api:
  - recommendations.ts

Hit [your-codespaces-url]/api/recommendations and if you get a bunch of JSON barf, you’re golden!

Ok, wiseguy, what if when I go to that URL I have an error?

Such as, for example, this:

This can happen if you stepped away for awhile and came back and your Codespace had to be restarted. To fix, run the following from your part2-fullstack/movie-recommender directory:

npm run dev

This restarts the application and you can re-open it in Codespace’s browser to continue where you left off.

First time on this forum, not sure what area I should post this in.

Regarding the movie recommender workshop, when I browse to the API endpoints the page shows in dark mode and the query text can’t be seen, even though both my browser and GitHub codespace are in light mode.

When I run the movie recommender workshop, the query form doesn’t show what I type (except for a red underline) although the query works. For example

2 Likes

Welcome, @Lloyd_Matthews ! Thanks for joining us today!

I have moved your question under this post so we can see all workshop Qs in one place (this also helps others in future workshops who might have the same question).

I do not, however, immediately know the answer to your question :sweat_smile: but have posted it to the team and hopefully we’ll get an answer for you soon! :slight_smile:

Good catch! It is related to this field <input type="search" id="default-search" ref={searchInput} autoComplete="off" placeholder="Type what do you want to watch about" required/>. In that intermediate step we still lack the classes assigned to properly visualise the field. That’s why the text takes white color, same as the background. During the next iteration we fix the styles and text becomes visible. Alternatively you can set the className=“text-black” in your example. Here are the docs for Tailwind Css on text color - Text Color - Tailwind CSS

Recommendations from today’s workshop!

  1. Padmaavat
  2. 3 Idiots
  3. Money Heist
  4. Kahani
  5. A Wednesday
  6. Golmal 1, 2, & 3

YAY Thank you, Debjit & Kaushlendra!

1 Like