MongoDB Function
const {
dataSource,
database,
collection,
index,
queryVector,
apiKey,
URL
} = args.inputVars;
try {
const response = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*',
'api-key': apiKey,
'Accept': 'application/json'
},
body: JSON.stringify({
dataSource,
database,
collection,
pipeline: [
{
"$vectorSearch": {
"index": index,
"queryVector": queryVector,
"path": "plot_embedding",
"numCandidates": 100,
"limit": 5
}
},
{
"$project": {
"_id": 0,
"title": 1,
"plot": 1,
"score": { "$meta": "vectorSearchScore" }
}
}
]
})
});
const data = await response.json();
if (!response.ok) {
throw new Error(
HTTP error! status: ${response.status});}
return {
outputVars: {
documents: JSON.stringify(data.documents)
},
next: {
path: 'success',
},
};
} catch (error) {
return {
outputVars: {
error: error.message,
},
next: {
path: 'error',
},
};
}
}
When I run it i am getting this error: {"success":true,"latencyMS":574.2536602020264,"runtimeCommands":{"outputVars":{"error":"response.json is not a function"},"next":{"path":"error"}}}
