Added semantic episode searching
This commit is contained in:
18
packages/orchestration-service/src/services/embedding.js
Normal file
18
packages/orchestration-service/src/services/embedding.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const {getEnv, SERVICES } = require('@nexusai/shared')
|
||||
|
||||
const BASE_URL = getEnv('EMBEDDING_SERVICE_URL', SERVICES.EMBEDDING_URL);
|
||||
|
||||
async function embed(text) {
|
||||
const res = await fetch(`${BASE_URL}/embed`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({text}),
|
||||
})
|
||||
|
||||
if (!res.ok) throw new Error(`Embedding service error: ${res.status}`);
|
||||
|
||||
const data = await res.json();
|
||||
return data.embedding;
|
||||
}
|
||||
|
||||
module.exports = { embed };
|
||||
@@ -40,9 +40,17 @@ async function createEpisode(sessionId, userMessage, aiResponse, tokenCount) {
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getEpisodeById(episodeId) {
|
||||
const res = await (`${BASE_URL}/episodes/${episodeId}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch episode: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSessionByExternalId,
|
||||
createSession,
|
||||
getRecentEpisodes,
|
||||
createEpisode
|
||||
createEpisode,
|
||||
getEpisodeById
|
||||
}
|
||||
27
packages/orchestration-service/src/services/qdrant.js
Normal file
27
packages/orchestration-service/src/services/qdrant.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const {getEnv, QDRANT, COLLECTIONS } = require('@nexusai/shared')
|
||||
|
||||
const BASE_URL = getEnv('QDrant_URL', QDRANT.DEFAULT_URL);
|
||||
|
||||
async function searchEpisodes( vector, {limit = 5, scoreThreshold = 0.75, sessionId } = {}) {
|
||||
const body = {vector, limit, score_threshold: scoreThreshold, with_payload: true};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
module.exports = { searchEpisodes };
|
||||
Reference in New Issue
Block a user