Skip to main content
Glama

search_memories_similarity

Find related memories by comparing embedding vector similarities on the AGI MCP Server, enabling AI systems to retrieve relevant past experiences based on a defined threshold and limit.

Instructions

Search memories by vector similarity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
embeddingYesQuery embedding vector
limitNoMaximum number of results
thresholdNoMinimum similarity threshold

Implementation Reference

  • Core implementation of search_memories_similarity: performs pgvector cosine similarity search on active memories, filters by threshold, orders by similarity distance, limits results, includes similarity score.
    async searchMemoriesBySimilarity(queryEmbedding, limit = 10, threshold = 0.7) { try { const embeddingVector = `[${queryEmbedding.join(',')}]`; const results = await this.db .select({ id: schema.memories.id, type: schema.memories.type, content: schema.memories.content, importance: schema.memories.importance, accessCount: schema.memories.accessCount, createdAt: schema.memories.createdAt, relevanceScore: schema.memories.relevanceScore, similarity: sql`1 - (${schema.memories.embedding} <=> ${embeddingVector}::vector)`.as('similarity') }) .from(schema.memories) .where( and( eq(schema.memories.status, 'active'), sql`1 - (${schema.memories.embedding} <=> ${embeddingVector}::vector) >= ${threshold}` ) ) .orderBy(sql`${schema.memories.embedding} <=> ${embeddingVector}::vector`) .limit(limit); return results; } catch (error) { const truncatedEmbedding = queryEmbedding.length > 10 ? `[${queryEmbedding.slice(0, 5).join(',')}...${queryEmbedding.slice(-5).join(',')}] (${queryEmbedding.length} values)` : `[${queryEmbedding.join(',')}]`; console.error('Error searching memories by similarity with embedding:', truncatedEmbedding, error.message); throw error; } }
  • mcp.js:546-552 (registration)
    MCP tool call handler: delegates to MemoryManager.searchMemoriesBySimilarity and formats response as MCP content.
    case "search_memories_similarity": const similarMemories = await memoryManager.searchMemoriesBySimilarity( args.embedding, args.limit || 10, args.threshold || 0.7 ); return { content: [{ type: "text", text: JSON.stringify(similarMemories, null, 2) }] };
  • mcp.js:63-86 (schema)
    Input schema definition for the tool, used in MCP ListTools response: requires embedding vector, optional limit and threshold.
    name: "search_memories_similarity", description: "Search memories by vector similarity", inputSchema: { type: "object", properties: { embedding: { type: "array", items: { type: "number" }, description: "Query embedding vector" }, limit: { type: "integer", description: "Maximum number of results", default: 10 }, threshold: { type: "number", description: "Minimum similarity threshold", default: 0.7 } }, required: ["embedding"] } },
  • Identical input schema definition exported in memoryTools array (possibly for reference or alternative use).
    name: "search_memories_similarity", description: "Search memories by vector similarity", inputSchema: { type: "object", properties: { embedding: { type: "array", items: { type: "number" }, description: "Query embedding vector" }, limit: { type: "integer", description: "Maximum number of results", default: 10 }, threshold: { type: "number", description: "Minimum similarity threshold", default: 0.7 } }, required: ["embedding"] } },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/QuixiAI/agi-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server