🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(database): remove dead fallbacks behind v8 ignore in userMemory/query and sources (#22450)
Arvin Xu6a07151f6045
diff --git a/packages/database/src/models/userMemory/query/scoring.ts b/packages/database/src/models/userMemory/query/scoring.tsindex 0c20c366f1f..d6803749517 100644--- a/packages/database/src/models/userMemory/query/scoring.ts+++ b/packages/database/src/models/userMemory/query/scoring.ts@@ -13,27 +13,13 @@ const SHORT_TERM_ASSOCIATION_WINDOW_MS = 1000 * 60 * 60 * 24 * 3;const normalizeSimilarityTerm = (value: string) => value.trim().toLowerCase();-const normalizeSearchTerms = (values?: string[]) => [- ...new Set(- (- values ??- // v8 ignore start -- unreachable: both callers pass an array- []- )- // v8 ignore stop- .map((value) => normalizeSimilarityTerm(value))- .filter(Boolean),- ),+const normalizeSearchTerms = (values: string[]) => [+ ...new Set(values.map((value) => normalizeSimilarityTerm(value)).filter(Boolean)),];const clampScore = (value: number) => Math.max(0, Math.min(1, value));-const reciprocalRankScore = (rank?: number) =>- rank === undefined- ? // v8 ignore start -- unreachable: callers always pass the list index; the pair is ignored because a skipped first arm shifts the second arm's count- 0- : 1 / (rank + 1);-// v8 ignore stop+const reciprocalRankScore = (rank: number) => 1 / (rank + 1);const tokenizeSimilarityTerm = (value: string) =>normalizeSimilarityTerm(value)@@ -48,11 +34,7 @@ const computeTokenJaccard = (left: string[], right: string[]) => {const intersection = [...leftSet].filter((token) => rightSet.has(token)).length;const union = new Set([...leftSet, ...rightSet]).size;- return union === 0- ? // v8 ignore start -- unreachable: both token lists are non-empty here; the pair is ignored because a skipped first arm shifts the second arm's count- 0- : intersection / union;- // v8 ignore stop+ return intersection / union;};const computeTermSimilarity = (left: string, right: string) => {diff --git a/packages/database/src/models/userMemory/query/searchMemory.ts b/packages/database/src/models/userMemory/query/searchMemory.tsindex 8a279cf5c6e..dbab60551df 100644--- a/packages/database/src/models/userMemory/query/searchMemory.ts+++ b/packages/database/src/models/userMemory/query/searchMemory.ts@@ -12,14 +12,6 @@ import type {} from './types';import { normalizeUserMemorySearchQueries, shouldRunUserMemoryLexicalSearch } from './utils';-interface HybridLayerLimitRecord {- activities?: number;- contexts?: number;- experiences?: number;- identities?: number;- preferences?: number;-}-const createEmptySearchLayerMeta = (): Record<SearchLayerKey, HybridSearchLayerMeta> => ({activities: { hasMore: false, returned: 0, total: 0 },contexts: { hasMore: false, returned: 0, total: 0 },@@ -35,7 +27,7 @@ export const searchMemory = async (): Promise<UserMemoryHybridSearchAggregatedResult> => {const appliedQueries = normalizeUserMemorySearchQueries(params.queries);const lexicalSearch = shouldRunUserMemoryLexicalSearch(appliedQueries, queryEmbeddings);- const limits: HybridLayerLimitRecord = {+ const limits: Record<SearchLayerKey, number> = {activities: params.topK?.activities ?? DEFAULT_HYBRID_SEARCH_LIMIT,contexts: params.topK?.contexts ?? DEFAULT_HYBRID_SEARCH_LIMIT,experiences: params.topK?.experiences ?? DEFAULT_HYBRID_SEARCH_LIMIT,@@ -49,36 +41,16 @@ export const searchMemory = async (if (layer === LayersEnum.Experience) return false;switch (layer) {case LayersEnum.Activity: {- return (- (limits.activities ??- // v8 ignore start -- unreachable: limits.activities always falls back to DEFAULT_HYBRID_SEARCH_LIMIT- 0) > 0- // v8 ignore stop- );+ return limits.activities > 0;}case LayersEnum.Context: {- return (- (limits.contexts ??- // v8 ignore start -- unreachable: limits.contexts always falls back to DEFAULT_HYBRID_SEARCH_LIMIT- 0) > 0- // v8 ignore stop- );+ return limits.contexts > 0;}case LayersEnum.Identity: {- return (- (limits.identities ??- // v8 ignore start -- unreachable: limits.identities always falls back to DEFAULT_HYBRID_SEARCH_LIMIT- 0) > 0- // v8 ignore stop- );+ return limits.identities > 0;}case LayersEnum.Preference: {- return (- (limits.preferences ??- // v8 ignore start -- unreachable: limits.preferences always falls back to DEFAULT_HYBRID_SEARCH_LIMIT- 0) > 0- // v8 ignore stop- );+ return limits.preferences > 0;}}}),@@ -86,7 +58,7 @@ export const searchMemory = async (const layerMeta = createEmptySearchLayerMeta();- const [activities, contexts, experiences, identities, preferences] = await Promise.all([+ const [activities, contexts, identities, preferences] = await Promise.all([requestedLayers.has(LayersEnum.Activity)? ctx.searchHybridActivities({embeddings: queryEmbeddings,@@ -103,16 +75,6 @@ export const searchMemory = async (queries: appliedQueries,}): Promise.resolve([]),- requestedLayers.has(LayersEnum.Experience)- ? // v8 ignore start -- unreachable: requestedLayers filters out LayersEnum.Experience; the pair is ignored because a skipped first arm shifts the second arm's count- ctx.searchHybridExperiences({- embeddings: queryEmbeddings,- lexicalSearch,- params,- queries: appliedQueries,- })- : Promise.resolve([]),- // v8 ignore stoprequestedLayers.has(LayersEnum.Identity)? ctx.searchHybridIdentities({embeddings: queryEmbeddings,@@ -137,11 +99,7 @@ export const searchMemory = async (key: SearchLayerKey,items: RankedSearchCandidate<T>[],) => {- const limit =- limits[key] ??- // v8 ignore start -- unreachable: every limits entry is already defaulted- DEFAULT_HYBRID_SEARCH_LIMIT;- // v8 ignore stop+ const limit = limits[key];const sorted = items.sort((left, right) => right.score.final - left.score.final);const selected = sorted.slice(0, limit).map((entry) => entry.item);ranking[key] = Object.fromEntries(@@ -160,7 +118,7 @@ export const searchMemory = async (return {activities: finalizeLayer('activities', activities),contexts: finalizeLayer('contexts', contexts),- experiences: finalizeLayer('experiences', experiences),+ experiences: finalizeLayer('experiences', []),identities: finalizeLayer('identities', identities),meta: {appliedFilters: {diff --git a/packages/database/src/models/userMemory/sources/benchmarkLoCoMo.ts b/packages/database/src/models/userMemory/sources/benchmarkLoCoMo.tsindex 855b5df3246..5c750b0d749 100644--- a/packages/database/src/models/userMemory/sources/benchmarkLoCoMo.ts+++ b/packages/database/src/models/userMemory/sources/benchmarkLoCoMo.ts@@ -10,6 +10,8 @@ export interface BenchmarkLoCoMoPart {speaker?: string;}+type StoredBenchmarkLoCoMoPart = BenchmarkLoCoMoPart & { createdAt: Date };+export interface UpsertBenchmarkLoCoMoParams {id?: string;metadata?: Record<string, unknown>;@@ -19,7 +21,7 @@ export interface UpsertBenchmarkLoCoMoParams {export class UserMemorySourceBenchmarkLoCoMoModel {private static readonly sources = new Map<string, Map<string, UserMemorySource>>();- private static readonly parts = new Map<string, Map<string, BenchmarkLoCoMoPart[]>>();+ private static readonly parts = new Map<string, Map<string, StoredBenchmarkLoCoMoPart[]>>();private readonly userId: string;constructor(userId: string) {@@ -68,7 +70,7 @@ export class UserMemorySourceBenchmarkLoCoMoModel {store.delete(sourceId);if (!parts.length) return;- const normalized = parts.map((part) => ({+ const normalized: StoredBenchmarkLoCoMoPart[] = parts.map((part) => ({...part,createdAt: part.createdAt ?? new Date(),}));@@ -85,16 +87,7 @@ export class UserMemorySourceBenchmarkLoCoMoModel {.sort((a, b) => {if (a.partIndex !== b.partIndex) return a.partIndex - b.partIndex;- return (- (a.createdAt?.getTime() ??- // v8 ignore start -- unreachable: replaceParts always sets createdAt- 0) -- // v8 ignore stop- (b.createdAt?.getTime() ??- // v8 ignore start -- unreachable: replaceParts always sets createdAt- 0)- // v8 ignore stop- );+ return a.createdAt.getTime() - b.createdAt.getTime();});}}