You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/uc/personalized_recommendations.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,16 @@
1
-
Imagine you’re building a movie recommendation app that goes beyond simple keyword matching. Your users want recommendations based on the meaning of the movie plots — an intuitive and meaningful search experience powered by semantic understanding.
1
+
Imagine building a movie recommendation app that goes beyond keyword matching. Your users get intuitive, meaningful suggestions based on the true meaning of movie plots — powered by semantic understanding.
2
2
3
3
### Store Movie Documents with Vector Embeddings
4
-
Semantic search uses vector embeddings — numerical representations of text that capture the meaning of sentences. This enables search by intent rather than just keywords.
5
-
Let’s import a dataset containing plot summaries, each paired with an embedding vector.
4
+
Semantic search uses vector embeddings — numeric representations of text that capture meaning, enabling search by intent rather than keywords.
5
+
6
+
We'll import a dataset of plot summaries, each paired with an embedding vector.
7
+
6
8
Each movie is stored as a JSON document with:
7
-
- `title`, `genres`, `year`, `plot`
8
-
- `embedding`, which is a binary-encoded `FLOAT32[]`used for vector similarity that can be generated using sentence-transformers or similar libraries. Demo uses 8-dim vectors; production models typically use 128–1536 dimensions.
9
+
-`title`, `genres`, `year`, `plot`
10
+
-`embedding`: a binary-encoded `FLOAT32[]` for vector similarity, generated via sentence-transformer models or similar.
9
11
10
12
```redis:[run_confirmation=true] Upload Movies
13
+
// Demo uses 8 DIM embeddings; production typically uses 128–1536D.
11
14
JSON.SET movie:001 $ '{"title":"Toy Story","genres":["Animation","Comedy","Family"],"plot":"Toys come to life when humans arent around.","year":1995,"embedding":[0.22,0.04,0.33,0.12,-0.02,0.17,0.09,0.01]}'
12
15
JSON.SET movie:002 $ '{"title":"Inside Out","genres":["Animation","Comedy","Drama"],"plot":"Emotions guide a young girl through change.","year":2015,"embedding":[0.20,0.03,0.31,0.11,-0.03,0.16,0.08,0.02]}'
13
16
JSON.SET movie:003 $ '{"title":"Whiplash","genres":["Drama","Music"],"plot":"A young drummer is pushed to greatness.","year":2014,"embedding":[0.14,0.01,0.22,0.08,-0.07,0.10,0.04,0.00]}'
@@ -66,7 +69,7 @@ JSON.SET movie:55 $ '{"title":"All That Jazz","year":1979,"genres":["Drama","Mus
66
69
```
67
70
68
71
### Create a Vector-Enabled Search Index
69
-
Redis stores movie data as JSON documents with text fields (title, genres, plot) and vector embeddings. Creating an index lets you quickly filter documents and run fast approximate nearest neighbor (ANN) searches on embeddings.
72
+
Redis stores movie data as JSON documents with text fields (title, genres, plot) and vector embeddings. Indexing enables fast filtering and approximate nearest neighbor (ANN) searches on embeddings.
70
73
71
74
```redis:[run_confirmation=true] Create a Vector Index
72
75
FT.CREATE idx:movies ON JSON PREFIX 1 "movie:" SCHEMA
This sets the stage for combined textual and semantic search.
85
88
86
89
### Semantic Search by Query Embedding
87
-
When users search: “I want a fun animated movie about toys and friendship.”, you can generate embeddings using models like text-embedding-3-small from OpenAI, or sentence-transformers from Hugging Face. These models turn text into numerical vectors you can store and query with Redis.
90
+
When users search “I want a fun animated movie about toys and friendship”, sentence-transformers models can convert the text into a vector. You can store and query this vector in Redis for semantic search.
88
91
89
92
```redis:[run_confirmation=false] Search Per Plot
90
93
FT.SEARCH idx:movies "*=>[KNN 3 @embedding $vec AS score]"
@@ -119,7 +122,7 @@ Let’s say you love Inception and want similar movies. Let’s retrieve the Inc
119
122
```redis:[run_confirmation=false] Get the Embedding From the Movie Document
120
123
JSON.GET movie:006 $.embedding
121
124
```
122
-
Now let’s run vector similarity search using that embedding as a binary blob (FLOAT32-packed):
125
+
Now let’s run vector similarity search using that embedding as a binary blob (`FLOAT32`-packed):
123
126
124
127
```redis:[run_confirmation=false] Search for Similar Movies
125
128
FT.SEARCH idx:movies "*=>[KNN 5 @embedding $vec AS score]"
This makes Redis recommendations responsive to evolving user preferences without retraining embeddings.
156
159
157
160
### Next Steps
158
-
- Build a UI that lets users type natural language queries and get semantic recommendations instantly
159
-
- Add personalization by combining user preferences with semantic search
160
-
- Explore advanced vector search techniques like HNSW indexing for large datasets
161
+
- Learn more about building personalized recommendations with this [workshop](https://github.com/redis-developer/redis-movies-searcher/tree/springio-2025-workshop).
162
+
- Build a UI for natural language queries that delivers instant semantic recommendations.
163
+
- Add personalization by merging user preferences with semantic search.
164
+
- Explore advanced vector search methods like HNSW indexing for large datasets.
0 commit comments