googleapis / langchain-google-alloydb-pg-python

Apache License 2.0
9 stars 9 forks source link

Can't create tables in own schema using engine.init_vectorstore_table #95

Open MarkEdmondson1234 opened 2 months ago

MarkEdmondson1234 commented 2 months ago

I attempted to create a vector store like this:

...
          table_name = f"schema.table_name"
          engine.init_vectorstore_table(
              table_name,
              vector_size=vector_size,
              metadata_columns=[Column("source", "TEXT", nullable=True)],
              overwrite_existing=False
          )

Logs:

STATEMENT:  CREATE TABLE "myschema.my_table"(
            "langchain_id" UUID PRIMARY KEY,
            "content" TEXT NOT NULL,
            "embedding" vector(1536) NOT NULL,
"source" TEXT ,
"langchain_metadata" JSON
);
...
2024-04-03 10:58:08.074 UTC [1088933]: [2-1] db=db_multivac-internal-dev,user=sa-llmops@my-project.iam ERROR:  [aclchk.c:3655]  permission denied for schema public at character 14

It thinks its creating a table with a . in it within public schema.

I worked around by creating the table myself like this: in the alloydb studio client:

CREATE TABLE myschema.my_table (
            "langchain_id" UUID PRIMARY KEY,
            "content" TEXT NOT NULL,
            "embedding" vector(1536) NOT NULL,
"source" TEXT ,
"langchain_metadata" JSON
);

but it would be cool to be able to pass in the schema or something.

jackwotherspoon commented 2 months ago

@MarkEdmondson1234 This is a good feature request, currently the package tries to use the public schema when creating tables. We should allow users to specify schema directly, or like in your example if the table name includes a . in it to detect this as a table with schema specified (i.e. "my-schema.my-table" should assume schema="my-schema" and table= "my-table")