-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
56 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
developers/academy/starter_text_data/101_start_wcs/_snippets/30_connect.py
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
48 changes: 48 additions & 0 deletions
48
developers/academy/starter_text_data/102_text_collections/_snippets/20_create_collection.py
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,48 @@ | ||
import os | ||
|
||
your_wcs_url = os.getenv("WCS_DEMO_URL") | ||
your_wcs_key = os.getenv("WCS_DEMO_ADMIN_KEY") | ||
|
||
# CreateMovieCollection | ||
import weaviate | ||
# CreateMovieCollection # SubmoduleImport | ||
import weaviate.classes.config as wc | ||
# CreateMovieCollection # END SubmoduleImport | ||
|
||
client = weaviate.connect_to_wcs( | ||
cluster_url=your_wcs_url, # Replace with your WCS URL | ||
auth_credentials=weaviate.auth.AuthApiKey(your_wcs_key) # Replace with your WCS key | ||
) | ||
|
||
# END CreateMovieCollection | ||
|
||
client.close() | ||
|
||
# Actual instantiation | ||
client = weaviate.connect_to_local() | ||
|
||
client.collections.delete("Movie") | ||
|
||
# CreateMovieCollection | ||
try: | ||
client.collections.create( | ||
name="Movie", | ||
properties=[ | ||
wc.Property(name="title", data_type=wc.DataType.TEXT), | ||
wc.Property(name="overview", data_type=wc.DataType.TEXT), | ||
wc.Property(name="vote_average", data_type=wc.DataType.NUMBER), | ||
wc.Property(name="genre_ids", data_type=wc.DataType.INT_ARRAY), | ||
wc.Property(name="release_date", data_type=wc.DataType.DATE), | ||
wc.Property(name="tmdb_id", data_type=wc.DataType.INT), | ||
], | ||
# Define the vectorizer module | ||
vectorizer_config=wc.Configure.Vectorizer.text2vec_openai(), | ||
# Define the generative module | ||
generative_config=wc.Configure.Generative.openai() | ||
# END generativeDefinition # CreateMovieCollection | ||
) | ||
|
||
finally: | ||
client.close() # Release resources | ||
# END CreateMovieCollection | ||
|
51 changes: 51 additions & 0 deletions
51
developers/academy/starter_text_data/102_text_collections/_snippets/30_import_data.py
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,51 @@ | ||
import os | ||
|
||
your_wcs_url = os.getenv("WCS_DEMO_URL") | ||
your_wcs_key = os.getenv("WCS_DEMO_ADMIN_KEY") | ||
|
||
# BatchImportData | ||
import weaviate | ||
import pandas as pd | ||
import requests | ||
import datetime | ||
from weaviate.util import generate_uuid5 | ||
|
||
client = weaviate.connect_to_wcs( | ||
cluster_url=your_wcs_url, # Replace with your WCS URL | ||
auth_credentials=weaviate.auth.AuthApiKey(your_wcs_key) # Replace with your WCS key | ||
) | ||
|
||
# END BatchImportData | ||
|
||
client.close() | ||
|
||
# Actual instantiation | ||
client = weaviate.connect_to_local() | ||
client.connect() | ||
|
||
# BatchImportData | ||
data_url = "https://raw.githubusercontent.com/weaviate-tutorials/edu-datasets/main/movies_data_1990_2024.json" | ||
resp = requests.get(data_url) | ||
df = pd.DataFrame(resp.json()) | ||
|
||
try: | ||
movies = client.collections.get("Movie") | ||
with movies.batch.dynamic() as batch: | ||
for i, movie in df[:10].iterrows(): | ||
release_date = datetime.datetime.strptime(movie["release_date"], "%Y-%m-%d") | ||
movie_obj = { | ||
"title": movie["title"], | ||
"overview": movie["overview"], | ||
"vote_average": movie["vote_average"], | ||
"genre_ids": movie["genre_ids"], | ||
"release_date": release_date, | ||
"tmdb_id": movie["id"] | ||
} | ||
batch.add_object( | ||
properties=movie_obj, | ||
uuid=generate_uuid5(movie["id"]) | ||
) | ||
|
||
finally: | ||
client.close() | ||
|