Skip to main content
Glama
AgentWong

Knowledge Graph Memory Server

by AgentWong

search_nodes

Find nodes in the knowledge graph by matching entity names, types, and observation content against a search query.

Instructions

Search for nodes in the knowledge graph based on a query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query to match against entity names, types, and observation content

Implementation Reference

  • The actual implementation of the search_nodes logic, which queries the database for entities matching the query and retrieves their related nodes.
    async def search_nodes(self, query: str) -> Dict[str, List[Dict[str, Any]]]:
        """Search for nodes and their relations."""
        if not query:
            raise ValueError("Search query cannot be empty")
    
        async with self.pool.get_connection() as conn:
            search_pattern = f"%{sanitize_input(query)}%"
            
            # Search entities
            cursor = await conn.execute(
                """
                SELECT * FROM entities 
                WHERE name LIKE ? 
                OR entity_type LIKE ? 
                OR observations LIKE ?
                """,
                (search_pattern, search_pattern, search_pattern)
            )
            rows = await cursor.fetchall()
            
            entities = []
            entity_names = set()
            for row in rows:
                entity = Entity(
                    name=row['name'],
                    entityType=row['entity_type'],
                    observations=row['observations'].split(',') if row['observations'] else []
                )
                entities.append(entity.to_dict())
                entity_names.add(entity.name)
    
            relations = await self._get_relations_for_entities(conn, entity_names)
            return {"entities": entities, "relations": relations}

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/AgentWong/optimized-memory-mcp-server'

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