Loading…
Building a Movie Recommendation Engine with Hugging Face and Voyage AI
MongoDBArek Borucki
Summary
Traditional movie search mechanisms depend on coarse filters such as genre, actor, or title, which fail to capture emotional context and narrative nuances. This guide demonstrates building a mood-based semantic recommendation system by combining the voyage-4-nano open-weights embedding model, Hugging Face datasets, and MongoDB Atlas Vector Search. The architecture uses Sentence Transformers to generate embeddings and exposes an endpoint through FastAPI to match user moods against movie plots. Truncating the Matryoshka embeddings from 2048 to 1024 dimensions balances semantic retrieval quality, storage footprint, and query latency. Testing shows that while abstract emotional queries return moderate similarity scores around 0.62 to 0.67, concrete descriptive queries exceed 0.75 without requiring exact keyword matches.
Context
Traditional movie search relies on coarse metadata filtering like genres, actors, or titles, which cannot capture nuanced emotional states or abstract intents such as searching for an uplifting or cathartic film.
Approach / What changed
The implementation deploys the open-weight voyage-4-nano embedding model using Sentence Transformers, indexes over 1500 movie plot summaries from Hugging Face into MongoDB Atlas Vector Search, and serves semantic search via a FastAPI application using 1024-dimension Matryoshka embeddings.
Takeaways
- The voyage-4-nano model uses asymmetric encoding prompts to improve retrieval quality by distinguishing between query representations and document representations.
- Matryoshka embeddings allow truncating vector dimensions from 2048 to 1024 or 512, balancing storage overhead and search latency while preserving ranking stability.
- Concrete descriptive mood queries achieve higher semantic similarity scores (0.75+) compared to abstract emotional concepts (0.62 to 0.67).
Related reading
Sentence Transformers is joining Hugging Face!
Sentence Transformers is officially transitioning its stewardship from the Ubiquitous Knowledge Processing Lab at TU Darmstadt to Hugging Face. The open-source embedding library was introduced in 2019 by Nils Reimers using a Siamese network architecture to overcome standard BERT limitations on sentence-level semantics. Tom Aarsen of Hugging Face has maintained the project since late 2023 and will continue leading its development. Under Hugging Face, the project retains its Apache 2.0 license and leverages infrastructure such as continuous integration and automated testing. Sentence Transformers currently serves over one million monthly unique users, with more than 16,000 community models publicly hosted on the Hugging Face Hub.
Tom AarsenWelcome EmbeddingGemma, Google's new efficient embedding model