Use Express router for vectors endpoint
This commit is contained in:
parent
414c9bd5fb
commit
68049afd84
|
@ -3612,7 +3612,7 @@ require('./src/endpoints/stable-diffusion').registerEndpoints(app, jsonParser);
|
|||
require('./src/endpoints/horde').registerEndpoints(app, jsonParser);
|
||||
|
||||
// Vector storage DB
|
||||
require('./src/endpoints/vectors').registerEndpoints(app, jsonParser);
|
||||
app.use('/api/vector', require('./src/endpoints/vectors').router);
|
||||
|
||||
// Chat translation
|
||||
require('./src/endpoints/translate').registerEndpoints(app, jsonParser);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const vectra = require('vectra');
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const { jsonParser } = require('../express-common');
|
||||
|
||||
/**
|
||||
* Gets the vector for the given text from the given source.
|
||||
|
@ -112,13 +114,9 @@ async function queryCollection(collectionId, source, searchText, topK) {
|
|||
return { metadata, hashes };
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the endpoints for the vector API
|
||||
* @param {express.Express} app - Express app
|
||||
* @param {any} jsonParser - Express JSON parser
|
||||
*/
|
||||
async function registerEndpoints(app, jsonParser) {
|
||||
app.post('/api/vector/query', jsonParser, async (req, res) => {
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/query', jsonParser, async (req, res) => {
|
||||
try {
|
||||
if (!req.body.collectionId || !req.body.searchText) {
|
||||
return res.sendStatus(400);
|
||||
|
@ -135,9 +133,9 @@ async function registerEndpoints(app, jsonParser) {
|
|||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/vector/insert', jsonParser, async (req, res) => {
|
||||
router.post('/insert', jsonParser, async (req, res) => {
|
||||
try {
|
||||
if (!Array.isArray(req.body.items) || !req.body.collectionId) {
|
||||
return res.sendStatus(400);
|
||||
|
@ -153,9 +151,9 @@ async function registerEndpoints(app, jsonParser) {
|
|||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/vector/list', jsonParser, async (req, res) => {
|
||||
router.post('/list', jsonParser, async (req, res) => {
|
||||
try {
|
||||
if (!req.body.collectionId) {
|
||||
return res.sendStatus(400);
|
||||
|
@ -170,9 +168,9 @@ async function registerEndpoints(app, jsonParser) {
|
|||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/vector/delete', jsonParser, async (req, res) => {
|
||||
router.post('/delete', jsonParser, async (req, res) => {
|
||||
try {
|
||||
if (!Array.isArray(req.body.hashes) || !req.body.collectionId) {
|
||||
return res.sendStatus(400);
|
||||
|
@ -188,9 +186,9 @@ async function registerEndpoints(app, jsonParser) {
|
|||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/api/vector/purge', jsonParser, async (req, res) => {
|
||||
router.post('/purge', jsonParser, async (req, res) => {
|
||||
try {
|
||||
if (!req.body.collectionId) {
|
||||
return res.sendStatus(400);
|
||||
|
@ -218,7 +216,6 @@ async function registerEndpoints(app, jsonParser) {
|
|||
console.error(error);
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = { registerEndpoints };
|
||||
module.exports = { router };
|
||||
|
|
Loading…
Reference in New Issue