mongodb/mongoid · error · ArgumentError

No auto-embed index '#{index}' declared on #{name}

Error message

No auto-embed index '#{index}' declared on #{name}

What it means

Error "No auto-embed index '#{index}' declared on #{name}" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/search_indexable.rb:502

        # Extracted to keep cyclomatic complexity within RuboCop's threshold.
        spec = select_auto_embed_spec(auto_embed_specs, index)
        resolved_index = spec[:name] || 'default'
        resolved_path  = path ? path.to_s : infer_auto_embed_path(spec)

        [ resolved_index, resolved_path ]
      end

      # Picks one spec from the list of auto-embed specs, guided by +index+.
      #
      # @param [ Array<Hash> ] specs The candidate auto-embed specs.
      # @param [ String | Symbol | nil ] index The requested index name.
      #
      # @return [ Hash ] the selected spec.
      def select_auto_embed_spec(specs, index)
        if index
          found = specs.find { |s| s[:name] == index.to_s }
          raise ArgumentError, "No auto-embed index '#{index}' declared on #{name}" unless found

          found
        elsif specs.size == 1
          specs.first
        else
          raise ArgumentError,
                "#{name} has multiple auto-embed indexes; specify index: to select one"
        end
      end

      # Infers the text field path from an index definition by locating
      # the first field declared with type 'autoEmbed'.
      #
      # @param [ Hash ] spec The vector search index spec.
      #
      # @return [ String ] the field path.
      def infer_auto_embed_path(spec)
        field_list = spec.dig(:definition, :fields) || spec.dig(:definition, 'fields') || []

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/search_indexable.rb:502 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/510503e9c73b4fae. Report an issue: GitHub.