mongodb/mongoid · error · ArgumentError

Cannot infer vector path on #{name}: no 'vector' type field

Error message

Cannot infer vector path on #{name}: no 'vector' type field in index definition; specify path:

What it means

Error "Cannot infer vector path on #{name}: no 'vector' type field in index definition; specify path:" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/search_indexable.rb:462

        resolved_index = spec[:name] || 'default'
        resolved_path  = path ? path.to_s : infer_vector_path(spec)

        [ resolved_index, resolved_path ]
      end

      # Infers the vector field path from the index definition by locating
      # the first field declared with type 'vector'.
      #
      # @param [ Hash ] spec The vector search index spec.
      #
      # @return [ String ] the field path.
      def infer_vector_path(spec)
        field_list = spec.dig(:definition, :fields) || spec.dig(:definition, 'fields') || []
        vector_field = field_list.find { |f| (f[:type] || f['type']) == 'vector' }

        unless vector_field
          raise ArgumentError,
                "Cannot infer vector path on #{name}: no 'vector' type field in index definition; specify path:"
        end

        (vector_field[:path] || vector_field['path']).to_s
      end

      # Resolves the index name and text field path for an auto-embedding
      # query, applying inference when either is omitted.
      #
      # @param [ String | Symbol | nil ] index The requested index name.
      # @param [ String | Symbol | nil ] path The requested field path.
      #
      # @return [ Array<String> ] the resolved [ index_name, field_path ] pair.
      def resolve_auto_embed_index(index, path)
        auto_embed_specs = search_index_specs.select do |s|
          s[:type] == 'vectorSearch' &&
            (s.dig(:definition, :fields) || s.dig(:definition, 'fields') || [])
              .any? { |f| (f[:type] || f['type']) == 'autoEmbed' }

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/search_indexable.rb:462 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/5e072be9b38a3f24. Report an issue: GitHub.