Skip to content

Commit

Permalink
Improve the logic to generate vectors.
Browse files Browse the repository at this point in the history
Also adds some warning messages for easy of use.
  • Loading branch information
jfrancoa committed Nov 7, 2024
1 parent a9f7c4a commit f11fcca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/unittests/test_managers/test_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_ingest_data(mock_client):
consistency_level="quorum",
randomize=True,
auto_tenants=0,
vector_dimensions=None,
vector_dimensions=1536,
)

mock_client.collections.get.assert_called_once_with("TestCollection")
Expand Down
6 changes: 6 additions & 0 deletions weaviate_cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ def create_data_cli(
):
"""Ingest data into a collection in Weaviate."""

if vector_dimensions != 1536 and not randomize:
click.echo(
"Error: --vector_dimensions has no effect unless --randomize is enabled."
)
sys.exit(1)

client = None
try:
client = get_client_from_context(ctx)
Expand Down
14 changes: 13 additions & 1 deletion weaviate_cli/managers/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,26 @@ def __ingest_data(
cl_collection = collection.with_consistency_level(cl)
vectorizer = cl_collection.config.get().vectorizer
if vectorizer == "text2vec-contextionary":
(
print("Warning: Using vector dimensions: 300")
if vector_dimensions != 1536
else None
)
vector_dimensions = 300
elif vectorizer == "text2vec-transformers":
(
print("Warning: Using vector dimensions: 768")
if vector_dimensions != 1536
else None
)
vector_dimensions = 768
with cl_collection.batch.dynamic() as batch:
for obj in data_objects:
batch.add_object(
properties=obj,
vector=np.random.rand(1, vector_dimensions)[0].tolist(),
vector=(
2 * np.random.rand(1, vector_dimensions)[0] - 1
).tolist(),
)
counter += 1

Expand Down

0 comments on commit f11fcca

Please sign in to comment.