minor clean up

This commit is contained in:
Storme-bit
2026-04-27 20:17:05 -07:00
parent 055683424d
commit b58a4e4692
13 changed files with 171 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ const express = require('express');
const {getEnv, OLLAMA, PORTS, logger} = require('@nexusai/shared');
const app = express();
app.use(express.json());
app.use(express.json({ limit: '1mb' })); // limit request body to 1mb to prevent abuse - embedding requests should be small
const PORT = getEnv('PORT', PORTS.EMBEDDING);
const OLLAMA_URL = getEnv('OLLAMA_URL', OLLAMA.DEFAULT_URL);
@@ -14,7 +14,8 @@ async function embedText(text) {
const res = await fetch(`${OLLAMA_URL}/api/embed`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model: EMBED_MODEL, input: text })
body: JSON.stringify({ model: EMBED_MODEL, input: text }),
signal: AbortSignal.timeout(30_000),
});
if (!res.ok) {
@@ -37,7 +38,7 @@ app.get('/health', (req,res) => {
app.post('/embed', async (req, res) => {
const { text } = req.body;
if (!text || typeof text !== 'string' || text.trim() === '') {
return res.status(400).json({ error: 'text is required and must be empty' });
return res.status(400).json({ error: 'text is required and must not be empty' });
}
try {
@@ -60,7 +61,10 @@ app.post('/embed/batch', async (req, res) => {
}
try {
//sequential embedding for now, Ollama doesn't natively parallize embeddings
const invalid = texts.findIndex(t => !t || typeof t !== 'string' || t.trim() === '');
if (invalid !== -1)
return res.status(400).json({ error: `texts[${invalid}] is empty or not a string` });
const embeddings = [];
for (const text of texts) {
embeddings.push(await embedText(text.trim()));