Want to build an application that provides personalized game recommendations? This tutorial will guide you step-by-step through the use of Retrieval Augmented Generation (RAG) techniques, combined with the DeepSeek cap (a poem) Ollama model to create a customized game recommendation system.
We'll be using the Epic Games Store dataset for the games.csv
file as a data source. The technology stack choices for this tutorial are as follows:
- Large Language Model (LLM): We will use Ollama to run the
deepseek-r1:1.5b
Model. - Embedding Model: We will use Weaviate's
text2vec_openai
component with the defaulttext-embedding-3-small
Model.
Step 1: Install dependent libraries and configure API keys
First, you'll need to install the following Python libraries, which are required to build and run the RAG necessary for the application.
!pip install weaviate-client pandas tqdm ollama
Next, in order to use OpenAI's embedding model, you need to set up the OpenAI API key. If you haven't set it up yet, follow these steps:
from getpass import getpass
import os
if "OPENAI_APIKEY" not in os.environ: os.environ["OPENAI_APIKEY"] = getpass("Enter your OpenAI API Key")
os.environ["OPENAI_APIKEY"] = getpass("Enter your OpenAI API Key")
This code checks to see if OPENAI_APIKEY already exists in your environment variables, and if it doesn't, it prompts you to enter your OpenAI API key and set it as an environment variable.
Step 2: Run the DeepSeek model
This tutorial uses Ollama to run the deepseek-r1:1.5b model locally. If you haven't installed Ollama and pulled the deepseek-r1:1.5b model yet, please refer to the official Ollama Docs to complete the installation and model pulling.
On macOS, for example, you can run the DeepSeek model in Terminal using the following command:
ollama run deepseek-r1:1.5b
Ensure that the model runs successfully before proceeding to the next step.
Step 3: Create and populate the Weaviate collection
Weaviate collections are used to store and retrieve game data. Follow the steps below to create and populate your Weaviate collection:
- Download games.csv file: Download games.csv file from Kaggle (Kaggle) to your local directory.
- Starting the Weaviate Docker Container: Start Weaviate using the following docker-compose.yml file and make sure the generative-ollama and text2vec-openai modules are enabled. Save the following as a docker-compose.yml file and start Weaviate in a terminal using the command docker compose up.
---
services.
weaviate_anon.
command:
--host
- 0.0.0.0
--port
- '8080'
---scheme
- http
image: cr.weaviate.io/semitechnologies/weaviate:1.28.4
ports.
- 8080:8080
- 50051:50051
restart: on-failure:0
environment.
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
ENABLE_API_BASED_MODULES: 'true'
BACKUP_FILESYSTEM_PATH: '/var/lib/weaviate/backups'
CLUSTER_HOSTNAME: 'node1'
LOG_LEVEL: 'trace'
ENABLE_MODULES: "text2vec-openai,generative-ollama"
...
- Creating the "Games" Collection: Run the following Python code to create a Weaviate collection called "Games". This code defines the properties of the collection, including game name, price, platform, release date, and description, and configures the generative-ollama and text2vec-openai modules.
import weaviate
import weaviate.classes.config as wc
from weaviate.util import generate_uuid5
from weaviate.util import generate_uuid5
from tqdm import tqdm
import pandas as pd
headers = {"X-OpenAI-Api-Key": os.getenv("OPENAI_APIKEY")}
client = weaviate.connect_to_local(headers=headers)
if client.collections.exists("Games"):: client.collections.delete("Games").
client.collections.delete("Games")
client.collections.create(
client.collections.create() name="Games",
properties=[
wc.Property(name="name", data_type=wc.DataType.TEXT),
wc.Properties(name="price", data_type=wc.DataType.INT),
wc.Property(name="platforms", data_type=wc.DataType.TEXT_ARRAY), wc.Property(name="platforms", data_type=wc.DataType.TEXT_ARRAY), wc.
wc.Property(name="release_date", data_type=wc.DataType.DATE), wc.Property(name="release_date", data_type=wc.DataType.DATE), wc.
wc.Property(name="description", data_type=wc.DataType.TEXT),
],
generative_config=wc.Configure.Generative.ollama(model="deepseek-r1:1.5b",
api_endpoint="http://host.docker.internal:11434"),
vectorizer_config=wc.Configure.Vectorizer.text2vec_openai(), )
)
- Importing Game Data: Use the following code to import the data from the games.csv file into the "Games" collection. The code reads the CSV file and converts each row of data into Weaviate objects, which are then added to the collection in bulk.
games = client.collections.get("Games")
df = pd.read_csv('games.csv')
with games.batch.dynamic() as batch: for i, game in tqdm(df.iterrows())
for i, game in tqdm(df.iterrows()): platforms = game["platform"].
platforms = game["platform"].split(',') if type(game["platform"]) is str else []
game_obj = {
"name": game["name"],
"platforms": platforms, "price": game["price"], game["platform"], game["platform"] is str else
"description": game["description"],
}
batch.add_object(
properties=game_obj,
uuid=generate_uuid5(game["id"])
)
if len(games.batch.failed_objects) > 0:.
print(f "Failed to import {len(games.batch.failed_objects)} objects")
print(games.batch.failed_objects)
Step 4: Perform an embedded search
Now, your "Games" collection is populated with data. You can try an embedded search to retrieve games related to the user's query. The following code demonstrates how to query for games related to "I play the vilain" and return the 3 most relevant results.
response = games.query.near_text(query="I play the vilain", limit=3)
for o in response.objects: print(o.properties)
print(o.properties)
This code outputs information about the attributes of the 3 games relevant to the query, such as platform, description, price, release date and name.
Step 5: Build the Recommended RAG Application
In order to implement smarter game recommendations, we need to create a RAG application. The following recommend_game function accomplishes this. It takes a user query as input, retrieves the 5 most relevant games, and uses the deepseek-r1:1.5b model to generate personalized recommendations.
def recommend_game(query: str):
response = games.generate.near_text(
query=query,
query=query, limit=5,
grouped_task=f"""You've been provided some relevant games based on the users query.
Provide an answer to the query. Your final answer MUST indicate the platform each game is available on.
User query: {query}""","
grouped_properties=["name", "description", "price", "platforms"], )
)
return {'thought': response.generated.split('')[0], 'recommendation': response.generated.split('')[1]}
This function uses the games.generate.near_text method, which not only performs a vector search, but also utilizes the generative model to generate recommended text based on the retrieved game information. the grouped_task parameter defines the model's generative task, instructing the model to generate an answer based on the user's query and retrieved game information, and explicitly requesting that the answer include the information about the game platform.
You can test your game recommendation application by calling the recommend_game function and passing in a user query. For example, the query "What are some games that I get to role play a magical creature".
response = recommendation_game("What are some games that I get to role play a magical creature")
print(response['recommendation'])
Run this code and you will see the results of the game recommendations generated by the model, for example:
Here are several games that allow you to role-play as a magical creature.
1.**Mages of Mystralia**
- **Platform:** Windows
- Description: A fantasy RPG where you design your own spells in a world of magic, allowing creativity and flexibility.
2. **Geneforge 1 - Mutagen** **Platforms:** Windows Description.
- **Platforms:** Windows, Mac
- Description: An open-ended RPG with mutant monsters, multiple skills, treasures, factions, and creation possibilities, offering unparalleled Freedom and replayability.
- **Platform:** Windows
- Description: A 3D adventure game where you role as a wildlife photographer exploring magical ecosystems, focusing on behavior learning for A 3D adventure game where you role as a wildlife photographer exploring magical ecosystems, focusing on behavior learning for photography.
4. **Paper Beast** **Platforms:** Windows
- **Platforms:** Windows (PC)
- Description: An adventure game about disrupting wildlife balance with a focus on exotic creatures and mystery-solving.
5. **Black Book** **Platform:** **Windows (PC) Description.
- **Platform:** Windows
- Description: A dark RPG based on Slavic myths, played as a young sorceress in a world of mythological creatures through card-based battles.
Each game offers unique experiences suitable for role-playing as a magical creature.
If you want to see what the model is thinking about when generating recommendation results, you can print the response['thought'] property:
print(response['thought'])
This will output the model's thought process in the background and help you better understand the recommendation logic.
Okay, so I need to figure out some games that let me role-play as a magical creature. The user provided several options, each with a description and platform Let me go through them one by one.
First up is "Mages of Mystralia." From the description, it's a fantasy RPG where you design your own spells in a world of magic. That sounds perfect because it allows for a lot of creativity as a magical creature. The platform is Windows, so maybe the user can run it on their PC or any desktop system.
Next is "Geneforge 1 - Mutagen." This seems like an open-ended RPG with mutant monsters and a battle mechanic. It's described as having countless skills, treasures, factions, and creations. It's described as having countless skills, treasures, factions, and creation possibilities. Unmatched freedom and replayability make sense because it allows for various storylines. Unmatched freedom and replayability make sense because it allows for various storylines. The platform here is Windows and Mac, so compatible options would be useful.
Then there's "Beasts of Maravilla Island." As the name suggests, it's a 3D adventure game where you take on a wildlife photographer exploring ecosystems. It focuses on behavior learning and photography, which could be exciting for someone looking to role-play in nature. The platform is Windows, so that The platform is Windows, so that should be accessible.
The platform is Windows, so that should be accessible. "Paper Beast" is another adventure game mentioned. It's about an unknown power disrupting wildlife balance, with players joining exotic creatures to solve mysteries. While it's PC-focused, maybe there are porting options available or different devices that can run it if the user has access to them.
Lastly, "Black Book." This dark RPG is based on Slavic myths and played as a young sorceress. It involves card-based battles in a world with mythological creatures. The platform here is Windows, so maybe older hardware might be a bit limiting unless the user has an updated PC or a dedicated console.
I should make sure each game is listed clearly with their platforms and any necessary details about how they work as magical creatures. Also, it's good to Also, it's good to offer a couple of options if some aren't available. Maybe suggest cross-platform games or platforms that can be used for playing.
</Maybe suggest cross-platform games or platforms that can be used for playing.
Congratulations! You have successfully built a game recommendation RAG application based on DeepSeek and Ollama. In this tutorial, you have learned the basics of how to build a personalized recommendation system using RAG techniques combined with a large language model and a vector database. You can extend and improve the application according to your needs, such as adding more game data, optimizing the recommendation algorithm, or developing the user interface to create a better game recommendation service.