diff --git a/src/langchain_google_cloud_sql_pg/async_vectorstore.py b/src/langchain_google_cloud_sql_pg/async_vectorstore.py index 9d08ae86..b8884438 100644 --- a/src/langchain_google_cloud_sql_pg/async_vectorstore.py +++ b/src/langchain_google_cloud_sql_pg/async_vectorstore.py @@ -246,7 +246,11 @@ async def __aadd_embeddings( else "" ) insert_stmt = f'INSERT INTO "{self.schema_name}"."{self.table_name}"("{self.id_column}", "{self.content_column}", "{self.embedding_column}"{metadata_col_names}' - values = {"id": id, "content": content, "embedding": str(embedding)} + values = { + "id": id, + "content": content, + "embedding": str([float(dimension) for dimension in embedding]), + } values_stmt = "VALUES (:id, :content, :embedding" # Add metadata @@ -496,9 +500,9 @@ async def __query_collection( columns.append(self.metadata_json_column) column_names = ", ".join(f'"{col}"' for col in columns) - filter = f"WHERE {filter}" if filter else "" - stmt = f"SELECT {column_names}, {search_function}({self.embedding_column}, '{embedding}') as distance FROM \"{self.schema_name}\".\"{self.table_name}\" {filter} ORDER BY {self.embedding_column} {operator} '{embedding}' LIMIT {k};" + embedding_string = f"'{[float(dimension) for dimension in embedding]}'" + stmt = f'SELECT {column_names}, {search_function}({self.embedding_column}, {embedding_string}) as distance FROM "{self.schema_name}"."{self.table_name}" {filter} ORDER BY {self.embedding_column} {operator} {embedding_string} LIMIT {k};' if self.index_query_options: async with self.pool.connect() as conn: await conn.execute( diff --git a/tests/test_engine.py b/tests/test_engine.py index 1c2653bf..eeff53e1 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -130,7 +130,9 @@ async def test_init_table(self, engine): id = str(uuid.uuid4()) content = "coffee" embedding = await embeddings_service.aembed_query(content) - stmt = f"INSERT INTO {DEFAULT_TABLE} (langchain_id, content, embedding) VALUES ('{id}', '{content}','{embedding}');" + # Note: DeterministicFakeEmbedding generates a numpy array, converting to list a list of float values + embedding_string = [float(dimension) for dimension in embedding] + stmt = f"INSERT INTO {DEFAULT_TABLE} (langchain_id, content, embedding) VALUES ('{id}', '{content}','{embedding_string}');" await aexecute(engine, stmt) async def test_init_table_custom(self, engine): @@ -350,7 +352,9 @@ async def test_init_table(self, engine): id = str(uuid.uuid4()) content = "coffee" embedding = await embeddings_service.aembed_query(content) - stmt = f"INSERT INTO {DEFAULT_TABLE_SYNC} (langchain_id, content, embedding) VALUES ('{id}', '{content}','{embedding}');" + # Note: DeterministicFakeEmbedding generates a numpy array, converting to list a list of float values + embedding_string = [float(dimension) for dimension in embedding] + stmt = f"INSERT INTO {DEFAULT_TABLE_SYNC} (langchain_id, content, embedding) VALUES ('{id}', '{content}','{embedding_string}');" await aexecute(engine, stmt) async def test_init_table_custom(self, engine):