Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError for Shapes when using Neo4j. #2364

Open
parshvadaftari opened this issue Mar 11, 2025 · 6 comments · May be fixed by #2377
Open

ValueError for Shapes when using Neo4j. #2364

parshvadaftari opened this issue Mar 11, 2025 · 6 comments · May be fixed by #2377

Comments

@parshvadaftari
Copy link
Contributor

parshvadaftari commented Mar 11, 2025

🐛 Describe the bug

When using only the Neo4j as graph_store and setting the embeddings dimension to something less than 1534 gives the below error. Also gives the deprecation warning for the langchain-neo4j package.

import os
from mem0 import Memory

config = {
    "embedder": {
        "provider": "openai",
        "config": {
            "api_key": os.getenv("OPENAI_API_KEY"),
            "model": "text-embedding-3-small",
            "embedding_dims": 384,
        },
    },
    "graph_store": {
        "provider": "neo4j",
        "config": {
            "url": "neo4j+s://xxxxxxx.databases.neo4j.io",
            "username": "neo4j",
            "password": "xxxxxxxxxxx"
        }
    }
}


m = Memory.from_config(config)
messages = [
    {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
    {"role": "assistant", "content": "How about a thriller movie? They can be quite engaging."},
    {"role": "user", "content": "I’m not a big fan of thriller movies but I love sci-fi movies."},
    {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
add_result = m.add(messages, user_id="alice", metadata={"category": "movies"})

ERROR:

ValueError: shapes (0,1536) and (384,) not aligned: 1536 (dim 1) != 384 (dim 0)
@alokjha2
Copy link

Hello, I have recreated this bug. The issue is caused by "embedding_dims": 384. To fix it, you need to change it to "embedding_dims": 1536.

I have attached the image of reproduced bug

Image

@parshvadaftari
Copy link
Contributor Author

@alokjha2 It's not the solution to the bug. As many embedding models don't support more than 768 dims for eg: nomic. Then this fix cannot solve the issues which is faced.

@parshvadaftari
Copy link
Contributor Author

@Dev-Khant I can pick this issue!

@alokjha2
Copy link

I checked this code, and it works with the dimension set to 1536.

Regarding your statement: "It's not the solution to the bug, as many embedding models don't support more than 768 dimensions (e.g., Nomic). This fix cannot resolve the issue being faced."

Yes, many embedding models don’t support more than 768 dimensions, but the model the user is using for embedding generation supports 1536

@alokjha2
Copy link

And if you think something else is causing this issue, what do you believe it is, and how would you approach fixing it?

@parshvadaftari
Copy link
Contributor Author

I checked this code, and it works with the dimension set to 1536.

Regarding your statement: "It's not the solution to the bug, as many embedding models don't support more than 768 dimensions (e.g., Nomic). This fix cannot resolve the issue being faced."

Yes, many embedding models don’t support more than 768 dimensions, but the model the user is using for embedding generation supports 1536

This embedding model does but not every right. So in short this becomes a feature request where you can set any supported embedding dimensions. I'm still looking into it where the issue is occuring. Will link the PR once solved.

parshvadaftari added a commit to parshvadaftari/mem0 that referenced this issue Mar 13, 2025
@parshvadaftari parshvadaftari linked a pull request Mar 13, 2025 that will close this issue
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants