const {getEnv, QDRANT, COLLECTIONS, ORCHESTRATION } = require('@nexusai/shared') const BASE_URL = getEnv('QDRANT_URL', QDRANT.DEFAULT_URL); async function searchEpisodes( vector, {limit = ORCHESTRATION.RECENT_EPISODE_LIMIT, scoreThreshold = ORCHESTRATION.SCORE_THRESHOLD, sessionId, projectSessionIds } = {}) { const body = {vector, limit, score_threshold: scoreThreshold, with_payload: true}; if(projectSessionIds) { body.filter = { should: projectSessionIds.map(id => ({ key: 'sessionId', match: { value: id } })) }; } else if (sessionId) { body.filter = { must: [{key: 'sessionId', match: {value: sessionId} }] }; } const res = await fetch ( `${BASE_URL}/collections/${COLLECTIONS.EPISODES}/points/search`, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(body) } ); if (!res.ok) throw new Error(`QDrant error: ${res.status}`); const data = await res.json(); return data.result; } async function searchEntities(vector, { limit = ORCHESTRATION.ENTITIES_LIMIT, scoreThreshold = ORCHESTRATION.ENTITIES_THRESHOLD, projectId = undefined } = {}) { const body = { vector, limit, score_threshold: scoreThreshold, with_payload: true }; if (projectId !== undefined) { body.filter = { must: [{ key: 'projectId', match: { value: projectId ?? null } }] }; } const res = await fetch( `${BASE_URL}/collections/${COLLECTIONS.ENTITIES}/points/search`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), } ); if (!res.ok) throw new Error(`Qdrant error: ${res.status}`); const data = await res.json(); return data.result; } module.exports = { searchEpisodes, searchEntities };