code clean up pass
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const semantic = require('../semantic')
|
||||
const { getEnv, SERVICES, formatEpisodeText } = require('@nexusai/shared');
|
||||
const { getEnv, SERVICES, formatEpisodeText, ENTITIES } = require('@nexusai/shared');
|
||||
const { upsertEntity } = require('./index');
|
||||
|
||||
const EXTRACTION_URL = getEnv('EXTRACTION_URL', 'http://localhost:11434');
|
||||
@@ -63,12 +63,8 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
try {
|
||||
// Fetch existing entities to guide the model toward consistent name/type pairs
|
||||
const db = require('../db').getDB();
|
||||
console.log('[entities] fetching known entities...'); // add this
|
||||
const knownEntities = db.prepare(`SELECT name, type FROM entities ORDER BY rowid DESC LIMIT 20`).all();
|
||||
console.log('[entities] known entities count:', knownEntities.length);
|
||||
|
||||
const prompt = buildExtractionPrompt(userMessage, aiResponse, knownEntities);
|
||||
console.log('[entities] prompt preview:', JSON.stringify(prompt.slice(-300)));
|
||||
|
||||
|
||||
const res = await fetch(`${EXTRACTION_URL}/api/generate`, {
|
||||
@@ -80,8 +76,8 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
stream: false,
|
||||
format: 'json',
|
||||
options: {
|
||||
temperature: 0.1,
|
||||
num_predict: 1024,
|
||||
temperature: ENTITIES.TEMPERATURE,
|
||||
num_predict: ENTITIES.NUM_PREDICT,
|
||||
},
|
||||
}),
|
||||
});
|
||||
@@ -90,7 +86,6 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
|
||||
const data = await res.json();
|
||||
const raw = data.response?.trim() ?? '';
|
||||
console.log('[entities] raw response:', JSON.stringify(raw.slice(0, 300)));
|
||||
|
||||
const parsed = JSON.parse(raw);
|
||||
const entities = Array.isArray(parsed.entities) ? parsed.entities : [];
|
||||
@@ -122,7 +117,6 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
}))
|
||||
.catch(err => {
|
||||
console.warn(`[entities] Failed to embed entity "${entity.name}":`, err.message);
|
||||
console.warn(`[entities] Embed error stack:`, err.stack); // add this
|
||||
});
|
||||
|
||||
saved++;
|
||||
@@ -133,7 +127,6 @@ async function extractAndStoreEntities(userMessage, aiResponse, projectId=null)
|
||||
} catch (err) {
|
||||
// Non-critical — log and move on, episode is already saved
|
||||
console.warn('[entities] Extraction failed:', err.message);
|
||||
console.warn('[entities] Stack:', err.stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ function getSession(id) {
|
||||
}
|
||||
|
||||
|
||||
function getSessions(limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = 0, projectId = null) {
|
||||
function getSessions(limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = EPISODIC.DEFAULT_OFFSET, projectId = null) {
|
||||
const db = getDB();
|
||||
const stmt = projectId
|
||||
? db.prepare(`
|
||||
@@ -143,7 +143,7 @@ function getEpisode(id) {
|
||||
}
|
||||
|
||||
// Retrieves episodes for a given session, ordered by creation time descending, with pagination
|
||||
function getEpisodesBySession(sessionId, limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = 0) {
|
||||
function getEpisodesBySession(sessionId, limit = EPISODIC.DEFAULT_PAGE_SIZE, offset = EPISODIC.DEFAULT_OFFSET) {
|
||||
const db = getDB();
|
||||
const stmt = db.prepare(`
|
||||
SELECT * FROM episodes
|
||||
|
||||
Reference in New Issue
Block a user