{"record":{"id":"51167462fb4dd92e","repo":"mongodb/laravel-mongodb","slug":"this-method-is-not-supported-by-mongodb-use-vectorsearch-511674","errorCode":null,"errorMessage":"This method is not supported by MongoDB. Use vectorSearch() instead, which returns vectorSearchScore in the result.","messagePattern":"This method is not supported by MongoDB\\. Use vectorSearch\\(\\) instead, which returns vectorSearchScore in the result\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Query/Builder.php","lineNumber":2053,"sourceCode":"     * Base method from Laravel >= 13.0\n     * ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0\n     *\n     * @internal This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.\n     */\n    public function orWhereVectorDistanceLessThan($column, $vector, $maxDistance)\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() with the $filter parameter instead.');\n    }\n\n    /**\n     * Base method from Laravel >= 13.0\n     * ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0\n     *\n     * @internal This method is not supported by MongoDB. Use vectorSearch() instead, which returns vectorSearchScore in the result.\n     */\n    public function selectVectorDistance($column, $vector, $as = null)\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() instead, which returns vectorSearchScore in the result.');\n    }\n\n    /**\n     * Base method from Laravel >= 13.0\n     * ToDo: mark as `#[Override]` when we drop support for Laravel < 13.0\n     *\n     * @internal This method is not supported by MongoDB. Use vectorSearch() instead, which returns results ordered by vector score.\n     */\n    public function orderByVectorDistance($column, $vector = [])\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB. Use vectorSearch() instead, which returns results ordered by vector score.');\n    }\n}\n","sourceCodeStart":2035,"sourceCodeEnd":2067,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Query/Builder.php#L2035-L2067","documentation":"selectVectorDistance selects a computed vector distance column in SQL builders; MongoDB cannot compute it as a select alias, so the builder throws BadMethodCallException and points to vectorSearch(), whose results include a vectorSearchScore field.","triggerScenarios":"Calling ->selectVectorDistance($column, $vector, $as) on a MongoDB-backed query builder.","commonSituations":"Ported pgvector code reading distance values per row; portable Laravel vector abstractions running against MongoDB after upgrading to Laravel >= 13.0.","solutions":["Use vectorSearch() and read the vectorSearchScore field from each result instead of a distance column","Map/scale vectorSearchScore client-side if an actual distance value is required","Catch BadMethodCallException and switch the projection code to vectorSearch results"],"exampleFix":"// before\n$rows = Doc::selectVectorDistance('embedding', $vec, 'distance')->get();\n// after\n$rows = Doc::vectorSearch('embedding', $vec)->get(); // each has $row->vectorSearchScore","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"if ($builder instanceof MongoDB\\Query\\Builder) { /* use vectorSearch and read vectorSearchScore */ }","tryCatchPattern":"try { $rows = $q->selectVectorDistance($col, $vec)->get(); } catch (\\BadMethodCallException $e) { $rows = $q->vectorSearch($col, $vec)->get(); }","preventionTips":["Consume vectorSearchScore from vectorSearch results instead of a distance alias","Handle vector-score-to-distance conversion client-side if needed","Keep projection logic connection-specific"],"tags":["query-builder","vector-search","unsupported-method","mongodb"],"backgroundTag":"unsupported-operation","analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}