Skip to content

Commit

Permalink
fix: allow special characters in table name for vector store delete (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon committed Mar 27, 2024
1 parent b8a9a05 commit 7fc1c63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/langchain_google_cloud_sql_pg/vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ async def adelete(
return False

id_list = ", ".join([f"'{id}'" for id in ids])
query = f"DELETE FROM {self.table_name} WHERE {self.id_column} in ({id_list})"
query = f'DELETE FROM "{self.table_name}" WHERE {self.id_column} in ({id_list})'
await self.engine._aexecute(query)
return True

Expand Down
24 changes: 24 additions & 0 deletions tests/test_cloudsql_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ async def test_aadd_embedding(self, engine, vs):
assert len(results) == 3
await engine._aexecute(f"TRUNCATE TABLE {DEFAULT_TABLE}")

async def test_adelete(self, engine, vs):
ids = [str(uuid.uuid4()) for i in range(len(texts))]
await vs.aadd_texts(texts, ids=ids)
results = await engine._afetch(f"SELECT * FROM {DEFAULT_TABLE}")
assert len(results) == 3
# delete an ID
await vs.adelete([ids[0]])
results = await engine._afetch(f"SELECT * FROM {DEFAULT_TABLE}")
assert len(results) == 2

async def test_aadd_texts_custom(self, engine, vs_custom):
ids = [str(uuid.uuid4()) for i in range(len(texts))]
await vs_custom.aadd_texts(texts, ids=ids)
Expand Down Expand Up @@ -222,6 +232,20 @@ async def test_aadd_embedding_custom(self, engine, vs_custom):
assert len(results) == 3
await engine._aexecute(f'TRUNCATE TABLE "{CUSTOM_TABLE}"')

async def test_adelete_custom(self, engine, vs_custom):
ids = [str(uuid.uuid4()) for i in range(len(texts))]
await vs_custom.aadd_texts(texts, ids=ids)
results = await engine._afetch(f'SELECT * FROM "{CUSTOM_TABLE}"')
content = [result["mycontent"] for result in results]
assert len(results) == 3
assert "foo" in content
# delete an ID
await vs_custom.adelete([ids[0]])
results = await engine._afetch(f'SELECT * FROM "{CUSTOM_TABLE}"')
content = [result["mycontent"] for result in results]
assert len(results) == 2
assert "foo" not in content

async def test_add_docs(self, engine_sync, vs_sync):
ids = [str(uuid.uuid4()) for i in range(len(texts))]
vs_sync.add_documents(docs, ids=ids)
Expand Down

0 comments on commit 7fc1c63

Please sign in to comment.