Skip to content

Commit 8cb35ca

Browse files
tests: upgrade embedding model in tests (#419)
1 parent 9733c43 commit 8cb35ca

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

tests/test_embeddings.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
import pytest_asyncio
2020
from langchain_core.documents import Document
2121

22-
from langchain_google_alloydb_pg import AlloyDBEmbeddings, AlloyDBEngine
22+
from langchain_google_alloydb_pg import (
23+
AlloyDBEmbeddings,
24+
AlloyDBEngine,
25+
AlloyDBModelManager,
26+
)
2327

2428
project_id = os.environ["PROJECT_ID"]
2529
region = os.environ["REGION"]
@@ -62,10 +66,20 @@ async def sync_engine(self):
6266

6367
@pytest.fixture(scope="module")
6468
def model_id(self) -> str:
65-
return "textembedding-gecko@001"
69+
return "text-embedding-005"
6670

6771
@pytest_asyncio.fixture
68-
def embeddings(self, engine, model_id):
72+
async def embeddings(self, engine, model_id):
73+
model_manager = await AlloyDBModelManager.create(engine=engine)
74+
model = await model_manager.aget_model(model_id=model_id)
75+
if not model:
76+
# create model if not exists
77+
await model_manager.acreate_model(
78+
model_id=model_id,
79+
model_provider="google",
80+
model_qualified_name=model_id, # assuming model is built-in
81+
model_type="text_embedding",
82+
)
6983
return AlloyDBEmbeddings.create_sync(engine=engine, model_id=model_id)
7084

7185
async def test_model_exists(self, sync_engine):

tests/test_model_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_env_var(key: str, desc: str) -> str:
2828
return v
2929

3030

31-
EMBEDDING_MODEL_NAME = "textembedding-gecko@003" + str(uuid.uuid4()).replace("-", "_")
31+
EMBEDDING_MODEL_NAME = "text-embedding-005" + str(uuid.uuid4()).replace("-", "_")
3232

3333

3434
@pytest.mark.asyncio
@@ -79,7 +79,7 @@ async def test_acreate_model(self, model_manager):
7979
await model_manager.acreate_model(
8080
model_id=EMBEDDING_MODEL_NAME,
8181
model_provider="google",
82-
model_qualified_name="textembedding-gecko@003",
82+
model_qualified_name="text-embedding-005",
8383
model_type="text_embedding",
8484
)
8585

tests/test_vectorstore_embeddings.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from langchain_google_alloydb_pg import (
2424
AlloyDBEmbeddings,
2525
AlloyDBEngine,
26+
AlloyDBModelManager,
2627
AlloyDBVectorStore,
2728
Column,
2829
)
@@ -31,7 +32,7 @@
3132
DEFAULT_TABLE = "test_table" + str(uuid.uuid4()).replace("-", "_")
3233
DEFAULT_TABLE_SYNC = "test_table" + str(uuid.uuid4()).replace("-", "_")
3334
CUSTOM_TABLE = "test_table_custom" + str(uuid.uuid4()).replace("-", "_")
34-
DEFAULT_EMBEDDING_MODEL = "textembedding-gecko@001"
35+
DEFAULT_EMBEDDING_MODEL = "text-embedding-005"
3536
VECTOR_SIZE = 768
3637

3738

@@ -106,6 +107,16 @@ async def engine(
106107

107108
@pytest_asyncio.fixture(scope="class")
108109
async def embeddings_service(self, engine):
110+
model_manager = await AlloyDBModelManager.create(engine=engine)
111+
model = await model_manager.aget_model(model_id=DEFAULT_EMBEDDING_MODEL)
112+
if not model:
113+
# create model if not exists
114+
await model_manager.acreate_model(
115+
model_id=DEFAULT_EMBEDDING_MODEL,
116+
model_provider="google",
117+
model_qualified_name=DEFAULT_EMBEDDING_MODEL, # assuming model is built-in
118+
model_type="text_embedding",
119+
)
109120
return await AlloyDBEmbeddings.create(engine, DEFAULT_EMBEDDING_MODEL)
110121

111122
@pytest_asyncio.fixture(scope="class")
@@ -197,7 +208,7 @@ async def test_similarity_search_with_relevance_scores_threshold_cosine(self, vs
197208
)
198209
assert len(results) == 4
199210

200-
score_threshold = {"score_threshold": 0.73}
211+
score_threshold = {"score_threshold": 0.65}
201212
results = await vs.asimilarity_search_with_relevance_scores(
202213
"foo", **score_threshold
203214
)

0 commit comments

Comments
 (0)