search api updated to include json w/ vector
This commit is contained in:
13
server.js
13
server.js
@@ -36,17 +36,14 @@ buildVPTree()
|
|||||||
loadVPTree()
|
loadVPTree()
|
||||||
|
|
||||||
// Load tree endpoint
|
// Load tree endpoint
|
||||||
app.post('/search/:word', (req, res) => {
|
app.post('/search/', (req, res) => {
|
||||||
|
const { vector } = req.body;
|
||||||
|
|
||||||
const searchWord = req.params.word;
|
if (!Array.isArray(vector) || vector.length !== 7 || !vector.every(num => typeof num === 'number')) {
|
||||||
|
return res.status(400).send({ success: false, message: 'Invalid vector provided. It must be an array of 7 floating-point numbers.' });
|
||||||
if (!searchWord) {
|
|
||||||
return res.status(400).send({ success: false, message: 'No word provided' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vector = [angry, disgust, fear, happy, sad, suprise, neutral]
|
let idx = queryVPTree(vector)
|
||||||
let query_vec = [0, 0, 1.0, 0, 0, 0, 0]
|
|
||||||
let idx = queryVPTree(query_vec)
|
|
||||||
|
|
||||||
// Retrieve the filename from the stored JSON data
|
// Retrieve the filename from the stored JSON data
|
||||||
let filename = idx !== undefined && idx < jsonEmbeddings.length ? jsonEmbeddings[idx].filename : null;
|
let filename = idx !== undefined && idx < jsonEmbeddings.length ? jsonEmbeddings[idx].filename : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user