memory isolation fix

This commit is contained in:
Storme-bit
2026-04-19 01:02:52 -07:00
parent ed57a0331a
commit 56355d232b
7 changed files with 23 additions and 13 deletions

View File

@@ -107,10 +107,10 @@ async function getSemanticEpisodes(
}
}
async function getRelevantEntities(userMessage) {
async function getRelevantEntities(userMessage, projectId=null) {
try {
const vector = await embedding.embed(userMessage);
const results = await qdrant.searchEntities(vector);
const results = await qdrant.searchEntities(vector, { projectId });
console.log(
"[orchestration] Entity search results:",
results.map((r) => ({ name: r.payload?.name, score: r.score })),
@@ -176,7 +176,7 @@ async function chat(externalId, userMessage, options = {}) {
);
// 3b. Entity Search
const entities = await getRelevantEntities(userMessage);
const entities = await getRelevantEntities(userMessage, session.project_id ?? null);
// 4. Assemble prompt
const prompt = buildPrompt(
@@ -196,6 +196,7 @@ async function chat(externalId, userMessage, options = {}) {
userMessage,
result.text,
(result.evalCount || 0) + (result.promptEvalCount || 0),
session.project_id ?? null,
)
.catch((err) =>
console.error(`[orchestration] Failed to save episode`, err.message),
@@ -262,7 +263,7 @@ async function chatStream(externalId, userMessage, onChunk, options = {}) {
{semanticLimit, scoreThreshold }
);
const entities = await getRelevantEntities(userMessage);
const entities = await getRelevantEntities(userMessage, session.project_id ?? null);
const prompt = buildPrompt(
recentEpisodes,
@@ -323,7 +324,7 @@ async function chatStream(externalId, userMessage, onChunk, options = {}) {
console.log("[orchestration] final streamed text length:", fullText.length);
if (fullText.trim()) {
await memory.createEpisode(session.id, userMessage, fullText, tokenCount);
await memory.createEpisode(session.id, userMessage, fullText, tokenCount, session.project_id ?? null);
} else {
console.warn(
"[orchestration] Stream finished with no assistant text; episode not saved",