Browse Source

search api updated to include json w/ vector

master
cailean 4 months ago
parent
commit
b29f5a49f4
  1. 13
      server.js
  2. 2
      tree.txt

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;

2
tree.txt

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save