Skip to main content
Glama
README.md
## Description

This boilerplate shows how to build a GraphRAG MCP server on Neo4j 5.22, using movie recommendation as the example. Movies, directors and genres 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 cleans up the request with 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 picks 3-5 topic keywords for each movie, and movies that share two or more keywords are listed as similar movies. Keywords used by more than 20 movies, such as action or crime, are skipped because they work like genres. Chappie, for example, is linked to I, Robot through "robot" and "artificial intelligence", while the same director's District 9 is not.

## Search

 - HyDE : writes a fake plot for the request and compares it with movie plots
 - HyPE : compares the request with 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 test both before extending this.

## Structure

```
app.js                      MCP server
lib/                        Neo4j driver, Ollama client, .env loader
services/
  recommend-hype.js
  recommend-hyde.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. Connection settings are in `.env`.

## MCP

```bash
claude mcp add movie-rag -- node /path/to/GraphRAG-MCP-Boilerplate/app.js
```

The MCP server returns the matched movies with their directors' other works, similar movies and plots, and the client model such as Claude picks three and writes the recommendation. It 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.

## Example

![Result](./example2.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