memory isolation fix
This commit is contained in:
@@ -64,7 +64,7 @@ async function embedEntity(entity) {
|
||||
return data.embedding;
|
||||
}
|
||||
|
||||
async function extractAndStoreEntities(userMessage, aiResponse) {
|
||||
async function extractAndStoreEntities(userMessage, aiResponse, projectId=null) {
|
||||
console.log('[entities] Extraction triggered')
|
||||
try {
|
||||
// Fetch existing entities to guide the model toward consistent name/type pairs
|
||||
@@ -109,6 +109,7 @@ async function extractAndStoreEntities(userMessage, aiResponse) {
|
||||
name: entity.name,
|
||||
type: entity.type,
|
||||
notes: entity.notes,
|
||||
projectId: projectId ?? null,
|
||||
}))
|
||||
.catch(err => {
|
||||
console.warn(`[entities] Failed to embed entity "${entity.name}":`, err.message);
|
||||
|
||||
@@ -98,7 +98,7 @@ function deleteSessionByExternalId(externalId) {
|
||||
|
||||
// --Episodes --------------------------------------------------
|
||||
// Creates a new episode linked to a session, with user message, AI response, optional token count, and metadata
|
||||
async function createEpisode(sessionId, userMessage, aiResponse, tokenCount = null, metadata = null) {
|
||||
async function createEpisode(sessionId, userMessage, aiResponse, tokenCount = null, metadata = null, projectId=null) {
|
||||
const db = getDB();
|
||||
|
||||
// Wrap insert + session touch in a transaction — both succeed or neither does
|
||||
@@ -128,7 +128,7 @@ async function createEpisode(sessionId, userMessage, aiResponse, tokenCount = nu
|
||||
}))
|
||||
.catch(err => console.error(`Failed to embed episode ${episode.id}:`, err.message));
|
||||
|
||||
extractAndStoreEntities(userMessage, aiResponse)
|
||||
extractAndStoreEntities(userMessage, aiResponse, projectId)
|
||||
.catch(err => console.error(`Failed to extract entities for episode ${episode.id}:`, err.message));
|
||||
|
||||
|
||||
|
||||
@@ -96,11 +96,11 @@ app.delete('/sessions/by-external/:externalId', (req, res) => {
|
||||
/************************************* */
|
||||
|
||||
app.post('/episodes', async (req, res) => {
|
||||
const { sessionId, userMessage, aiResponse, tokenCount, metadata } = req.body;
|
||||
const { sessionId, userMessage, aiResponse, tokenCount, metadata, projectId } = req.body;
|
||||
if (!sessionId || !userMessage || !aiResponse) {
|
||||
return res.status(400).json({ error: 'sessionId, userMessage and aiResponse are required' });
|
||||
}
|
||||
const episode = await episodic.createEpisode(sessionId, userMessage, aiResponse, tokenCount, metadata);
|
||||
const episode = await episodic.createEpisode(sessionId, userMessage, aiResponse, tokenCount, metadata, projectId);
|
||||
|
||||
console.log('[memory] create episode body:', {
|
||||
sessionId,
|
||||
|
||||
Reference in New Issue
Block a user