Skip to main content
Glama

search_memories_similarity

Find stored memories by comparing vector embeddings to retrieve semantically similar content based on similarity thresholds.

Instructions

Search memories by vector similarity

Input Schema

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

Implementation Reference

  • The actual implementation of searchMemoriesBySimilarity method that performs vector similarity search using PostgreSQL's <=> operator to find memories with embeddings above a threshold, ordered by similarity distance.
    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)
    The tool handler case that receives the tool request and calls memoryManager.searchMemoriesBySimilarity with the embedding, limit, and threshold parameters.
    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:62-86 (schema)
    The tool schema definition for search_memories_similarity including its description, input parameters (embedding array, limit integer, threshold number), and required fields.
    {
      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"]
      }
    },
  • A standalone schema definition for search_memories_similarity in the memory-tools module, defining the same input validation structure as the main registration.
      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"]
      }
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the search method but doesn't describe what 'memories' are in this context, how results are returned (format, ordering), whether this is a read-only operation, or any performance/rate limit considerations. For a search tool with 3 parameters, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's appropriately sized for a search tool and front-loads the core purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and 3 parameters, the description is incomplete. It doesn't explain what constitutes a 'memory' in this system, what the search returns (e.g., memory objects with scores), or how similarity is calculated. For a vector similarity search tool, this leaves too much contextual ambiguity for effective agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (embedding, limit, threshold) with descriptions. The description adds no additional parameter semantics beyond implying that 'embedding' is used for 'vector similarity' search, which is already clear from the schema. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search memories by vector similarity' clearly states the verb (search) and resource (memories) with the specific method (vector similarity). It distinguishes from sibling tools like 'search_memories_text' and 'search_memories_advanced' by specifying the similarity-based approach, though it doesn't fully explain how it differs operationally from those alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_memories_text' or 'search_memories_advanced'. It mentions 'vector similarity' which implies usage with embeddings, but doesn't explicitly state prerequisites, exclusions, or comparative contexts with sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/randyandrade/agi-mcp-server'

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