Need a support in custom vector search with my own embeddings

I tried to search mu own embeddings but the following error raised. Please share the tutorial for own embedding search or share the solution
raise MarqoWebError(message=response_msg, code=code, error_type=error_type,
marqo.errors.MarqoWebError: MarqoWebError: MarqoWebError Error message: {‘detail’: [{‘loc’: [‘body’, ‘q’], ‘msg’: ‘str type expected’, ‘type’: ‘type_error.str’}, {‘loc’: [‘body’, ‘q’, ‘my_custom_vector’], ‘msg’: ‘value is not a valid float’, ‘type’: ‘type_error.float’}, {‘loc’: [‘body’, ‘q’, ‘customVector’], ‘msg’: ‘field required’, ‘type’: ‘value_error.missing’}, {‘loc’: [‘body’, ‘q’, ‘my_custom_vector’], ‘msg’: ‘extra fields not permitted’, ‘type’: ‘value_error.extra’}], ‘code’: ‘unprocessable_entity’, ‘type’: ‘invalid_request’, ‘link’: ‘’}
status_code: 422, type: invalid_request, code: unprocessable_entity, link:

import marqo
mq = marqo.Client(url='http://localhost:8882')
import numpy as np

settings = {
    "type": "structured",
    # "model": "open_clip/ViT-B-32/laion2b_s34b_b79k",
    "all_fields": [{"name": "my_custom_vector", "type": "custom_vector"}],
    "tensor_fields": ["my_custom_vector"],
    "ann_parameters": {
        "spaceType": "angular",
        "parameters": {"efConstruction": 512, "m": 16},
    },
}

mq.create_index("my-index-2", **settings)

example_vector_1 = [float(i) for i in range(768)]
arr1 = np.array(example_vector_1)
arr2 = arr1 + 2.0
arr3 = arr1 + 4.0
arr4 = arr1 + 6.0
arr5 = arr1 + 8.0


res = mq.index("my-index-2").add_documents(
    documents=[
        {
            "_id": "doc1",
            "my_custom_vector": {
                # Put your own vector (of correct length) here.
                "vector": arr1.tolist()
            },
        },
        {
            "_id": "doc2",
            "my_custom_vector": {
                # Put your own vector (of correct length) here.
                "vector": arr2.tolist()
            },
        },
        {
            "_id": "doc3",
            "my_custom_vector": {
                # Put your own vector (of correct length) here.
                "vector": arr3.tolist()
            },
        },
        {
            "_id": "doc4",
            "my_custom_vector": {
                # Put your own vector (of correct length) here.
                "vector": arr4.tolist()
            },
        },
        {
            "_id": "doc5",
            "my_custom_vector": {
                # Put your own vector (of correct length) here.
                "vector": arr5.tolist()
            },
        },
    ]
)
print(res)

example_vector_1 = [float(i) for i in range(768)]
qu = np.array(example_vector_1)+8.5
print(qu)

q = {
    'q':{
        "my_custom_vector" : {"vector": qu.tolist()}
    }
}
results = mq.index("my-index-2").search(q=q)
print(results)

Hello @Dhamu785 , there are two issues in the search request you posted in this thread.

  1. There’s an extra layer of q in your request
  2. The custom vector search request need to be in this json format:
    {"customVector": {"vector": [...]}

could you please try this instead? Thanks

q = {
    "customVector" : {"vector": qu.tolist()}
}
1 Like

Thank you, It solved my error.

1 Like