mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
@@ -25,22 +25,43 @@ export const MemoryManifest: BuiltinToolManifest = {
|
||||
parameters: {
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
query: { type: 'string' },
|
||||
query: {
|
||||
description: 'The search query to find relevant memories',
|
||||
type: 'string',
|
||||
},
|
||||
topK: {
|
||||
additionalProperties: false,
|
||||
description:
|
||||
'Limits on number of memories to return per layer, default to search 3 activities, 0 contexts, 0 experiences, and 0 preferences if not specified.',
|
||||
'Optional. Limits on number of memories to return per layer. If omitted entirely, uses defaults (3 activities, 3 preferences). Set a layer to 0 to exclude it.',
|
||||
properties: {
|
||||
activities: { minimum: 0, type: 'integer' },
|
||||
contexts: { minimum: 0, type: 'integer' },
|
||||
experiences: { minimum: 0, type: 'integer' },
|
||||
preferences: { minimum: 0, type: 'integer' },
|
||||
activities: {
|
||||
description: 'Number of activity memories (what happened, when, where). Default: 3',
|
||||
minimum: 0,
|
||||
type: 'integer',
|
||||
},
|
||||
contexts: {
|
||||
description:
|
||||
'Number of context memories (ongoing situations, projects). Default: 0',
|
||||
minimum: 0,
|
||||
type: 'integer',
|
||||
},
|
||||
experiences: {
|
||||
description:
|
||||
'Number of experience memories (lessons learned, insights). Default: 0',
|
||||
minimum: 0,
|
||||
type: 'integer',
|
||||
},
|
||||
preferences: {
|
||||
description:
|
||||
'Number of preference memories (user preferences, directives). Default: 3',
|
||||
minimum: 0,
|
||||
type: 'integer',
|
||||
},
|
||||
},
|
||||
required: ['contexts', 'experiences', 'preferences'],
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
required: ['query', 'topK'],
|
||||
required: ['query'],
|
||||
type: 'object',
|
||||
} satisfies JSONSchema7,
|
||||
},
|
||||
|
||||
@@ -8,16 +8,24 @@ import {
|
||||
} from './layers';
|
||||
|
||||
export const searchMemorySchema = z.object({
|
||||
// TODO: we need to dynamically fetch the available categories/types from the backend
|
||||
// memoryCategory: z.string().optional(),
|
||||
// memoryType: z.string().optional(),
|
||||
query: z.string(),
|
||||
topK: z.object({
|
||||
activities: z.coerce.number().int().min(0),
|
||||
contexts: z.coerce.number().int().min(0),
|
||||
experiences: z.coerce.number().int().min(0),
|
||||
preferences: z.coerce.number().int().min(0),
|
||||
}),
|
||||
/**
|
||||
* Optional limits for each memory layer. If omitted, server defaults are used.
|
||||
* Each field is optional - only specify layers you want to customize.
|
||||
* Set a layer to 0 to exclude it from search results.
|
||||
*/
|
||||
topK: z
|
||||
.object({
|
||||
/** Number of activity memories to return */
|
||||
activities: z.number().int().min(0).optional(),
|
||||
/** Number of context memories to return */
|
||||
contexts: z.number().int().min(0).optional(),
|
||||
/** Number of experience memories to return */
|
||||
experiences: z.number().int().min(0).optional(),
|
||||
/** Number of preference memories to return */
|
||||
preferences: z.number().int().min(0).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type SearchMemoryParams = z.infer<typeof searchMemorySchema>;
|
||||
|
||||
@@ -146,10 +146,10 @@ const searchUserMemories = async (
|
||||
});
|
||||
|
||||
const limits = {
|
||||
activities: input.topK?.activities,
|
||||
contexts: input.topK?.contexts,
|
||||
experiences: input.topK?.experiences,
|
||||
preferences: input.topK?.preferences,
|
||||
activities: input.topK?.activities ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.activities,
|
||||
contexts: input.topK?.contexts ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.contexts,
|
||||
experiences: input.topK?.experiences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.experiences,
|
||||
preferences: input.topK?.preferences ?? DEFAULT_SEARCH_USER_MEMORY_TOP_K.preferences,
|
||||
};
|
||||
|
||||
const layeredResults = await ctx.memoryModel.searchWithEmbedding({
|
||||
|
||||
Reference in New Issue
Block a user