mirror of
https://github.com/langchain-ai/langchain-postgres.git
synced 2026-07-16 01:33:18 -04:00
[bug] IntegrityError When Adding Texts to Vector Store with Metadata #74
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ocyss on GitHub (May 29, 2025).
I have written the following code based on the example documentation. However, I encountered an error when attempting to add texts to the vector store with metadata.
Code
Here is the relevant code snippet:
Error Message
When executing the code, I received the following error:
Expected Behavior
The text and metadata should be successfully added to the vector store without violating the
not-nullconstraint on theentity_idcolumn.Actual Behavior
The operation fails with an
IntegrityErrordue to anullvalue in theentity_idcolumn, despite passing a value in the metadata.Environment
Additional Notes
entity_idis not being correctly mapped to the column in the database.Request for Help
Could you please help identify why the
entity_idvalue from the metadata is not being inserted into the database column? Any guidance or fixes would be greatly appreciated!Additional Question on SQL Construction
I also noticed that the
add_embeddingsmethod uses f-strings to manually concatenate SQL statements. Could this potentially lead to security issues, and is there a reason for not using SQLAlchemy's table objects or parameterized queries?@averikitsch commented on GitHub (Jul 2, 2025):
Hi @Ocyss ,
You'll need to tell the vector store about the use of the metadata column "entity_id" like
Let me know if this does not fix your issue.