{"record":{"id":"6095b8cf332113d1","repo":"ankane/searchkick","slug":"distance-must-match-searchkick-options-for-approxi","errorCode":null,"errorMessage":"distance must match searchkick options for approximate search","messagePattern":"distance must match searchkick options for approximate search","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/searchkick/query.rb","lineNumber":982,"sourceCode":"    def set_knn(payload, knn, per_page, offset)\n      if term != \"*\"\n        raise ArgumentError, \"Use Searchkick.multi_search for hybrid search\"\n      end\n\n      field = knn[:field]\n      field_options = searchkick_options.dig(:knn, field.to_sym) || searchkick_options.dig(:knn, field.to_s) || {}\n      vector = knn[:vector]\n      distance = knn[:distance] || field_options[:distance]\n      exact = knn[:exact]\n      exact = field_options[:distance].nil? || distance != field_options[:distance] if exact.nil?\n      k = per_page + offset\n      ef_search = knn[:ef_search]\n      filter = payload.delete(:query)\n\n      if distance.nil?\n        raise ArgumentError, \"distance required\"\n      elsif !exact && distance != field_options[:distance]\n        raise ArgumentError, \"distance must match searchkick options for approximate search\"\n      end\n\n      if Searchkick.opensearch?\n        if exact\n          # https://opensearch.org/docs/latest/search-plugins/knn/knn-score-script/#spaces\n          space_type =\n            case distance\n            when \"cosine\"\n              \"cosinesimil\"\n            when \"euclidean\"\n              \"l2\"\n            when \"taxicab\"\n              \"l1\"\n            when \"inner_product\"\n              \"innerproduct\"\n            when \"chebyshev\"\n              \"linf\"\n            else","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/ankane/searchkick/blob/93e901a75b11a25101668a616e006b158251b16e/lib/searchkick/query.rb#L964-L1000","documentation":"Error \"distance must match searchkick options for approximate search\" thrown in ankane/searchkick.","triggerScenarios":"Thrown at lib/searchkick/query.rb:982 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93e901a75b11a25101668a616e006b158251b16e","analyzedAt":"2026-08-21T19:06:23.767Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}