{"record":{"id":"8fb1254fabe78953","repo":"appwrite/appwrite","slug":"bulkembed-requires-at-least-one-text","errorCode":null,"errorMessage":"bulkEmbed requires at least one text","messagePattern":"bulkEmbed requires at least one text","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"packages/agents/src/Adapters/Appwrite.php","lineNumber":107,"sourceCode":"        ];\n    }\n\n    /**\n     * Bulk embedding generation — sends multiple texts in a single request.\n     *\n     * @param  array<int, string>  $texts\n     * @return array{\n     *     embeddings: array<int, array<int, float>>,\n     *     tokensProcessed: int|null,\n     *     totalDuration: int|null\n     * }\n     *\n     * @throws \\Exception\n     */\n    public function bulkEmbed(array $texts): array\n    {\n        if (empty($texts)) {\n            throw new \\InvalidArgumentException('bulkEmbed requires at least one text');\n        }\n\n        $payload = [\n            'model' => $this->model,\n            'texts' => array_values($texts),\n        ];\n        $response = $this->post($this->getEndpoint(), $payload);\n        $json = json_decode((string) $response->getBody(), true);\n\n        if (! is_array($json)) {\n            throw new \\Exception('Invalid response format received from the API');\n        }\n\n        if (isset($json['error'])) {\n            throw new \\Exception(is_string($json['error']) ? $json['error'] : 'Unknown error', $response->getStatusCode());\n        }\n\n        if (! isset($json['embeddings']) || ! is_array($json['embeddings']) || count($json['embeddings']) !== count($texts)) {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/appwrite/appwrite/blob/7eab5f1970bacb06f8cce069c27b7d14a4178153/packages/agents/src/Adapters/Appwrite.php#L89-L125","documentation":"Thrown by the Appwrite agents adapter's bulkEmbed when called with an empty texts array. The bulk embedding endpoint requires at least one input string; sending an empty batch would produce a pointless API call. Guard the caller: only invoke bulkEmbed when the array contains at least one non-empty string.","triggerScenarios":"Calling bulkEmbed([]) directly, or via embed()/batch pipelines when the input list was filtered down to nothing.","commonSituations":"Empty database result sets or empty user input passed into an embedding step; collecting texts with array_filter that removed everything.","solutions":["Guard the call site: only invoke bulkEmbed when count($texts) > 0","Return early (e.g. empty vector list) when the input batch is empty","Fix upstream filtering logic that empties the batch unexpectedly"],"exampleFix":"// before\n$vectors = $adapter->bulkEmbed($texts);\n// after\n$vectors = $texts === [] ? [] : $adapter->bulkEmbed($texts);","handlingStrategy":"validation","validationCode":"if (count($texts) === 0) {\n    return []; // or skip the embedding step\n}\n$vectors = $adapter->bulkEmbed($texts);","typeGuard":null,"tryCatchPattern":"try {\n    $vectors = $adapter->bulkEmbed($texts);\n} catch (\\InvalidArgumentException $e) {\n    $vectors = []; // empty batch\n}","preventionTips":["Guard empty batches before embedding","Check that upstream filters do not empty the input list","Treat empty input as a no-op, not an error path"],"tags":["php","empty-input","validation","embeddings"],"backgroundTag":"empty-required-field","analyzedSha":"7eab5f1970bacb06f8cce069c27b7d14a4178153","analyzedAt":"2026-09-23T00:38:38.905Z","contentChangedAt":"2026-09-23T00:38:38.905Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}