From c50b8a8f84fb1c7a3dfb23f28068080e1baeeb3f Mon Sep 17 00:00:00 2001 From: bash000000 Date: Wed, 18 Jun 2025 16:48:03 +0800 Subject: [PATCH 1/3] Remove wrong async --- langchain_postgres/v2/engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain_postgres/v2/engine.py b/langchain_postgres/v2/engine.py index 6067ba23..219717ec 100644 --- a/langchain_postgres/v2/engine.py +++ b/langchain_postgres/v2/engine.py @@ -399,7 +399,7 @@ async def adrop_table( self._adrop_table(table_name=table_name, schema_name=schema_name) ) - async def drop_table( + def drop_table( self, table_name: str, *, From 2841f25e285b850af4e50e864813a9653fbd079b Mon Sep 17 00:00:00 2001 From: bash000000 Date: Thu, 26 Jun 2025 15:11:43 +0800 Subject: [PATCH 2/3] Add feature use_jsonb --- langchain_postgres/v2/engine.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/langchain_postgres/v2/engine.py b/langchain_postgres/v2/engine.py index 219717ec..965c9926 100644 --- a/langchain_postgres/v2/engine.py +++ b/langchain_postgres/v2/engine.py @@ -158,6 +158,7 @@ async def _ainit_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, + use_jsonb: bool = True, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -181,6 +182,8 @@ async def _ainit_vectorstore_table( overwrite_existing (bool): Whether to drop existing table. Default: False. store_metadata (bool): Whether to store metadata in the table. Default: True. + use_jsonb (bool): Whether to use JSONB for metadata storage. + Default: True. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Default: None. @@ -256,7 +259,10 @@ async def _ainit_vectorstore_table( nullable = "NOT NULL" if not column["nullable"] else "" query += f',\n"{column["name"]}" {column["data_type"]} {nullable}' if store_metadata: - query += f""",\n"{metadata_json_column}" JSON""" + if use_jsonb: + query += f""",\n"{metadata_json_column}" JSONB""" + else: + query += f""",\n"{metadata_json_column}" JSON""" query += "\n);" async with self._pool.connect() as conn: @@ -276,6 +282,7 @@ async def ainit_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, + use_jsonb: bool = True, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -299,6 +306,8 @@ async def ainit_vectorstore_table( overwrite_existing (bool): Whether to drop existing table. Default: False. store_metadata (bool): Whether to store metadata in the table. Default: True. + use_jsonb (bool): Whether to use JSONB for metadata storage. + Default: True. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Note that queries might be slow if the hybrid search column does not exist. For best hybrid search performance, consider creating a TSV column and adding GIN index. @@ -316,6 +325,7 @@ async def ainit_vectorstore_table( id_column=id_column, overwrite_existing=overwrite_existing, store_metadata=store_metadata, + use_jsonb=use_jsonb, hybrid_search_config=hybrid_search_config, ) ) @@ -333,6 +343,7 @@ def init_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, + use_jsonb: bool = True, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -356,6 +367,8 @@ def init_vectorstore_table( overwrite_existing (bool): Whether to drop existing table. Default: False. store_metadata (bool): Whether to store metadata in the table. Default: True. + use_jsonb (bool): Whether to use JSONB for metadata storage. + Default: True. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Note that queries might be slow if the hybrid search column does not exist. For best hybrid search performance, consider creating a TSV column and adding GIN index. @@ -373,6 +386,7 @@ def init_vectorstore_table( id_column=id_column, overwrite_existing=overwrite_existing, store_metadata=store_metadata, + use_jsonb=use_jsonb, hybrid_search_config=hybrid_search_config, ) ) From 25c8cc2858e1ceb1d5e5a8ed5b9c93e864573f5e Mon Sep 17 00:00:00 2001 From: bash000000 Date: Thu, 26 Jun 2025 15:16:14 +0800 Subject: [PATCH 3/3] Add feature use_jsonb --- langchain_postgres/v2/engine.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/langchain_postgres/v2/engine.py b/langchain_postgres/v2/engine.py index 965c9926..5ed9625d 100644 --- a/langchain_postgres/v2/engine.py +++ b/langchain_postgres/v2/engine.py @@ -158,7 +158,7 @@ async def _ainit_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, - use_jsonb: bool = True, + use_jsonb: bool = False, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -183,7 +183,7 @@ async def _ainit_vectorstore_table( store_metadata (bool): Whether to store metadata in the table. Default: True. use_jsonb (bool): Whether to use JSONB for metadata storage. - Default: True. + Default: False. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Default: None. @@ -282,7 +282,7 @@ async def ainit_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, - use_jsonb: bool = True, + use_jsonb: bool = False, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -307,7 +307,7 @@ async def ainit_vectorstore_table( store_metadata (bool): Whether to store metadata in the table. Default: True. use_jsonb (bool): Whether to use JSONB for metadata storage. - Default: True. + Default: False. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Note that queries might be slow if the hybrid search column does not exist. For best hybrid search performance, consider creating a TSV column and adding GIN index. @@ -343,7 +343,7 @@ def init_vectorstore_table( id_column: Union[str, Column, ColumnDict] = "langchain_id", overwrite_existing: bool = False, store_metadata: bool = True, - use_jsonb: bool = True, + use_jsonb: bool = False, hybrid_search_config: Optional[HybridSearchConfig] = None, ) -> None: """ @@ -368,7 +368,7 @@ def init_vectorstore_table( store_metadata (bool): Whether to store metadata in the table. Default: True. use_jsonb (bool): Whether to use JSONB for metadata storage. - Default: True. + Default: False. hybrid_search_config (HybridSearchConfig): Hybrid search configuration. Note that queries might be slow if the hybrid search column does not exist. For best hybrid search performance, consider creating a TSV column and adding GIN index.