Skip to main content
Glama

faiss_search

Perform semantic similarity searches on external FAISS indices to find relevant content based on query meaning.

Instructions

Search external FAISS tether for semantic similarity search (if enabled).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
top_kNoNumber of results (default: 10)

Implementation Reference

  • Implementation of the faiss_search tool handler, which delegates the search request to the FaissTetherBridge object.
    elif name == "faiss_search":
        query = _validate_string(arguments.get("query", ""), "query")
        top_k = int(_validate_number(arguments.get("top_k", 10), "top_k", 1, 100))
    
        if not tether.is_available():
            return [
                types.TextContent(
                    type="text",
                    text=json.dumps(
                        {
                            "success": False,
                            "message": f"FAISS tether not available (enabled: {Config.FAISS_TETHER_ENABLED})",
                            "suggestion": "Enable and start the FAISS tether",
                        },
                        indent=2,
                    ),
                )
            ]
    
        result = tether.search(query, top_k)
    
        return [
            types.TextContent(
                type="text",
                text=json.dumps(
                    {
                        "success": result.get("status") != "error",
                        "query": query,
                        "results": result.get("results", []),
                        "count": result.get("count", 0),
                    },
                    indent=2,
                ),
            )
        ]
  • The FaissTetherBridge class, which handles the communication with an external FAISS service via socket.
    class FaissTetherBridge:
        """Bridge to external FAISS tether (optional integration)."""
    
        def __init__(self):
            self.host = Config.FAISS_TETHER_HOST
            self.port = Config.FAISS_TETHER_PORT
            self.enabled = Config.FAISS_TETHER_ENABLED
    
        def is_available(self) -> bool:
            if not self.enabled:
                return False
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(2)
                sock.connect((self.host, self.port))
                sock.close()
                return True
            except Exception:
                return False
    
        def search(self, query: str, top_k: int = 10) -> Dict:
            if not self.enabled:
                return {"status": "error", "message": "FAISS tether not enabled"}
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(10)
                sock.connect((self.host, self.port))
                request = json.dumps({"cmd": "search", "query": query, "top_k": top_k})
                sock.sendall(request.encode("utf-8"))
                response = sock.recv(65536).decode("utf-8")
                sock.close()
                return json.loads(response)
            except Exception as e:
                return {"status": "error", "message": str(e)}
    
        def status(self) -> Dict:
            if not self.enabled:
                return {"status": "error", "message": "FAISS tether not enabled"}
            try:
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(5)
                sock.connect((self.host, self.port))
                request = json.dumps({"cmd": "status"})
                sock.sendall(request.encode("utf-8"))
                response = sock.recv(16384).decode("utf-8")
                sock.close()
                return json.loads(response)
            except Exception as e:
                return {"status": "error", "message": str(e)}
  • Registration of the faiss_search tool in the server.list_tools() method.
    types.Tool(
        name="faiss_search",
        description="Search external FAISS tether for semantic similarity search (if enabled).",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {"type": "string", "description": "Search query"},
                "top_k": {"type": "number", "description": "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/For-Sunny/hebbian-mind-enterprise'

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