-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable testing index Weaviate (#790)
PR that enables testing the weaviate indexing component Leverage the embedded weaviate component to setup the client and bypass the docker-compose setup https://weaviate.io/developers/weaviate/installation/embedded
- Loading branch information
1 parent
d1c4313
commit 48fbbd4
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
pythonpath = ../src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
numpy==1.24.4 | ||
pytest==7.4.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import typing as t | ||
|
||
import dask.dataframe as dd | ||
import numpy as np | ||
import pandas as pd | ||
import weaviate | ||
from weaviate.embedded import EmbeddedOptions | ||
|
||
from src.main import IndexWeaviateComponent | ||
|
||
|
||
def get_written_objects( | ||
client: weaviate.Client, | ||
class_name: str, | ||
) -> t.List[t.Dict[str, t.Any]]: | ||
"""Taken from https://weaviate.io/developers/weaviate/manage-data/read-all-objects.""" | ||
query = ( | ||
client.query.get( | ||
class_name, | ||
["id_", "passage"], | ||
) | ||
.with_additional(["id vector"]) | ||
.with_limit(8) | ||
) | ||
|
||
result = query.do() | ||
|
||
return result["data"]["Get"][class_name] | ||
|
||
|
||
def test_index_weaviate_component(monkeypatch): | ||
client = weaviate.Client(embedded_options=EmbeddedOptions()) | ||
|
||
pandas_df = pd.DataFrame( | ||
[ | ||
("Lorem ipsum dolor", np.array([1.0, 2.0])), | ||
("ligula eget dolor", np.array([2.0, 3.0])), | ||
], | ||
columns=["text", "embedding"], | ||
) | ||
dask_df = dd.from_pandas(pandas_df, npartitions=2) | ||
|
||
index_component = IndexWeaviateComponent( | ||
weaviate_url="http://localhost:6666", # local weaviate instance running on port 6666 | ||
batch_size=10, | ||
dynamic=True, | ||
num_workers=2, | ||
overwrite=True, | ||
class_name="TestClass", | ||
vectorizer=None, | ||
) | ||
|
||
index_component.write(dask_df) | ||
written_objects = get_written_objects(client, "TestClass") | ||
|
||
for _object in written_objects: | ||
matching_row = pandas_df.loc[int(_object["id_"])] | ||
assert matching_row.text == _object["passage"] | ||
assert matching_row.embedding.tolist() == _object["_additional"]["vector"] |