Recreating Andrej Karpathy’s Weekend Project — a Movie Search Engine
Building a movie recommender system with OpenAI embeddings and a vector database

Despite its popularity, Karpathy unfortunately has not publicly shared the project’s source code.

Thus, to follow along in this tutorial, you will need the following:
- Python for data processing and populating the vector database
- Docker and Docker-Compose for running the vector database locally.
- Node.js and npm for running the application locally.
- OpenAI API key to access the OpenAI embedding model
Implementing a Movie Search Engine
This section analyzes Karpathy’s weekend hack and aims to recreate it with its own little twists. To build a simple movie search engine, follow these steps:
- .
Preparation: Movie dataset
Karpathy’s project indexes all 11,762 movies since 1970, including the plot and the summary from Wikipedia.
To achieve something similar without manually scraping Wikipedia, you can use the following two datasets from Kaggle:
- ) for the columns 'id', 'name', 'PosterLink', 'Genres', 'Actors', 'Director', 'Description', 'Keywords', and 'DatePublished'.
- ), for the column 'plot'.
The two datasets are merged on the movie title and release year and then filtered by movies released after 1970. You can find the detailed preprocessing steps in the , which should be used for semantic similarity.
Additionally, the similarity is calculated based on each movie’s Wikipedia summary and plot with two choices for a similarity ranker:
- k-Nearest Neighbor (kNN) using cosine similarity
- Support Vector Machine
Karpathy suggests a combination of under original Tweet (Screenshot by author)
In this project, we will also use the *, an open source vector database. Although I could argue that vector databases are much faster than when you store your embeddings in np.arraybecause they use vector indexing, let’s be honest here: At this scale (thousands), you won’t notice any difference in speed. My main reason for using a vector database here is that Weaviate has many convenient built-in functionalities you can use out of the box, such as automatic vectorization using embedding models.
First, as shown in the embedding model. Additionally, you can define the cosine distance as the similarity measure.
movie_class_schema = {
"class": "Movies",
"description": "A collection of movies since 1970.",
"vectorizer": "text2vec-openai",
"moduleConfig": {
"text2vec-openai": {
"vectorizeClassName": False,
"model": "ada",
"modelVersion": "002",
"type": "text"
},
},
"vectorIndexConfig": {"distance" : "cosine"},
}Next, you define the movie data objects’ properties and for which properties to generate vector embeddings. In the following shortened code snippet, you can see that for the properties movie_id and title no vector embeddings are generated because of the "skip" : True setting for the vectorizer module. This is because, we only want to generate vector embeddings for the description and plot.
movie_class_schema["properties"] = [
{
"name": "movie_id",
"dataType": ["number"],
"description": "The id of the movie",
"moduleConfig": {
"text2vec-openai": {
"skip" : True,
"vectorizePropertyName" : False
}
}
},
{
"name": "title",
"dataType": ["text"],
"description": "The name of the movie",
"moduleConfig": {
"text2vec-openai": {
"skip" : True,
"vectorizePropertyName" : False
}
}
},
# shortened for brevity ...
{
"name": "description",
"dataType": ["text"],
"description": "overview of the movie",
},
{
"name": "Plot",
"dataType": ["text"],
"description": "Plot of the movie from Wikipedia",
},
]
# Create class
client.schema.create_class(movie_class_schema)
Finally, you define a batch process to populate the vector database:
# Configure batch process - for faster imports
client.batch.configure(batch_size=10)
# Importing the data
for i in range(len(df)):
item = df.iloc[i]
movie_object = {
'movie_id':float(item['id']),
'title': str(item['Name']).lower(),
# shortened for brevity ...
'description':str(item['Description']),
'plot': str(item['Plot']),
}
client.batch.add_data_object(movie_object, "Movies")
Step 2: Search for movies
In Karpathy’s project, the search bar is a simple keyword-based search that tries to match your exact query to movie titles verbatim. When some people stated that they expected the search to allow semantic search for movies, Karpathy agreed that this could be a good extension of the project:

- keyword-based search (, which is a combination of keyword-based search and semantic search.
Each of these searches will return num_movies = 20 movies with the properties ['title', 'poster_link', 'genres', 'year', 'director', 'movie_id'].
To enable keyword-based search, you can use a .withBm25() search query across the properties ['title', 'director', 'genres', 'actors', 'keywords', 'description', 'plot']. You can give the property 'title' a bigger weight by specifying 'title^3'.
async function get_keyword_results(text) {
let data = await client.graphql
.get()
.withClassName('Movies')
.withBm25({query: text,
properties: ['title^3', 'director', 'genres', 'actors', 'keywords', 'description', 'plot'],
})
.withFields(['title', 'poster_link', 'genres', 'year', 'director', 'movie_id'])
.withLimit(num_movies)
.do()
.then(info => {
return info
})
.catch(err => {
console.error(err)
})
return data;
}To enable semantic search, you can use a .withNearText() search query. This will automatically vectorize the search query and retrieve its closest movies in the vector space.
async function get_semantic_results(text) {
let data = await client.graphql
.get()
.withClassName('Movies')
.withFields(['title', 'poster_link', 'genres', 'year', 'director', 'movie_id'])
.withNearText({concepts: [text]})
.withLimit(num_movies)
.do()
.then(info => {
return info
})
.catch(err => {
console.error(err)
});
return data;
}To enable hybrid search, you can use a .withHybrid() search query. The alpha : 0.5 means that keyword search and semantic search are weighted equally.
async function get_hybrid_results(text) {
let data = await client.graphql
.get()
.withClassName('Movies')
.withFields(['title', 'poster_link', 'genres', 'year', 'director', 'movie_id'])
.withHybrid({query: text, alpha: 0.5})
.withLimit(num_movies)
.do()
.then(info => {
return info
})
.catch(err => {
console.error(err)
});
return data;
}Step 3: Get similar movie recommendations
To get similar movie recommendations, you can do a .withNearObject() search query, as shown in the aesthetic (I’m not going to bore you with frontend stuff), and voila! You’re all set!
To run the demo locally, clone the Additionally, run the following command in the directory to install all required dependencies in your virtual environment.
pip install -r requirements.txt
Next, set your OPENAI_API_KEY in the docker-compose.yml file and run the following command to run Weaviate locally via Docker.
docker compose up -d
Once your Weaviate instance is up and running, run the add_data.py file to populate your vector database.
python add_data.py
Before you can run your application, install all required node modules.
npm install
Finally, run the following command to start up your movie search engine application locally.
npm run start
Now, navigate to :

Enjoyed This Story?
, !
Disclaimer
- At the time of writing, I am a developer advocate at .
- This project is not an original idea: The project is inspired by
on Medium, where people are continuing the conversation by highlighting and responding to this story.
SOCIAL SHARE CARD GENERATOR