mongodb/mongoid · error · ArgumentError

#{resolved_path} is nil on this document; cannot perform aut

Error message

#{resolved_path} is nil on this document; cannot perform auto-embed search

What it means

Error "#{resolved_path} is nil on this document; cannot perform auto-embed search" thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/search_indexable.rb:133

    #   to use (optional when only one is declared on the model).
    # @param [ String | Symbol | nil ] path The indexed text field path
    #   (optional if unambiguous from the index definition).
    # @param [ Integer ] limit Maximum number of results (default: 10).
    # @param [ Integer | nil ] num_candidates Candidates for ANN search;
    #   defaults to limit * 10. Ignored when exact: true.
    # @param [ Hash | nil ] filter Optional MongoDB filter for pre-filtering.
    # @param [ true | false ] exact Use exact nearest-neighbor search (default: false).
    # @param [ String | nil ] model Query-time embedding model override.
    # @param [ Array ] pipeline Additional aggregation stages to append.
    #
    # @return [ Array<Mongoid::Document> ] matching documents, each with
    #   a populated +vector_search_score+ attribute.
    def auto_embed_search(index: nil, path: nil, limit: 10, num_candidates: nil, filter: nil, exact: false, model: nil, pipeline: []) # rubocop:disable Metrics/ParameterLists
      _index, resolved_path = self.class.send(:resolve_auto_embed_index, index, path)
      text = public_send(resolved_path)

      if text.nil?
        raise ArgumentError,
              "#{resolved_path} is nil on this document; cannot perform auto-embed search"
      end

      self_exclusion = { '$match' => { '_id' => { '$ne' => _id } } }
      post_pipeline = [ self_exclusion, { '$limit' => limit }, *Array(pipeline) ]
      effective_candidates = num_candidates || (limit * 10)

      self.class.auto_embed_search(
        text,
        index: index,
        path: path,
        limit: limit + 1,
        num_candidates: effective_candidates,
        filter: filter,
        exact: exact,
        model: model,
        pipeline: post_pipeline
      )

View on GitHub (pinned to 0da0e23d71)

When it happens

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