mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
21.6k stars 1.97k forks source link

Unable to setup PGVector vector store as per documentation #1740

Closed ggozad closed 2 weeks ago

ggozad commented 2 weeks ago

🐛 Describe the bug

Pedantic validation fails when trying to instantiate a memory using PGVector. The following is probably the easiest way to reproduce cleanly:

from mem0.vector_stores.configs import VectorStoreConfig

vector_store_config = VectorStoreConfig(
    provider="pgvector",
    config={
        "dbname": "test",
        "user": "test",
        "password": "test",
        "host": "test",
        "port": 1234,
    },
)

which leads to:


Traceback (most recent call last):
  File "/Users/ggozad/dev/open-source/mem0/test.py", line 3, in <module>
    vector_store_config = VectorStoreConfig(
                          ^^^^^^^^^^^^^^^^^^
  File "/Users/ggozad/dev/open-source/mem0/.venv/lib/python3.12/site-packages/pydantic/main.py", line 193, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for VectorStoreConfig
  Value error, Extra fields not allowed: path. Please input only the following fields: dbname, host, collection_name, user, password, embedding_model_dims, port [type=value_error, input_value={'dbname': 'test', 'user'...'path': '/tmp/pgvector'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error```

It seems that instead of a `PGVectorConfig` a `QdrantConfig` is instantiated being the default provider.
zacrafidi commented 2 weeks ago

Similar error on my end when trying to connect to my pgvector store (via supabase), the error I get is:

ValidationError: 1 validation error for MemoryConfig vector_store Value error, Extra fields not allowed: path. Please input only the following fields: embedding_model_dims, host, dbname, port, user, collection_name, password [type=value_error, input_value={'user': '...'path': '/tmp/pgvector'}, input_type=dict]

is it something to do with this file? https://github.com/mem0ai/mem0/blob/4f5a40a84f0f43e78740710ab0e858e20edd6925/mem0/vector_stores/configs.py#L5

zacrafidi commented 2 weeks ago

i made these changes locally and it started working. Changed:

if "path" not in config: config["path"] = f"/tmp/{provider}"

with:

Only add 'path' for providers that are not 'pgvector'

    if provider != 'pgvector' and "path" not in config:
        config["path"] = f"/tmp/{provider}"

then installing psycopg2-binary and full restarting everything and passing below to the config:

"vector_store": { "provider": "pgvector", "config": { "user": SUPABASE_DB_USER, "password": SUPABASE_DB_PASSWORD, "host": SUPABASE_DB_HOST, "port": SUPABASE_DB_PORT, } },

Dev-Khant commented 2 weeks ago

Closing this as #1703 fixes the issue. Feel free to open it if there's still problem with it.