Skip to main content
Glama

search_memories_text

Search stored memories by text content using full-text search to retrieve relevant information from persistent AI memory systems.

Instructions

Search memories by text content using full-text search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesText query to search for
limitNoMaximum number of results

Implementation Reference

  • Actual implementation of searchMemoriesByText method that performs full-text search on memories using PostgreSQL's tsvector and plainto_tsquery for English text search, filtering by active status and ordering by text rank and relevance score
    async searchMemoriesByText(query, limit = 10) {
      try {
        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,
            textRank: sql`ts_rank(to_tsvector('english', ${schema.memories.content}), plainto_tsquery('english', ${query}))`.as('text_rank')
          })
          .from(schema.memories)
          .where(
            and(
              eq(schema.memories.status, 'active'),
              sql`to_tsvector('english', ${schema.memories.content}) @@ plainto_tsquery('english', ${query})`
            )
          )
          .orderBy(
            sql`ts_rank(to_tsvector('english', ${schema.memories.content}), plainto_tsquery('english', ${query})) DESC`,
            desc(schema.memories.relevanceScore)
          )
          .limit(limit);
    
        return results;
      } catch (error) {
        console.error('Error searching memories by text:', error);
        throw error;
      }
    }
  • mcp.js:554-559 (handler)
    MCP tool handler for search_memories_text that extracts query and limit arguments from the request and calls memoryManager.searchMemoriesByText()
    case "search_memories_text":
      const textResults = await memoryManager.searchMemoriesByText(
        args.query,
        args.limit || 10
      );
      return { content: [{ type: "text", text: JSON.stringify(textResults, null, 2) }] };
  • mcp.js:88-104 (registration)
    Tool registration in the MCP server's ListToolsRequestSchema handler, defining the search_memories_text tool with its name, description, and input schema
    name: "search_memories_text",
    description: "Search memories by text content using full-text search",
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "Text query to search for"
        },
        limit: {
          type: "integer",
          description: "Maximum number of results",
          default: 10
        }
      },
      required: ["query"]
    }
  • Schema definition for search_memories_text tool, specifying the input parameters (query string required, limit integer optional with default 10)
    {
      name: "search_memories_text",
      description: "Search memories by text content using full-text search",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Text query to search for"
          },
          limit: {
            type: "integer",
            description: "Maximum number of results",
            default: 10
          }
        },
        required: ["query"]
      }

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