Replies: 4 comments 2 replies
-
To successfully add a schema name to PGVector in LangChain without encountering the In the provided context, there is no direct mention of setting or using a specific schema name in the PGVector class or its methods. However, you can specify the schema name in the PostgreSQL connection string or explicitly set it in your SQLAlchemy models or during the table creation process in SQLAlchemy. Here's a general approach to specify the schema in SQLAlchemy, which you can adapt to the PGVector setup:
Given the context does not show how PGVector handles schemas directly, you would likely need to modify the PGVector class or the way you use SQLAlchemy within the LangChain framework to support specifying a schema. This could involve adjusting the table creation logic to include the schema name or extending PGVector to accept a schema parameter and use it in all database operations. If PGVector and LangChain have specific mechanisms or configurations for handling schemas that are not shown in the provided context, you would need to refer to their documentation or source code to make the necessary adjustments. For more information, you can refer to the LangChain PGVector test file which might provide some insights on how the PGVector class is implemented and used. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi @OmiWakode , The table name is hard coded in langchain_community/vectorstores/pgvector.py (all examples below refer to this file) : def _get_embedding_collection_store(vector_dimension: Optional[int] = None) -> Any:
global _classes
if _classes is not None:
return _classes
from pgvector.sqlalchemy import Vector
class CollectionStore(BaseModel):
"""Collection store."""
__tablename__ = "langchain_pg_collection"
name = sqlalchemy.Column(sqlalchemy.String)
cmetadata = sqlalchemy.Column(JSON)
embeddings = relationship(
"EmbeddingStore",
back_populates="collection",
passive_deletes=True,
) And here : class EmbeddingStore(BaseModel):
"""Embedding store."""
__tablename__ = "langchain_pg_embedding"
collection_id = sqlalchemy.Column(
UUID(as_uuid=True),
sqlalchemy.ForeignKey(
f"{CollectionStore.__tablename__}.uuid",
ondelete="CASCADE",
),
) I'm not sure if it's recommended to change this variable but just in case, you could try to add parameters or hard code your updated schema |
Beta Was this translation helpful? Give feedback.
-
Looking to implement this into a feature as well. Please feel free to upvote the idea here if you find it helpful: #20878 |
Beta Was this translation helpful? Give feedback.
-
Proposed this PR - langchain-ai/langchain-postgres#138 |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
How to override the PGVector class so that I can specify the schema name? I tries adding table_args: {"schema": 'text"}
to the collectionstore and the embedding store but nothing seems to work.
Error:
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'langchain_pg_embedding.collection_id' could not find table 'langchain_pg_collection' with which to generate a foreign key to target column 'uuid'
When I remove the table_args it works perfectly fine with in my custom PGVector
IDK can anyone please help? Stuck on this since days , new to this:(
System Info
System Information
The following packages were not found:
Beta Was this translation helpful? Give feedback.
All reactions