Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/langchain_google_cloud_sql_pg/async_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down