search api updated to include json w/ vector

This commit is contained in:
2024-08-16 13:45:33 +01:00
parent 468e07ccfc
commit b29f5a49f4
2 changed files with 6 additions and 9 deletions

View File

@@ -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;

File diff suppressed because one or more lines are too long