Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge committed Mar 21, 2024
1 parent 95257dc commit 752f957
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions libs/vertexai/tests/integration_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def datastore_document_storage(

@pytest.fixture
def vector_store() -> VectorSearchVectorStore:

embeddings = VertexAIEmbeddings(model_name="textembedding-gecko-default")

vector_store = VectorSearchVectorStore.from_components(
Expand All @@ -82,15 +83,16 @@ def vector_store() -> VectorSearchVectorStore:

@pytest.fixture
def datastore_vector_store() -> VectorSearchVectorStoreDatastore:

embeddings = VertexAIEmbeddings(model_name="textembedding-gecko-default")

vector_store = VectorSearchVectorStoreDatastore.from_components(
project_id=os.environ["PROJECT_ID"],
region=os.environ["REGION"],
index_staging_bucket_name=os.environ["GCS_BUCKET_NAME"],
index_id=os.environ["INDEX_ID"],
endpoint_id=os.environ["ENDPOINT_ID"],
index_id=os.environ["STREAM_INDEX_ID_DATASTORE"],
endpoint_id=os.environ["STREAM_ENDPOINT_ID_DATASTORE"],
embedding=embeddings,
stream_update=True
)

return vector_store
Expand Down Expand Up @@ -164,8 +166,12 @@ def test_public_endpoint_vector_searcher(sdk_manager: VectorSearchSDKManager):


@pytest.mark.extended
def test_vector_store(vector_store: VectorSearchVectorStore):
assert isinstance(vector_store, VectorSearchVectorStore)
@pytest.mark.parametrize(
"vector_store_class", ["vector_store", "datastore_vector_store"]
)
def test_vector_store(vector_store_class: str, request: pytest.FixtureRequest):

vector_store: VectorSearchVectorStore = request.getfixturevalue(vector_store_class)

query = "What are your favourite animals?"
docs_with_scores = vector_store.similarity_search_with_score(query, k=1)
Expand All @@ -181,7 +187,16 @@ def test_vector_store(vector_store: VectorSearchVectorStore):


@pytest.mark.extended
def test_vector_store_filtering(vector_store: VectorSearchVectorStore):
@pytest.mark.parametrize(
"vector_store_class", [
"vector_store",
#"datastore_vector_store" Waiting for the bug to be fixed as its stream
]
)
def test_vector_store_filtering(
vector_store_class: str, request: pytest.FixtureRequest):

vector_store: VectorSearchVectorStore = request.getfixturevalue(vector_store_class)
documents = vector_store.similarity_search(
"I want some pants",
filter=[Namespace(name="color", allow_tokens=["blue"])],
Expand All @@ -194,19 +209,17 @@ def test_vector_store_filtering(vector_store: VectorSearchVectorStore):


@pytest.mark.extended
def test_vector_store_update_index(sample_documents: List[Document]):
embeddings = VertexAIEmbeddings(model_name="textembedding-gecko-default")
def test_vector_store_update_index(
vector_store: VectorSearchVectorStore, sample_documents: List[Document]):
vector_store.add_documents(documents=sample_documents, is_complete_overwrite=True)

vector_store = VectorSearchVectorStore.from_components(
project_id=os.environ["PROJECT_ID"],
region=os.environ["REGION"],
gcs_bucket_name=os.environ["GCS_BUCKET_NAME"],
index_id=os.environ["INDEX_ID"],
endpoint_id=os.environ["ENDPOINT_ID"],
embedding=embeddings,
)
@pytest.mark.extended
def test_vector_store_stream_update_index(
datastore_vector_store: VectorSearchVectorStoreDatastore,
sample_documents: List[Document]):

vector_store.add_documents(documents=sample_documents, is_complete_overwrite=True)
datastore_vector_store.add_documents(
documents=sample_documents, is_complete_overwrite=True)


@pytest.fixture
Expand Down

0 comments on commit 752f957

Please sign in to comment.