Skip to main content
Glama

find_similar_clusters

Identify clusters with similar characteristics to a reference cluster using similarity search in a vector-enhanced database for AI memory systems.

Instructions

Find clusters similar to a given cluster

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cluster_idYesUUID of the reference cluster
thresholdNoMinimum similarity threshold

Implementation Reference

  • Main handler implementation that executes SQL query to find clusters similar to a given cluster using vector cosine similarity (pgvector <=> operator). Takes clusterId and threshold parameters, returns array of similar clusters with similarity scores.
    async findSimilarClusters(clusterId, threshold = 0.7) {
      try {
        const embeddingVector = `[${Array(1536).fill(0).join(',')}]`;
        
        const results = await this.db.execute(sql`
          SELECT 
            mc2.*,
            1 - (mc1.centroid_embedding <=> mc2.centroid_embedding) as similarity
          FROM memory_clusters mc1
          CROSS JOIN memory_clusters mc2
          WHERE mc1.id = ${clusterId}
            AND mc2.id != ${clusterId}
            AND 1 - (mc1.centroid_embedding <=> mc2.centroid_embedding) >= ${threshold}
          ORDER BY similarity DESC
        `);
        
        return results.rows || [];
      } catch (error) {
        console.warn('Similar clusters query failed:', error.message);
        return [];
      }
    }
  • Tool schema definition in the tools registry. Defines input parameters: cluster_id (required string) and threshold (optional number with default 0.7). Describes the tool as finding clusters similar to a given cluster.
      name: "find_similar_clusters",
      description: "Find clusters similar to a given cluster",
      inputSchema: {
        type: "object",
        properties: {
          cluster_id: {
            type: "string",
            description: "UUID of the reference cluster"
          },
          threshold: {
            type: "number",
            description: "Minimum similarity threshold",
            default: 0.7
          }
        },
        required: ["cluster_id"]
      }
    },
  • mcp.js:387-405 (registration)
    Tool registration in the MCP server's tools list. Contains the tool name, description, and input schema definition with cluster_id and threshold parameters.
    {
      name: "find_similar_clusters",
      description: "Find clusters similar to a given cluster",
      inputSchema: {
        type: "object",
        properties: {
          cluster_id: {
            type: "string",
            description: "UUID of the reference cluster"
          },
          threshold: {
            type: "number",
            description: "Minimum similarity threshold",
            default: 0.7
          }
        },
        required: ["cluster_id"]
      }
    },
  • mcp.js:649-654 (registration)
    Switch case handler that routes tool invocations to the memoryManager.findSimilarClusters method, passing cluster_id and threshold (defaulting to 0.7), and returns results as formatted JSON text.
    case "find_similar_clusters":
      const similarClusters = await memoryManager.findSimilarClusters(
        args.cluster_id,
        args.threshold || 0.7
      );
      return { content: [{ type: "text", text: JSON.stringify(similarClusters, null, 2) }] };

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