Unexpected status code: 500

Description

I am trying to add an object to my collect using weaviate but getting below 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'}]}.. 

Here is my python code :

weaviate_url = os.environ["WEAVIATE_URL"]
weaviate_api_key = os.environ["WEAVIATE_API_KEY"]

# Connect to Weaviate Cloud
client = weaviate.connect_to_weaviate_cloud(
    cluster_url=weaviate_url,
    auth_credentials=Auth.api_key(weaviate_api_key),
)

print(client.is_ready())
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=["name", "bio", "occupation", "religion", "caste", "sub_caste"]
        ),
        properties=[.....],
    )
async def add_data(profile_data: Profile):
    profile_collection = client.collections.get(name="Profile")
    try:
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}.")

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’}]}..

hi @Asad_Ali !!

Welcome to our community :hugs:

I can’t see the error, can you try sending it again? Make sure to copy the entire stack trace, and not only the final message.

Thanks!

Hi @DudaNogueira I have updated the post with error

hi @Asad_Ali !!

That’s strange. The error indicates that your Weaviate server is reaching out to http://host.docker.internal:11434/api/embed instead of Weaviate Embedding server.

here is an isolated, small snippet that should work in a Weaviate hosted cluster. Let me know if you can run this code and get the same output:

client.collections.delete("Test") # WARNING! DELETING TEST COLLECTION
collection = client.collections.create(
    "Test",
    properties=[
        wvc.config.Property(name="content", data_type=wvc.config.DataType.TEXT),
    ],
    vectorizer_config=[
        wvc.config.Configure.NamedVectors.text2vec_weaviate(
            name="default",
            model="Snowflake/snowflake-arctic-embed-l-v2.0",
            source_properties=["content"]
        ),
    ]
)
collection.data.insert({"content": "A dog can bark"})
collection.data.insert({"content": "A cat can climb a tree"})
collection.data.insert({"content": "The Lion is the king of the forest"})
collection.data.insert({"content": "A Giraffe is a tall animal"})

for obj in collection.query.near_text("Jungle animals", return_metadata=wvc.query.MetadataQuery(distance=True)).objects:
    print(obj.properties, obj.metadata.distance)

Should output:

{'content': 'A Giraffe is a tall animal'} 0.6812568306922913
{'content': 'The Lion is the king of the forest'} 0.722403883934021
{'content': 'A cat can climb a tree'} 0.8355672359466553
{'content': 'A dog can bark'} 0.934282660484314

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?

Ok, a couple issues I am finding.

If you define one vectorizer, like in (notice you got it wrong: wvc.config.Configure.Vectors.text2vec_weaviate):

questions = client.collections.create(
    name="Profile",
    vector_config=wvc.config.Configure.Vectorizer.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"]
    ),

You don’t need to specify the source_properties, as those will be defined at the property level.

We suggest always using the NamedVectors approach, you need to specify the name parameter, and optionally the source_properties. If not provided, all properties will be used on vectorization.

here is a working snippet of you code:

from weaviate.classes import config as wc
from weaviate import classes as wvc

client.collections.delete("ProfileTest")

questions = client.collections.create(
    name="ProfileTest",
    vectorizer_config=[
        wvc.config.Configure.NamedVectors.text2vec_weaviate(
            name="default",
            model="Snowflake/snowflake-arctic-embed-l-v2.0",
            # below you can choose which properties to use. I have ommited, so it will select all properties
            # source_properties=["complexion", ...]
        ),
    ],
    properties=[
        wc.Property(name="complexion", data_type=wc.DataType.TEXT),
        wc.Property(name="marital_status",data_type=wc.DataType.TEXT),
        wc.Property(name="caste", data_type=wc.DataType.TEXT),
        wc.Property(name="gender", data_type=wc.DataType.TEXT),
        wc.Property(name="religion", data_type=wc.DataType.TEXT),
        wc.Property(name="date_of_birth",data_type=wc.DataType.TEXT),
        wc.Property(name="age", data_type=wc.DataType.NUMBER),
        wc.Property(name="sub_caste", data_type=wc.DataType.TEXT),
        wc.Property(name="bio", data_type=wc.DataType.TEXT),
        wc.Property(name="is_verified", data_type=wc.DataType.BOOL),
        wc.Property(name="created_at", data_type=wc.DataType.TEXT),
        wc.Property(name="profile_score", data_type=wc.DataType.NUMBER),
        wc.Property(name="updated_at", data_type=wc.DataType.TEXT),
        wc.Property(name="name", data_type=wc.DataType.TEXT),
        wc.Property(name="occupation", data_type=wc.DataType.TEXT),
        wc.Property(name="height_in_cm", data_type=wc.DataType.NUMBER),
        wc.Property(name="weight_in_kg", data_type=wc.DataType.NUMBER),
        wc.Property(name="user_id", data_type=wc.DataType.TEXT),

        # user_family object with nested properties
        # Notice, nested objects are not vectorizable not filterable.
        # https://docs.weaviate.io/weaviate/config-refs/datatypes#object
        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),
                wc.Property(name="father_education", data_type=wc.DataType.TEXT),
                wc.Property(name="father_occupation", data_type=wc.DataType.TEXT),
                wc.Property(name="mother_name", data_type=wc.DataType.TEXT),
                wc.Property(name="mother_education", data_type=wc.DataType.TEXT),
                wc.Property(name="mother_occupation", data_type=wc.DataType.TEXT),
                wc.Property(name="family_income", data_type=wc.DataType.NUMBER),
                wc.Property(name="family_status", data_type=wc.DataType.TEXT),
            ],
        ),
    ],
)

# INSERT SOME DATA
questions.data.insert({"complexion": "A dog can bark"})
questions.data.insert({"complexion": "A cat can climb a tree"})
questions.data.insert({"complexion": "The Lion is the king of the forest"})
questions.data.insert({"complexion": "A Giraffe is a tall animal"})

# DO THE QUERY
for obj in questions.query.near_text("Jungle animals", return_metadata=wvc.query.MetadataQuery(distance=True)).objects:
    print(obj.properties.get("complexion"), obj.metadata.distance)

Let me know if this helps!

Hi @DudaNogueira Thank you that was helpful and it really worked. However I am trying to use weaviate agent to get the result. I tried adding filters in the agent query but it is not working. Below is the code snippet

 agent = QueryAgent(
        client=client,
        collections=[
            QueryAgentCollectionConfig(
            name="Profile",
            target_vector=[
                "profile_vectorizer",
            ],
            filters=Filter.by_property("gender").equal("Female"),
            ),
        ],
        )
    result = agent.run(query)
    print(f"Result: {result.final_answer}")
    profile_list = []
    for source in result.sources:
        profile = profile_collection.query.near_object(near_object=source.object_id)
        print(f"Profile: {profile}")
        profile_list.append(profile)
    return profile_list

I am trying to filter by gender but the actual result has other gender too.

Another problem with the above agent code is that it is giving result with the object_id instead of particular profile from the collection and so I need to perform another lookup based on object_id to get profile one by one as you can see in the above code.

My simple requirement is to get matching profiles based on query(age, occupation, salary etc) and filters(like only females or males profile). Let me know if you have any code samples or Github repo(Jupyter notebook) link where I can find all complex read and write from/to collection based on query and filters.