entity isolation and estimateTokenFix
This commit is contained in:
@@ -177,8 +177,11 @@ function fuseEpisodeResults(semanticEps, keywordEps, { semanticWeight, keywordWe
|
||||
}
|
||||
|
||||
function estimateTokens(episode) {
|
||||
return episode.token_count
|
||||
?? Math.ceil((episode.user_message.length + episode.ai_response.length) / 4);
|
||||
//NOTE: episode.token_count is not used here. It stores the
|
||||
//full inference cost of that turn(prompt + injected memory + response),
|
||||
//this inflate the episodes apparent size and starving the budget.
|
||||
//Therefore, char/4 on the actual stored text is an honest selectedl
|
||||
return Math.ceil((episode.user_message.length + episode.ai_response.length) / 4);
|
||||
}
|
||||
|
||||
function buildScoredPool(fusedWithScores, recentEpisodes, entityBoostedIds, { entityWeight }) {
|
||||
|
||||
@@ -32,10 +32,18 @@ async function searchEpisodes( vector, {limit = ORCHESTRATION.RECENT_EPISODE_LIM
|
||||
async function searchEntities(vector, { limit = ORCHESTRATION.ENTITIES_LIMIT, scoreThreshold = ORCHESTRATION.ENTITIES_THRESHOLD, projectId = undefined } = {}) {
|
||||
const body = { vector, limit, score_threshold: scoreThreshold, with_payload: true };
|
||||
|
||||
// non-project chats must also be filters to the "no project" pool
|
||||
if (projectId !== null && projectId !== undefined) {
|
||||
body.filter = {
|
||||
must: [{ key: 'projectId', match: { value: projectId } }]
|
||||
};
|
||||
} else {
|
||||
//entities from project sessions carry a projectId;
|
||||
//without this branch, a non-project chat searches ALL entities and project knowledge leaks into the common pool.
|
||||
//is_empty matches null AND missing payload keys, so pre-isolation-era entities are covered too
|
||||
body.filter = {
|
||||
must: [{ is_empty: {key: 'projectId'} }]
|
||||
}
|
||||
}
|
||||
const res = await fetch(
|
||||
`${BASE_URL}/collections/${COLLECTIONS.ENTITIES}/points/search`,
|
||||
|
||||
Reference in New Issue
Block a user