{"record":{"id":"3593308989ef6179","repo":"microsoft/autogen","slug":"subclasses-must-implement-get-embedding","errorCode":null,"errorMessage":"Subclasses must implement _get_embedding","messagePattern":"Subclasses must implement _get_embedding","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/tools/azure/_ai_search.py","lineNumber":665,"sourceCode":"\n    @classmethod\n    @abstractmethod\n    def _from_config(cls, config: AzureAISearchConfig) -> \"BaseAzureAISearchTool\":\n        \"\"\"Create a tool instance from a configuration object.\n\n        This is an abstract method that must be implemented by subclasses.\n        \"\"\"\n        if cls is BaseAzureAISearchTool:\n            raise NotImplementedError(\n                \"BaseAzureAISearchTool is an abstract base class and cannot be instantiated directly. \"\n                \"Use a concrete implementation like AzureAISearchTool.\"\n            )\n        raise NotImplementedError(\"Subclasses must implement _from_config\")\n\n    @abstractmethod\n    async def _get_embedding(self, query: str) -> List[float]:\n        \"\"\"Generate embedding vector for the query text.\"\"\"\n        raise NotImplementedError(\"Subclasses must implement _get_embedding\")\n\n\n_allow_private_constructor = ContextVar(\"_allow_private_constructor\", default=False)\n\n\nclass AzureAISearchTool(EmbeddingProviderMixin, BaseAzureAISearchTool):\n    \"\"\"Azure AI Search tool for querying Azure search indexes.\n\n    This tool provides a simplified interface for querying Azure AI Search indexes using\n    various search methods. It's recommended to use the factory methods to create\n    instances tailored for specific search types:\n\n    1.  **Full-Text Search**: For traditional keyword-based searches, Lucene queries, or\n        semantically re-ranked results.\n        - Use `AzureAISearchTool.create_full_text_search()`\n        - Supports `query_type`: \"simple\" (keyword), \"full\" (Lucene), \"semantic\".\n\n    2.  **Vector Search**: For pure similarity searches based on vector embeddings.","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/tools/azure/_ai_search.py#L647-L683","documentation":"_get_embedding is the abstract hook that turns a query string into a vector for vector/hybrid search. Any subclass that supports vector queries must implement it; the base body raises NotImplementedError when called. This is hit when a subclass inherits the base's default body instead of overriding it (or an embedding provider mixin failed to supply it).","triggerScenarios":"Running a vector or hybrid search with a custom subclass that does not override _get_embedding; calling tool._get_embedding('query') on such a class; constructing a vector tool from a class whose MRO does not include EmbeddingProviderMixin.","commonSituations":"Writing a custom embedding backend (local model, non-OpenAI provider) and forgetting to wire in the embedding method before testing search; subclass composition where the mixin providing _get_embedding was omitted from the bases.","solutions":["Implement `async def _get_embedding(self, query: str) -> List[float]` in your subclass returning the embedding for the query using the same model/dimensions as the index's vector field.","If you intended standard OpenAI/Azure OpenAI embeddings, inherit from EmbeddingProviderMixin (as AzureAISearchTool does) instead of reimplementing.","Add a startup smoke test: await tool._get_embedding('ping') to fail fast on wiring mistakes."],"exampleFix":"# before\nclass MyTool(BaseAzureAISearchTool):  # no _get_embedding\n    ...\n# after\nclass MyTool(BaseAzureAISearchTool):\n    async def _get_embedding(self, query: str) -> List[float]:\n        return await self._embedder.embed(query)  # must match index vector dimensions","handlingStrategy":"type-guard","validationCode":"import inspect\n\ndef embedding_hook_ready(cls) -> bool:\n    return '_get_embedding' in cls.__dict__ or any(\n        '_get_embedding' in vars(c) for c in cls.__mro__ if c not in (object,)\n    )","typeGuard":"def can_embed(tool) -> bool:\n    import inspect\n    cls = type(tool)\n    for c in cls.__mro__:\n        if '_get_embedding' in vars(c) and vars(c)['_get_embedding'] is not getattr(__import__('autogen_ext.tools.azure._ai_search', fromlist=['BaseAzureAISearchTool']).BaseAzureAISearchTool, '_get_embedding', None):\n            return True\n    return False","tryCatchPattern":"try:\n    vec = await tool._get_embedding('ping')\nexcept NotImplementedError:\n    raise TypeError(f'{type(tool).__name__} cannot vector-search: implement _get_embedding')","preventionTips":["Smoke-test `await tool._get_embedding('ping')` at startup for any vector/hybrid tool.","Ensure your subclass MRO includes an embedding provider (e.g. EmbeddingProviderMixin) or your own implementation.","Match embedding model dimensions to the index vector field dimensions to avoid the next failure downstream."],"tags":["azure","azure-ai-search","embeddings","abstract-class","not-implemented"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}