Skip to main content
← Back to Projects
Development

GraphRAG Movie Recommendation Engine

Hybrid recommendation system combining knowledge graphs with vector search

A movie recommendation engine that combines collaborative filtering, knowledge graph traversal, and semantic search for contextually aware, explainable recommendations — 25% better than collaborative filtering alone.

PythonNeo4jPyTorchSentence TransformersStreamlitFastAPIDocker

Problem

Traditional collaborative filtering recommendation systems suffer from the cold-start problem, lack explainability, and fail to capture nuanced user preferences beyond 'users like you also liked.' A user who loves Christopher Nolan films for their exploration of time and reality won't get that from a matrix factorization algorithm — they'll just get 'more action movies.' The gap between surface-level genre matching and genuine taste understanding is enormous.

Solution

GraphRAG Movie Recommender builds a rich knowledge graph connecting movies, actors, directors, themes, and user preferences. Recommendations come from hybrid retrieval — collaborative filtering signals + graph-based relationship traversal + semantic search over movie descriptions. Every recommendation includes an explainable path through the knowledge graph, so users understand not just what to watch but why.

Architecture

Three-component hybrid: collaborative filtering (PyTorch matrix factorization), knowledge graph traversal (Neo4j with custom Cypher queries), and semantic search (Sentence Transformers + FAISS). Ensemble ranking with diversity constraints. Real-time serving at <100ms.

Challenges

  • Balancing accuracy vs. diversity — pure accuracy leads to recommendation bubbles; solved with MMR (Maximal Marginal Relevance) re-ranking
  • Cold-start for new users — 5 onboarding ratings bootstrap graph-based recommendations that match warm-start quality
  • Real-time graph traversal latency — built caching layer for common traversal patterns, reducing p99 from 400ms to 85ms

Results

  • 25% improvement in NDCG@10 over pure collaborative filtering baseline (evaluated on MovieLens 25M)
  • Explainable recommendation paths increased user trust scores by 40% in A/B test (n=500)
  • Cold-start recommendation quality matched warm-start within 5 explicit ratings
  • Real-time serving at < 85ms p99 per recommendation

Lessons Learned

  • Knowledge graphs shine for explainability — users trust 'because you liked X director and Y theme' infinitely more than a black-box similarity score
  • Hybrid systems are harder to build but dramatically better than any single approach — the ensemble consistently outperforms each component alone
  • Graph traversal caching is critical for latency — the most common paths (same director, shared actors) account for 80% of queries

System Architecture

                    ┌──────────────────────────────────┐
                    │          User Query / Profile      │
                    └──────────────┬───────────────────┘
                                   │
          ┌────────────────────────┼────────────────────────┐
          │                        │                        │
          ▼                        ▼                        ▼
┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│  Collaborative   │    │ Knowledge Graph │    │   Semantic       │
│   Filtering      │    │    Traversal    │    │    Search        │
│                  │    │                 │    │                  │
│ · Matrix Factor. │    │ · Director path  │    │ · SBERT embeddings│
│ · User similarity│    │ · Actor overlap  │    │ · FAISS index    │
│ · Implicit signal│    │ · Theme clusters │    │ · Description sim│
└────────┬─────────┘    └────────┬────────┘    └────────┬─────────┘
         │                       │                      │
         └───────────────────────┼──────────────────────┘
                                 │
                                 ▼
                    ┌──────────────────────────────────┐
                    │       Ensemble Ranking            │
                    │  · Score normalization            │
                    │  · Diversity constraint (MMR)     │
                    │  · Explanation path generation   │
                    └──────────────┬───────────────────┘
                                   │
                                   ▼
                    ┌──────────────────────────────────┐
                    │       Ranked Recommendations      │
                    │  Movie + Explanation + Confidence │
                    └──────────────────────────────────┘

The Knowledge Graph

The core of the system is a property graph in Neo4j:

  • Movies: title, year, runtime, rating, box office, tagline
  • People: actors, directors, writers, composers — with roles and relationships
  • Genres: hierarchical — Action → Sci-Fi Action, Drama → Psychological Drama
  • Themes: extracted from 50M+ reviews using topic modeling (BERTopic)
  • Users: explicit ratings, watch history, preference weights

Key relationships: ACTED_IN, DIRECTED, BELONGS_TO, HAS_THEME, RATED, SIMILAR_TO.

How Recommendations Are Generated

1. Collaborative Filtering

Matrix factorization on the user-item rating matrix captures latent taste factors. This handles the "users like you" signal but provides no explanation — scores are coordinates in an opaque embedding space.

2. Knowledge Graph Traversal

Given a user's highly-rated movies, traverse paths through the graph: same director (1-hop), shared actors (2-hop), similar themes (1-hop through theme nodes). Each path has a weight based on relationship type and user preference signals. This is where explainability comes from.

3. Semantic Search

Movie descriptions and 50M+ reviews are embedded with Sentence Transformers. FAISS index enables similarity search over descriptive content — captures "feel" and "vibe" that structured graph data misses.

4. Ensemble Ranking

Scores from all three components are normalized and merged. MMR re-ranking ensures diversity — prevents recommending five Christopher Nolan films in a row. Explanation paths are generated by tracing the highest-weight graph traversal that contributed to each recommendation.

"Recommended because you rated Inception 5 stars. Interstellar shares director Christopher Nolan, themes of time and reality, and is highly rated by users with your taste profile."