Skip to main content
Glama
README.md
## Description

A movie recommender built as a GraphRAG MCP server on Neo4j 5.22. Movies, directors, genres and topic keywords are stored as a graph, and their embeddings from EmbeddingGemma live in the same database, so vector search and graph traversal run in a single query without a separate vector store. When a user asks for a movie in Korean, Gemma2 handles query rewriting, vector search finds the closest matches, and the graph connects them to other films by the same director and to films that share the same topics. This gives the answer context that vector search alone cannot provide. Both HyDE and HyPE are included for the search step, so the two can be tested side by side.

## Graph

```
(:Person)-[:DIRECTED]->(:Movie)-[:HAS_GENRE]->(:Genre)
(:Question)-[:ABOUT]->(:Movie)
(:Movie)-[:HAS_KEYWORD]->(:Keyword)
```

Genres are separate nodes, so movies that share a genre are linked through the same node.

Keywords work the same way. Gemma2 extracts 3-5 topic keywords from each movie, and movies that share two or more keywords are listed as similar movies. Chappie, for example, is linked to I, Robot through "robot" and "artificial intelligence", while the same director's District 9 is not. Keywords used by more than 20 movies, such as action or crime, are skipped because they work like genres.

## Search

 - HyDE: generates a hypothetical plot for the request and compares it with movie plots
 - HyPE: compares the request with hypothetical questions generated for each movie in advance (used by the MCP server)

HyDE matches plot against plot. HyPE matches question against question.

With 300 movies, HyPE put the right movies higher for requests about a subject or setting, such as a magic school or a prison escape. HyDE did better when the request reads like a plot, such as being stranded alone in space, but it needs one more Gemma2 call per request. The better choice depends on the data and on what users tend to ask, so both are kept for comparison.

## Structure

```
app.js                      MCP server
chat.js                     function calling chat in the terminal
lib/                        Neo4j driver, Ollama client, .env loader
services/
  recommend-hype.js
  recommend-hyde.js
  recommend-langchain.js    HyPE search written with LangChain.js
  find-by-director.js
  find-similar.js
ingest/
  hype.js                   builds the graph with plot and question indexes and keywords (HyPE)
  hyde.js                   builds the graph with the plot index and keywords (HyDE)
data/
  movies.csv
  questions.json            cached HyPE questions
  keywords.json             cached keywords
```

## Run

```bash
ollama pull gemma2
ollama pull embeddinggemma
npm install
node ingest/hype.js
npm run inspect
```

Requires Neo4j 5.11+ and Ollama. Copy `.env.example` to `.env` and fill in your connection settings.

## MCP

```bash
claude mcp add movie-rag -- node /path/to/GraphRAG_MCP_Movie_Recommender/app.js
```

The MCP server has three tools.

 - `recommend_movies`: searches by mood, setting or theme and returns the matched movies with their directors' other works, similar movies and plots
 - `find_by_director`: returns the movies made by a director
 - `find_similar`: returns movies that share keywords with a given movie, most shared first

`recommend_movies` takes requests about mood, setting or theme, so it runs query rewriting with Gemma2 before the vector search. `find_by_director` and `find_similar` only need a director's name or a movie title, so they skip query rewriting.

The client model, such as Claude, decides which tool to call from the request, and can call more than one when needed. For a request like "movies like Inside Out", for example, it looks for movies that share keywords with Inside Out and also searches by its theme. It then writes the answer from the results.

`recommend_movies` uses HyPE by default. To use HyDE, import `recommendHyde` from `services/recommend-hyde.js` in `app.js` and call it instead of `recommendHype`.

Running `ingest/hyde.js` removes the question nodes' links, so run `ingest/hype.js` again before using the MCP server.

## Function Calling

```bash
ollama pull qwen2.5
node chat.js
```

The same search also works without MCP. `chat.js` registers `recommendHype` as a tool for qwen2.5 and runs it in the same process when the model calls it. Gemma2 is not used here because Ollama does not support tool calling for it. Press Enter on an empty line to quit.

## LangChain

`services/recommend-langchain.js` is the same HyPE search, written with LangChain.js to compare it with calling Ollama and Neo4j directly. The prompt, Gemma2 call and JSON parsing are joined into one chain, and the vector search runs through `Neo4jVectorStore` with the same graph query. Both return the same movies and search scores.

## Example

Recommending by theme (`recommend_movies`)

![Recommend](./data/mcp_recommend.png)

Other movies by a director (`find_by_director`)

![Director](./data/mcp_director.png)

Movies like Inside Out (`find_similar` and `recommend_movies`)

![Similar](./data/mcp_similar.png)

Function calling with qwen2.5

![Function calling](./data/function_calling.png)

## Note

 - The dataset ends in 2017.
 - Other works by the same director are listed because they share the director, not because their stories are similar.
 - The earlier version, without keywords and with Gemma2 writing the answer, is on the `basic` branch.

TDQS

B3.4/5.0

Scored across 1 tool

Disambiguation4/5

With only one tool there is no risk of misselection between tools. However, the single tool internally bundles several behaviors (natural-language candidate search, same-director lookup, thematic similarity, and final top-3 selection), so an agent cannot target a specific sub-capability.

Naming Consistency5/5

The sole tool name 'recommend_movies' follows a clear verb_noun snake_case convention and is descriptive of its action. There is no second name to conflict with, so consistency is trivially satisfied.

Tool Count2/5

A single monolithic tool that performs graph search, similarity traversal, ranking, and recommendation in one call is too coarse for the apparent scope. Splitting into search/related/recommend operations would give the agent meaningful control.

Completeness2/5

The surface offers only end-to-end recommendation; there is no way to look up a specific movie, list a director's filmography, filter by genre/theme, or inspect why a candidate was retrieved. Agents will hit dead ends when they need details or refinement beyond the initial three picks.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues