Hi @CedricHadjian. Thanks for reaching out! I was able to tweak the code you have shared a bit and w

Hi @CedricHadjian. Thanks for reaching out! I was able to tweak the code you have shared a bit and was able to get it to work. This is a codeblock that works as expected.

            try {
                const text = 'Liam Marshall';

                const ai_response = await env.AI.run('@cf/baai/bge-small-en-v1.5', {
                    text,
                });

                const vectorize_response = await env.TESTVECTORS.insert([
                    {
                        id: '1',
                        values: ai_response.data[0],
                        metadata: {
                            key: 'value',
                        },
                    },
                ]);

                return new Response(JSON.stringify(vectorize_response), {
                    headers: {
                        'content-type': 'text/plain;charset=UTF-8',
                        'Access-Control-Allow-Origin': '*',
                    },
                });
            } catch (error) {
                console.log(error);
            }


Summary of the fixes:
  1. I enclosed the object being passed to the Vectorize insert operation in square brackets. This is needed because the insert function requires the input to be of an Array type.
  2. I converted the id from 1 to '1'. This is needed because Vectorize vector identifiers need to be of a String type.
Feel free to reach out if you need additional support for Vectorize!
Was this page helpful?