# Movie Plot Embeddings Generator This Python script fetches movie plots from a Neo4j database, generates text embeddings using Ollama's nomic-embed-text model, and stores the embeddings in a CSV file. ## Prerequisites Before running this script, you need to have: 1. **Ollama** installed and running: - Download and install from [https://ollama.com/](https://ollama.com/) - Pull the required embedding model: ``` ollama pull nomic-embed-text:v1.5 ``` - Ensure Ollama is running locally (default endpoint: http://localhost:11434) 2. **Neo4j database**: - Running Neo4j instance with movie data - Database should contain Movie nodes with: - `movieId` property (integer) - `plot` property (text) 3. **Python environment** with the required packages ## Installation 1. Clone this repository or create a new directory for the project 2. Create a virtual environment: ```bash python -m venv venv source venv/bin/activate # Linux/MacOS) venv\Scripts\activate # Windows ``` 3. Install dependencies: ```bash pip install -r requirements.txt ``` ## Configuration Edit the following variables in the Python script: ```python # ==== CONFIG ==== NEO4J_URI = "bolt://1.2.3.4:7687" # Your Neo4j connection URI NEO4J_USER = "neo4j" # Neo4j username NEO4J_PASSWORD = "your-password" # Neo4j password CSV_FILENAME = "movie_embeddings.csv" # Output CSV file name OLLAMA_EMBEDDING_MODEL = "nomic-embed-text:v1.5" # Embedding model OLLAMA_ENDPOINT = "http://localhost:11434/api/embeddings" # Ollama endpoint ``` ## Usage 1. Ensure Ollama is running: ```bash ollama serve ``` 2. Run the script: ```bash python generate_embeddings.py ``` 3. The script will: - Connect to your Neo4j database - Fetch movie plots - Generate embeddings using Ollama - Save results to the specified CSV file - Show progress with a progress bar ## Output The output CSV file will have the following format: ``` movieId,embedding 1,"[0.123456,-0.078912,0.045621,...]" 2,"[0.034567,-0.091234,0.023456,...]" ... ``` Each embedding is stored as a string representation of a float array. ## Customization 1. To use a different embedding model: - First pull the model with Ollama (e.g., `ollama pull llama3`) - Update the model name in the configuration: ```python OLLAMA_EMBEDDING_MODEL = "llama3" ``` ## Troubleshooting 1. **Connection errors to Neo4j**: - Verify your Neo4j instance is running - Check URI, username and password - Test connection with Neo4j Browser 2. **Ollama connection issues**: - Ensure Ollama is running (`ollama serve`) - Verify model is downloaded (`ollama list`) - Test the endpoint: ```bash curl http://localhost:11434/api/embeddings -d '{"model": "nomic-embed-text:v1.5", "prompt": "test"}' ``` 3. **CSV formatting issues**: - Ensure the embedding array is properly formatted as a string - Verify all values are floats ## Dependencies - Python 3.7+ - Packages: - `neo4j` (Neo4j Python driver) - `requests` (HTTP requests) - `tqdm` (progress bars) ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.