Voiceflow PartnersVPVoiceflow Partners
Powered by
forward-apricotF
Voiceflow Partners•2y ago•
1 reply
forward-apricot

MongoDB Function

I have this current function to receive results from mongodb: export default async function main(args) {
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}
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"}}}
Voiceflow Partners banner
Voiceflow PartnersJoin
Exclusive community for Voiceflow Solutions Providers & Content Creators.
13,076Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Recent Announcements
jacklyn

# Let your agents search the web 🔎 Hey everyone! We just released the web search tool for the agent step! Your agents can now automatically search the web for information, letting your agent supplement the LLM's knowledge and the data in its knowledge base with live, up-to-date information. Plus.... * You can restrict searches to specific domains, so your agent only searches sites that you own * This is a tool, so you remain in control of when the agent searches the web * Results are automatically summarized in a way that your agent can automatically understand Under the hood, we're using OpenAI's web search API. Give it a try, and let us know what you think! https://docs.voiceflow.com/changelog/native-web-search-tool

jacklyn · 4mo ago

jacklyn

jacklynbiggin's Thread

jacklyn · 4mo ago

hurt-tomato

connor_maclean's Thread

hurt-tomato · 4mo ago

Similar Threads

function
CaioEliasCCaioElias / ❓┃ask-a-question
9mo ago
airtable function
scattered-tealSscattered-teal / ❓┃ask-a-question
8mo ago
Array filter function
moderate-tomatoMmoderate-tomato / ❓┃ask-a-question
2y ago
Perplexity AI function
significant-graySsignificant-gray / ❓┃ask-a-question
2y ago