Spaces:
Build error
Build error
Create weaviate_utils.py
#1
by
jskinner215
- opened
- weaviate_utils.py +33 -0
weaviate_utils.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import weaviate
|
| 2 |
+
from weaviate.embedded import EmbeddedOptions
|
| 3 |
+
from weaviate import Client
|
| 4 |
+
|
| 5 |
+
def initialize_weaviate_client():
|
| 6 |
+
return weaviate.Client(embedded_options=EmbeddedOptions())
|
| 7 |
+
|
| 8 |
+
def class_exists(client, class_name):
|
| 9 |
+
try:
|
| 10 |
+
client.schema.get_class(class_name)
|
| 11 |
+
return True
|
| 12 |
+
except:
|
| 13 |
+
return False
|
| 14 |
+
|
| 15 |
+
def map_dtype_to_weaviate(dtype):
|
| 16 |
+
if "int" in str(dtype):
|
| 17 |
+
return "int"
|
| 18 |
+
elif "float" in str(dtype):
|
| 19 |
+
return "number"
|
| 20 |
+
elif "bool" in str(dtype):
|
| 21 |
+
return "boolean"
|
| 22 |
+
else:
|
| 23 |
+
return "string"
|
| 24 |
+
|
| 25 |
+
def ingest_data_to_weaviate(client, dataframe, class_name, class_description):
|
| 26 |
+
# ... [same as in your code]
|
| 27 |
+
|
| 28 |
+
def get_class_schema(client, class_name):
|
| 29 |
+
all_classes = client.schema.get()["classes"]
|
| 30 |
+
for cls in all_classes:
|
| 31 |
+
if cls["class"] == class_name:
|
| 32 |
+
return cls
|
| 33 |
+
return None
|