Skip to content

Commit 1206c20

Browse files
committed
Fix tests
1 parent 94da110 commit 1206c20

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

src/langchain_google_alloydb_pg/async_vectorstore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ async def aadd_images(
9494
ids = await self.aadd_embeddings(
9595
texts_for_content_column, embeddings, metadatas=metadatas, ids=ids, **kwargs
9696
)
97-
return ids
97+
if ids:
98+
return ids
99+
return []
98100

99101
def _images_embedding_helper(self, image_uris: list[str]) -> list[list[float]]:
100102
# check if either `embed_images()` or `embed_image()` API is supported by the embedding service used

src/langchain_google_alloydb_pg/vectorstore.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ async def aadd_images(
176176
) -> list[str]:
177177
"""Embed images and add to the table."""
178178
return await self._engine._run_as_async(
179-
self.__vs.aadd_images(
180-
uris, metadatas, ids, store_uri_only=store_uri_only, **kwargs
181-
)
179+
self._PGVectorStore__vs.aadd_images(uris, metadatas, ids, **kwargs) # type: ignore
182180
)
183181

184182
def add_images(
@@ -191,9 +189,7 @@ def add_images(
191189
) -> list[str]:
192190
"""Embed images and add to the table."""
193191
return self._engine._run_as_sync(
194-
self.__vs.aadd_images(
195-
uris, metadatas, ids, store_uri_only=store_uri_only, **kwargs
196-
)
192+
self._PGVectorStore__vs.aadd_images(uris, metadatas, ids, **kwargs) # type: ignore
197193
)
198194

199195
def similarity_search_image(
@@ -205,7 +201,7 @@ def similarity_search_image(
205201
) -> list[Document]:
206202
"""Return docs selected by similarity search on image."""
207203
return self._engine._run_as_sync(
208-
self.__vs.asimilarity_search_image(image_uri, k, filter, **kwargs)
204+
self._PGVectorStore__vs.asimilarity_search_image(image_uri, k, filter, **kwargs) # type: ignore
209205
)
210206

211207
async def asimilarity_search_image(
@@ -217,19 +213,19 @@ async def asimilarity_search_image(
217213
) -> list[Document]:
218214
"""Return docs selected by similarity search on image_uri."""
219215
return await self._engine._run_as_async(
220-
self.__vs.asimilarity_search_image(image_uri, k, filter, **kwargs)
216+
self._PGVectorStore__vs.asimilarity_search_image(image_uri, k, filter, **kwargs) # type: ignore
221217
)
222218

223219
async def aset_maintenance_work_mem(
224220
self, num_leaves: int, vector_size: int
225221
) -> None:
226222
"""Set database maintenance work memory (for ScaNN index creation)."""
227223
await self._engine._run_as_async(
228-
self.__vs.set_maintenance_work_mem(num_leaves, vector_size)
224+
self._PGVectorStore__vs.set_maintenance_work_mem(num_leaves, vector_size) # type: ignore
229225
)
230226

231227
def set_maintenance_work_mem(self, num_leaves: int, vector_size: int) -> None:
232228
"""Set database maintenance work memory (for ScaNN index creation)."""
233229
self._engine._run_as_sync(
234-
self.__vs.set_maintenance_work_mem(num_leaves, vector_size)
230+
self._PGVectorStore__vs.set_maintenance_work_mem(num_leaves, vector_size) # type: ignore
235231
)

tests/test_async_vectorstore_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def engine(self, db_project, db_region, db_cluster, db_instance, db_name):
116116
await engine.close()
117117

118118
@pytest_asyncio.fixture(scope="class")
119-
async def vs_custom_scann_query_option(self, engine, vs_custom):
119+
async def vs_custom_scann_query_option(self, engine):
120120
vs_custom_scann_query_option = await AsyncAlloyDBVectorStore.create(
121121
engine,
122122
embedding_service=embeddings_service,

tests/test_vectorstore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
from langchain_google_alloydb_pg import AlloyDBEngine, AlloyDBVectorStore
3434

35-
IMAGE_TABLE = "test_image_table" + str(uuid.uuid4())
36-
IMAGE_TABLE_SYNC = "test_image_table_sync" + str(uuid.uuid4())
35+
IMAGE_TABLE = "test_table" + str(uuid.uuid4())
36+
IMAGE_TABLE_SYNC = "test_table_sync" + str(uuid.uuid4())
3737
VECTOR_SIZE = 768
3838

3939
embeddings_service = DeterministicFakeEmbedding(size=VECTOR_SIZE)

tests/test_vectorstore_embeddings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async def test_asimilarity_search(self, vs):
183183
results = await vs.asimilarity_search("foo", k=1)
184184
assert len(results) == 1
185185
assert results == [Document(page_content="foo", id=ids[0])]
186-
results = await vs.asimilarity_search("foo", k=1, filter={"content": "bar"})
186+
results = await vs.asimilarity_search("foo", k=1, filter={"mycontent": "bar"})
187187
assert results == [Document(page_content="bar", id=ids[1])]
188188

189189
async def test_asimilarity_search_score(self, vs):
@@ -242,7 +242,7 @@ async def test_amax_marginal_relevance_search(self, vs):
242242
results = await vs.amax_marginal_relevance_search("bar")
243243
assert results[0] == Document(page_content="bar", id=ids[1])
244244
results = await vs.amax_marginal_relevance_search(
245-
"bar", filter={"content": "boo"}
245+
"bar", filter={"mycontent": "boo"}
246246
)
247247
assert results[0] == Document(page_content="boo", id=ids[3])
248248

@@ -342,7 +342,7 @@ def test_similarity_search(self, vs_custom):
342342
results = vs_custom.similarity_search("foo", k=1)
343343
assert len(results) == 1
344344
assert results == [Document(page_content="foo", id=ids[0])]
345-
results = vs_custom.similarity_search("foo", k=1, filter={"content": "boo"})
345+
results = vs_custom.similarity_search("foo", k=1, filter={"mycontent": "boo"})
346346
assert results == [Document(page_content="bar", id=ids[1])]
347347

348348
def test_similarity_search_score(self, vs_custom):
@@ -364,7 +364,7 @@ def test_max_marginal_relevance_search(self, vs_custom):
364364
results = vs_custom.max_marginal_relevance_search("bar")
365365
assert results[0] == Document(page_content="bar", id=ids[1])
366366
results = vs_custom.max_marginal_relevance_search(
367-
"bar", filter={"content": "boo"}
367+
"bar", filter={"mycontent": "boo"}
368368
)
369369
assert results[0] == Document(page_content="boo", id=ids[3])
370370

0 commit comments

Comments
 (0)