Find answers from the community

Updated 3 months ago

Postgres as vector_store error: InvalidRequestError: Attribute name 'metadata' is reserved

Hi - I'm getting this error when using Postgres as the vector_store (it works as DatabaseReader):
"sqlalchemy.exc.InvalidRequestError: Attribute name 'metadata' is reserved when using the Declarative API."

Plain Text
vector_store = PGVectorStore.from_params(
            database="postgres",
            host="",
            password="",
            port=5432,
            user="",
            table_name="mytable"
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)

any ideas? thank you!
B
L
9 comments
What's the full traceback here?
Plain Text
Traceback (most recent call last):
  File "/Users/byronhsu/code/spcconnector/llamaindex/llama_index/byron/postgres_loadertest2.py", line 121, in <module>
    vector_store = PGVectorStore.from_params(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/vector_stores/postgres.py", line 80, in from_params
    return cls(connection_string=conn_str, table_name=table_name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/vector_stores/postgres.py", line 60, in __init__
    self.table_class = get_data_model(self._base, self.table_name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/llama_index/vector_stores/postgres.py", line 31, in get_data_model
    model = type(class_name, (AbstractData,), {"__tablename__": tablename})
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py", line 194, in __init__
    _as_declarative(reg, cls, dict_)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 247, in _as_declarative
    return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 328, in setup_mapping
    return _ClassScanMapperConfig(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 574, in __init__
    self._extract_mappable_attributes()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py", line 1507, in _extract_mappable_attributes
    raise exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Attribute name 'metadata' is reserved when using the Declarative API.

thank you!
Ah, I definitely caused this error, my bad!
Will patch this asap πŸ™‚
Not allowed to have a column named metadata I guess lol
Attachment
image.png
Will merge in a sec πŸ™‚
amazing, thank you!! you rock :cooldoge:
Add a reply
Sign up and join the conversation on Discord