Skip to main content
Glama

find_similar_clusters

Identify clusters with high similarity to a specified cluster using a customizable threshold. Essential for analyzing patterns and relationships in 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

  • The core handler function in MemoryManager class that implements the tool logic. It executes a SQL query using pgvector's cosine distance operator (<=>) to find other clusters whose centroid embeddings are similar (above threshold) to the given cluster's centroid.
    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 []; } }
  • Input schema definition for the tool, specifying parameters cluster_id (required UUID) and optional threshold (default 0.7). This schema is used for validation.
    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)
    Tool dispatch/registration in the main MCP server switch statement. Calls the MemoryManager handler with parsed arguments and returns JSON response.
    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) }] };
  • mcp.js:388-405 (registration)
    Tool registration in the ListTools response handler, exposing the tool with its schema to MCP clients.
    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"] } },

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