-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
fix: use jsonb instead of json for pgvector #11897
fix: use jsonb instead of json for pgvector #11897
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -132,7 +132,7 @@ def __post_init__( | |||
Initialize the store. | |||
""" | |||
self._conn = self.connect() | |||
# self.create_vector_extension() | |||
self.create_vector_extension() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also not sure why this was commented out, but seems like it should be part of the setup as well /cc @hwchase17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this, i get the following error:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedObject) type "vector" does not exist
LINE 4: embedding VECTOR,
^
[SQL:
CREATE TABLE langchain_pg_embedding (
collection_id UUID,
embedding VECTOR,
document VARCHAR,
cmetadata JSON,
custom_id VARCHAR,
uuid UUID NOT NULL,
PRIMARY KEY (uuid),
FOREIGN KEY(collection_id) REFERENCES langchain_pg_collection (uuid) ON DELETE CASCADE
)
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The creation query doesn't raise an exception if it fails but rather a warning, proposed fix in #11930
Closing in favor of: #18992 |
Description
When trying to integrate pgvector as a vector store with langchain, I got the following error:
The problem
From my brief research, it appears that the
@>
operator only works with jsonb. So I'm trying to figure out how this ever worked in the first place, but I'm not a postgres expert.Testing / Reproduced
To test this, I ran the following against my database after langchain created it and this seemed to fix my issue:
I'm using this python version of langchain for running my document loaders and storing my embeddings in PG, but then I have a chat client that's using the langchain-js lib to query it, so I happened to then go see if pgvector had the same problem over there, and it doesn't.
https://github.com/langchain-ai/langchainjs/blob/aa9b618786757c301e93caeb3253c56b56d05602/langchain/src/vectorstores/pgvector.ts#L244C38-L244C43
Let me know if the fix isn't as simple as this or if there's a better solution that should be considered like type casting or something else?
cc:
@baskaryan, @eyurtsev, @hwchase17