Skip to content

neo4j-graph-examples/recommendations

Repository files navigation

icon movie

Recommendations Graph Example

Description: Generate personalized real-time recommendations using a dataset of movie reviews

Nodes 28863 Relationships 166261

model
Figure 1. Model
example
Figure 2. Example
Example Query:
MATCH (m:Movie {title:$movie})<-[:RATED]-(u:User)-[:RATED]->(rec:Movie)
RETURN distinct rec.title AS recommendation LIMIT 20

Setup

This is for Neo4j version: 4.0

The database is also available on https://demo.neo4jlabs.com:7473

Username "recommendations", password: "recommendations", database: "recommendations"

Load graph data via the following:

Dump file: data/recommendations-40.dump

  • Drop the file into the Files section of a project in Neo4j Desktop. Then choose the option to Create new DBMS from dump option from the file options.

  • Use the neo4j-admin tool to load data from the command line with the command below.

bin/neo4j-admin database load --from data/recommendations-40.dump [--database "database"]

Embeddings

The data/recommendations-embeddings-aligned-5.26.dump and data/recommendations-embeddings-block-5.26.dump files ship with pre-computed vector embeddings on Movie and Person nodes. The other dumps do not contain embeddings.

Node Property Model Dim Encoded from

Movie

plotEmbedding

OpenAI text-embedding-ada-002

1536

f"{title}: {plot}"

Movie

posterEmbedding

sentence-transformers/clip-ViT-B-32 (OpenAI CLIP)

512

poster image

Person

bioEmbedding

OpenAI text-embedding-ada-002

1536

bio text

Same dimensions does not mean the same vector space — querying these embeddings requires the same model that produced them:

  • plotEmbedding / bioEmbedding — use OpenAI text-embedding-ada-002. Do not substitute text-embedding-3-small/-large (same 1536 dim, different space, returns garbage scores).

  • posterEmbedding — use sentence-transformers/clip-ViT-B-32, or its multilingual sibling sentence-transformers/clip-ViT-B-32-multilingual-v1 which was distilled to align to the same vector space and lets you query with text in 50+ languages. Run locally with sentence-transformers, or call the HuggingFace Inference API. OpenAI’s API does not expose CLIP.

The source CSVs and the Python scripts that produced these embeddings are at https://data.neo4j.com/rec-embed/README.html.

Code Examples

GraphQL API

See /graphql directory for Node.js GraphQL API server example using @neo4j/graphql

Feedback

Feel free to submit issues or pull requests for improvement on this repository.