Hi @DudaNogueira Thank you fort sharing the code snippet, I tested it and your code is working and I am able to insert and retrieve the data. However below is my create_collection code with add_data() and get_data() functions which is not working.
def create_collection():
questions = client.collections.create(
name="Profile",
vector_config=wvc.config.Configure.Vectors.text2vec_weaviate(
model="Snowflake/snowflake-arctic-embed-l-v2.0",
source_properties=["complexion", "marital_status", "caste", "gender", "religion", "date_of_birth", "age", "sub_caste", "bio", "is_verified", "created_at", "profile_score", "updated_at", "name", "occupation", "height_in_kg", "weight_in_kg", "user_id", "user_family", "user_lifestyle", "user_work_history", "user_education"]
),
properties=[
wc.Property(name="complexion", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="marital_status", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="caste", data_type=wc.DataType.TEXT),
wc.Property(name="gender", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="religion", data_type=wc.DataType.TEXT),
wc.Property(name="date_of_birth", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="age", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="sub_caste", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="bio", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="is_verified", data_type=wc.DataType.BOOL, skip_vectorization=True),
wc.Property(name="created_at", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="profile_score", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="updated_at", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="name", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="occupation", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="height_in_cm", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="weight_in_kg", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="user_id", data_type=wc.DataType.TEXT, skip_vectorization=True),
# user_family object with nested properties
wc.Property(
name="user_family",
data_type=wc.DataType.OBJECT,
skip_vectorization=True,
nested_properties=[
wc.Property(name="father_name", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="father_education", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="father_occupation", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="mother_name", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="mother_education", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="mother_occupation", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="family_income", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="family_status", data_type=wc.DataType.TEXT, skip_vectorization=True),
],
),
# user_lifestyle object with nested properties (including an object array "hobbies")
wc.Property(
name="user_lifestyle",
data_type=wc.DataType.OBJECT,
skip_vectorization=True,
nested_properties=[
wc.Property(name="drinking", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="diet", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="smoking", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="physical_activity", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(
name="hobbies",
data_type=wc.DataType.OBJECT_ARRAY,
skip_vectorization=True,
nested_properties=[
wc.Property(name="category", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="name", data_type=wc.DataType.TEXT, skip_vectorization=True),
],
),
],
),
# user_work_history as array of objects
wc.Property(
name="user_work_history",
data_type=wc.DataType.OBJECT_ARRAY,
skip_vectorization=True,
nested_properties=[
wc.Property(name="employer", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="industry", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="job_location", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="salary", data_type=wc.DataType.NUMBER, skip_vectorization=True),
wc.Property(name="end_date", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="is_current_job", data_type=wc.DataType.BOOL, skip_vectorization=True),
wc.Property(name="updated_at", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="website", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="job_type", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="designation", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="start_date", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="details", data_type=wc.DataType.TEXT, skip_vectorization=True),
],
),
# user_education as array of objects
wc.Property(
name="user_education",
data_type=wc.DataType.OBJECT_ARRAY,
skip_vectorization=True,
nested_properties=[
wc.Property(name="grade", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="field_of_study", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="start_date", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="institution", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="end_date", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="city", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="description", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="state", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="country", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="university", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="education_type", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="degree", data_type=wc.DataType.TEXT, skip_vectorization=True),
wc.Property(name="education_status", data_type=wc.DataType.TEXT, skip_vectorization=True),
],
),
],
)
async def add_data(profile_data: Profile):
profile_collection = client.collections.get(name="Profile")
try:
# Convert SQLAlchemy model to dict
profile_data = {
'complexion': profile_data.complexion,
'marital_status': profile_data.marital_status,
'caste': profile_data.caste,
'gender': profile_data.gender,
'religion': profile_data.religion,
'date_of_birth': str(profile_data.date_of_birth) if profile_data.date_of_birth else None,
'age': profile_data.age,
'sub_caste': profile_data.sub_caste,
'bio': profile_data.bio,
'is_verified': profile_data.is_verified,
'created_at': str(profile_data.created_at) if profile_data.created_at else None,
'profile_score': profile_data.profile_score,
'updated_at': str(profile_data.updated_at) if profile_data.updated_at else None,
'name': profile_data.name,
'occupation': profile_data.occupation,
'height_in_cm': profile_data.height_in_cm,
'weight_in_kg': profile_data.weight_in_kg,
'user_id': str(profile_data.user_id) if profile_data.user_id else None,
}
# Add related data if available
if hasattr(profile_data, 'family') and profile_data.family:
profile_data['user_family'] = {
'father_name': profile_data.family.father_name,
'father_education': profile_data.family.father_education,
'father_occupation': profile_data.family.father_occupation,
'mother_name': profile_data.family.mother_name,
'mother_education': profile_data.family.mother_education,
'mother_occupation': profile_data.family.mother_occupation,
'family_income': profile_data.family.family_income,
'family_status': profile_data.family.family_status,
}
if hasattr(profile_data, 'lifestyle') and profile_data.lifestyle:
profile_data['user_lifestyle'] = {
'drinking': profile_data.lifestyle.drinking,
'diet': profile_data.lifestyle.diet,
'smoking': profile_data.lifestyle.smoking,
'physical_activity': profile_data.lifestyle.physical_activity,
'hobbies': [{'category': hobby.category, 'name': hobby.name} for hobby in profile_data.lifestyle.hobbies] if hasattr(profile_data.lifestyle, 'hobbies') else []
}
if hasattr(profile_data, 'work_history') and profile_data.work_history:
profile_data['user_work_history'] = [
{
'employer': work.employer,
'industry': work.industry,
'job_location': work.job_location,
'salary': work.salary,
'end_date': str(work.end_date) if work.end_date else None,
'is_current_job': work.is_current_job,
'updated_at': str(work.updated_at) if work.updated_at else None,
'website': work.website,
'job_type': work.job_type,
'designation': work.designation,
'start_date': str(work.start_date) if work.start_date else None,
'details': work.details,
} for work in profile_data.work_history
]
if hasattr(profile_data, 'education') and profile_data.education:
profile_data['user_education'] = [
{
'grade': edu.grade,
'field_of_study': edu.field_of_study,
'start_date': str(edu.start_date) if edu.start_date else None,
'institution': edu.institution,
'end_date': str(edu.end_date) if edu.end_date else None,
'city': edu.city,
'description': edu.description,
'state': edu.state,
'country': edu.country,
'university': edu.university,
'education_type': edu.education_type,
'degree': edu.degree,
'education_status': edu.education_status,
} for edu in profile_data.education
]
# Remove None values and convert to dict
profile_data = {k: v for k, v in profile_data.items() if v is not None}
# Remove boolean values and null values from nested objects
for key, value in profile_data.items():
if isinstance(value, dict):
profile_data[key] = {k: v for k, v in value.items() if v is not None and not isinstance(v, bool)}
elif isinstance(value, list):
profile_data[key] = [
{k: v for k, v in item.items() if v is not None and not isinstance(v, bool)}
for item in value
]
properties = profile_data
uuid = profile_collection.data.insert(properties)
print(f"Profile {profile_data.get('name', 'Unknown')}: {uuid}", end='\n')
except Exception as e:
print(f"Exception: {e}.")
def get_data():
profile_collection = client.collections.get(name="Profile")
user_input = input("Asad Ali")
print(f"Profile Collection: {profile_collection}")
response = profile_collection.query.near_text(
query=user_input,
limit=1
)
for profile in response.objects:
print(f"{profile.properties['name']}: {profile.user_id}")
return response[0]
Invoking add_data or get_data is returning Error:
Exception: Object was not added! Unexpected status code: 500, with response body: {'error': [{'message': 'vectorize target vector default: update vector: send POST request: Post "http://host.docker.internal:11434/api/embed": dial tcp: lookup host.docker.internal on 10.13.0.10:53: no such host'}]}..
There is a small difference in your code and my code is with respect to creation of collection, But other than that I am not sure why is it failing? Is it failing because my data is complex or something?